Two more problems solved!
Problem 34
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits.
This was pretty straightforward. When we consider that 9! = 362880 we only have to do a few sums to get an upper bound on the numbers that we must consider. Then it is a simple case of putting together a loop which gets the digits of a number, sums the factorials of the digits and compares it with the number. There is a similar problem which I hope to have coded a routine for by the end of the weekend involving fifth powers of digits.
Problem 39
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120 - {20,48,52}, {24,45,51}, {30,40,50}. For which value of p ≤ 1000, is the number of solutions maximised?
I solved a similar problem to this a few days ago; this was a bigger problem because of searching through a large set of perimeters. However, with a bit more maths it wasn't difficult to get conditions to impose and then search through - for example, we can deduce with only a little work that p/3 < c < p/2 and that p must be a divisor of 2ab. The program took no time at all to find the p which had the most solutions (incidentally, the perimeter value found had 8 solutions!).
So that leaves... Four problems to solve? Really? Am I actually that close to finishing another one of my 101 things?!
Saturday, 28 February 2009
Project Euler, Problems 34 and 39
Friday, 27 February 2009
The Man Who Smiled
I really like Henning Mankell's Kurt Wallander mysteries. My friend Dave got me into reading them a few years ago when I first started getting interested in reading crime stories and noir, and The Man Who Smiled is the third Wallander novel I've read. I think that the brilliant thing about reading these stories is the setting and the atmosphere that Mankell creates. The crimes are well thought out, as is the description of the way that Wallander and the team in Ystad eventually solve them. The main draw for me is the way that you feel like you are there with him as he follows the clues and makes the deductions that lead him to the answer.
When he is on the job, Kurt Wallander eats poorly, sleeps little and gradually becomes more and more dishevelled. His personal life is an endless series of thoughts to call his family - which he invariably puts of to later - and reflections on why he became a police officer (he can't remember any more). In The Man Who Smiled, he begins his journey even more lost than usual. Wallander has taken a leave of absence that has lasted over a year, ever since he had to take a man's life in self-defence. On the day that he is to officially resign he discovers that a friend of his has been murdered, and in an instant he decides to return to work, and so the cycle begins again for him.
The Man Who Smiled is a good mystery story, although perhaps not the best place to start for people who've not read any of the other Wallander novels. You should definitely try One Step Behind if you get the chance, which is a fantastic mystery story, again permeated by the brilliant atmosphere that Mankell expertly builds up.
Thursday, 26 February 2009
Project Euler, Problems 9 and 28
I was just thinking the other day that I hadn't done any Project Euler problems in a while, and having a look down the list of problems a few jumped out at me as "do-able". Both of these required very little computing - in fact I did the second mentioned here with just a calculator once I had done some thinking.
(as a side note, I've also been working on thing number 62, to find the number of stacked 4-tangles; I've proved a few things which my previous assumptions had relied on, made it more concrete, and am at the point where I need to use a Maple program in order to find things and split things up. Not quite there in my C++ knowledge in order to be able to do that!)
Problem 9
Find the only Pythagorean triplet {a,b,c} such that a + b + c = 1000.
From this we can take a few bits of information:
- a^2 + b^2 = c^2
- a + b + c = 1000
- a < b < c and a, b, c are all positive integers
- ab = 1000(500 - c)
Problem 28
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: (looks better on Project Euler site, here)
21 22 23 24 25
20 7 8 9 10
19 6 1 2 11
18 5 4 3 12
17 16 15 14 13
I didn't need C++ to solve this. I extended the spiral out to 7 by 7, so I could get a better feel for the numbers in the diagonals. I split them up, and obtained (in the end) three sequences of numbers. From these I arrived at three quadratic relations that you could get the three sequences from, and then by summing the series I got the answer. Simple really - big numbers though!
This takes my total to 19 now, six more to go. I have a list of a few that I might try next. I was originally aiming to get my 25 done by the end of February. I'm now aiming for the end of March, and also hoping to get thing 62 done by then as well (or at least, to have the answer and be writing it out from all of my rough notes).
Tuesday, 24 February 2009
The Shack
A few weeks ago my mum said, "I've got a novel for you to read; it's called The Shack and... Well, I'm not really enjoying it, but I want someone else to read it so I know I'm not crazy for not liking it."
"What's it about?" I asked.
"It's about this man, and his young daughter is killed by a serial killer, and then a few years later he gets a note from God saying that he has to come to the shack where his daughter was killed - "
"O-kaaay..."
"- yeah, and then, when he's there, he meets God. And God is three people: an old black woman, a thirty-something Middle-Eastern man and a young Asian woman."
"Shall I just read it?"
"Maybe you'll like it more than I did," she said, "I skipped the last quarter to go straight to the end..."
So, once I had finished a stack of library books I borrowed it and started reading. The basic outline is exactly as my mum described it, and one would think that that opened up a lot of possibilities for an interesting story. Instead...
I'm going to be as concise as possible about the experience; from the front and back cover heaping praise on it, and the two pages of people giving quotes inside it - and in some ways throughout the story - it smacks of being a book that is going to desperate lengths to get itself noticed. At points it does this to the distraction of the story itself. There's a covering story, that the person who has written it is a friend of the person who all this happened to; this device bookends the story. The (fictional) writer has done a disservice to his friend; the narrator often refers to the protagonist's grief as The Great Sadness - italicised every time and always with capitals - and as strange as it seems at those (frequent) points it becomes absolutely ridiculous when the protagonist refers to his grief as The Great Sadness when talking to others...
My mum says that she hated the book; I don't know if I would go that far. I couldn't recommend it to anyone, I really couldn't. Some elements of the story challenged my own personal faith, but not in a positive way - in some ways it made me think, "Am I foolish for having religious faith?" One of the themes that runs through the story is that humans by and large don't really understand that faith (the Christian faith) is not about rules and religions, but about relationships. But then, why should we believe the message of the author? What does he offer apart from an argument that "other people get it wrong"?
Fundamentally, I didn't enjoy reading the book. The pacing is weird, the writing is quite strange at times and to my ear the dialogue rarely rang true, as if it had been written for two people sat on a chat show couch having a staged conversation. The denouement was the final straw, offering with one hand proof that the man had experienced everything that he said he did up at the shack and then taking away with the other what little internal logic the story had by summing up the consequences of this in a few lines.
As I said, the covers carry many endorsements and facts about sales - New York Times #1, a million copies sold - and the inside back cover asks people to blog about the book once they've read it, get the word out, etc. Well, here's my review: "Don't read The Shack. It's a frustrating, poorly written thesis on faith dressed up as an Oprah/Richard & Judy novel of the week."
Vegetarian Month I Update 3
Only a few days left to go; I'm not going to rush back into eating meat with a big steak on Sunday - I'll probably have a piece of fish or something - but I am looking forward to eating meat and fish again. I didn't do this out of any big moral imperative, but rather to try and eat differently, possibly more healthily; this has also meant that I have cooked a lot more over the last month, and while my family might claim that I have been quite limited in the range of foods that I have eaten, at the same time I feel quite good for having tried a range of recipes with them. Things definitely got better for me when I started to follow recipes as well, rather than just make them up as I went along (as I have noted previously).
I'll take next February as one of my two remaining vegetarian months I think, and try to have this April as my other one. Somewhere amongst all this I'll do my thirty days of five-a-day as well - probably; at the moment I'm looking into the whole five-a-day thing due to something a friend told me about the health benefits of following that being a myth (not that I want to excuse myself from eating five-a-day, but if there is no benefit I would rather add something else to the list).
Saturday, 21 February 2009
Scott Pilgrim's Precious Little Life
I've been meaning to read Scott Pilgrim for a very long time; recently, I don't know why, that feeling has been building up in me, a desire to find out what it's all about. I had an idea of the basic story - that a guy has to face the seven evil ex-boyfriends of the girl of his dreams - but had no idea of the specifics of it. I'm not sure I have ever read anything else by the creator of the series Bryan Lee O'Malley, but whenever I have come across a Scott Pilgrim illustration I have smiled at how cool it looks.
(I have seen various things recently about volume five being released, and had heard that Edgar Wright and Michael Cera were in the process of making a film based on the first few volumes; maybe that's why it has been sticking in my mind so much)
I've been economising recently, cutting down on what I do and where I go (credit crunch plus slow work period as a freelancer over the last few months) but last Thursday when I was in my local comic shop (Worlds Apart, near Lime Street Station in Liverpool) my regular order came to less than a fiver. A slow week for comics. And I thought, "Hmmm, maybe, maybe now is the time to see what Scott Pilgrim is like...?" I had a look around and finally (after asking) found volume one (it had been placed with manga due to the style of the artwork).
Normally, when I go to the comic shop I go immediately to the train station after that and get the train home, maybe read a few comics on the way, and read the rest after dinner. On Thursday I was going to meet my writing group, and then we went on for dinner. I read the two comics I had bought, and thought, "I'll read the first chapter of Scott Pilgrim before bed." (it is a graphic novel, broken down into chapters inside)
Well.
I couldn't put it down. The combination of artwork, story, technique, romance, humour - if I hadn't been lying back in bed, it would have floored me. This first volume was released back in 2004, so I'm playing catch up on the cool curve I guess; I had no idea just how absolutely brilliant it was. I like all kinds of comics and graphic novels, but apart from some of the webcomics I read I very rarely go for series that have a humourous focus. To say too much about where Scott Pilgrim gets its laughs from would spoil the surprise - the final twenty pages or so had me alternating between laughing out loud and literally gasping with delight. The dialogue, the story, the artwork - it combines to make a perfect entertainment.
I've looked over the last five paragraphs and realised that really this is a terrible review: aside from the one line synopsis, which is based on what I thought I knew about Scott Pilgrim before I read it, I have told you nothing about what happens or anything really. All I have done is gush about how I came to read it and how fantastic it is. Oh well.
(by the way, if anyone reading this has ever read Scott McCloud's Understanding Comics, it struck me that Bryan Lee O'Malley understands comics - the various things that he uses in it that McCloud talks about in the book just jumped out at me, and not in a distracting, obvious way, just the way that he framed things, used motion lines, drew characters and everything...)
I'm economising, but I am going to put pennies and pounds to one side over the coming weeks and months so that I can get the other four volumes that are currently available. Scott Pilgrim's Precious Little Life is a fantastic slice of pure joy, a wonderful piece of sequential art and a bloody good story.
Recent Books
Saturn's Children by Charles Stross
I've read a few novels by Charles Stross since I've started 101/1001, and while I'm not always blown away in the same way I am when I read something by, say, Peter F. Hamilton, I am always left entertained having read something of Stross's. Saturn's Children is a good mystery story, and has as its backdrop the society of robots living in the solar system after humans have become extinct.
The central mystery itself seemed to unravel in a fairly obvious way as time went on (so, for example, you know who the mysterious aristocrat really is long before you have her identity confirmed) but the background is so well thought out and put together that you just find yourself carried along for the ride. The central character being an obsolete sexbot makes for an interesting perspective, as do the observations about how ridiculous the robots' creators were (a human's frailties compared to a robot's resources).
So far, I'd recommend everything I've read by Charles Stross, and Saturn's Children is no exception; he has an amazing imagination and head for all of the little details that go into making something that feels like a real world. If you're new to Stross though, I'd start with The Atrocity Archives or Halting State, I think they're better stories.
The Hound of the Baskervilles by Arthur Conan Doyle
It should be obvious by now to any regular reader of this blog (all three of you) that I am a sucker for a good mystery story. I read A Study In Scarlet years and years ago, but have never read The Hound of the Baskervilles until now (although I was aware of the mystery and what the solution to the mystery was).
Sherlock Holmes is a brilliant creation; far better writers than myself have described how fantastic he and Doctor Watson are. Doyle really makes them jump out of the page at you as fully three-dimensional characters. The fantastical leap in the story is not connected with the ghastly hound of the title; as with every Holmes story the fantastic thing is Holmes himself, and the speed of the deductions that he makes, the evidence that he bases them on. While he is always right, and the explanation matches up, it makes for an excellent read on the strength of Doyle's creations and the mysteries that he conjures up. You suspend disbelief that a man could be that intelligent and go along with it because Holmes is such a fascinating man.
The 100 Classic Novels app I have for my DS has some Holmes stories, I'll have to give those a look some time soon.
