I spent a lot of time thinking about problem 18. I knew that a brute-force solution might work, but as the problem states, I would have to face a larger version later on, so it would be in my best interest to write a solution that could handle a larger set. The trick to problem 18 (and 67) is to think from the bottom-up, instead of the top-down. Given a three-number pyramid, it’s easy to see that the high sum path depends entirely on the larger of the two bottom numbers. Once you know that, just work your way up the pyramid, two rows at a time. The rest of the class is just parsing and setup code.
Problem 19 is stupidly easy using the DateTime class that .NET provides. I mean, it was just so trivial it’s barely worth mentioning.
Problem 20 would take a lot more thinking and work, were it not for the BigInteger class in .NET 4. Since I have that available, I just made a Factorial method and a method to parse out a string into digits and sum them up.
I was stuck on Problem 21 for a bit. Note that I was getting to problem 21 soon after I finally got problem 11 solved. The main block I had on problem 21 was that I was just overthinking it. The answer was very simple once I just broke it up into a series of simple steps—a nice, elegant solution emerged.
I was at a “Code and Coffee” session when I solved problem 21. I had time left, so I paired up to solved problem 22. This solution was very concise to express with Linq. The crux of the problem was figuring out a good way to get a score for each letter. It turns out the syntax is very similar to C++ [c - (‘A’ – 1) was all it took to score a single letter]. Thanks to the power of Linq, a string can be viewed as a collection of characters, and thus the ‘Sum’ extension method works on it.
As always, you can view my code at CodePlex – feel free to submit criticisms/comments/patches there, or use the framework for your own Project Euler solution.
So maybe you’ve heard that Mexican Coke is made with ‘real’ sugar (i.e. cane sugar), unlike Coke from the USA, which is made with evil, corporate sugar (i.e. corn syrup).Â Mexicans who drink USA Coke often claim that it’s not as good as Mexican Coke, and older people from the US claim that Mexican Coke is the Coke that ‘they remember’ from the pre-government-meddling-in-sugar era.Â Go check out Snopes or Google for more background about the whole ridiculous controversy.
I’m not interested in any of the political nonsense (though I am against corn subsidies and sugar tariffs/quotas) as much as I’m interested in Coke itself: I drink a lot of Coke.Â A lot.Â Just ask anyone I know, and the first thing they’ll mention about me is their concern for the abusive amounts of Coke that I drink.Â Between this word and the last period, I just drank some.Â It’s a relatively large part of my dietary life, so naturally, I’m interested in all kinds of Coke lore, and even the promise of a better Coke from below the border.
One day, bottles of Mexican Coke showed up in the convenience store in the lobby of the office where I work.Â In the interest of science, I bought 6 of them.Â I drank a few, and put a few in the fridge for later testing.Â I wanted to do a taste test to see if I could tell the difference, and which I preferred.Â Here is the science:
Question: What’s the big deal about Mexican Coke and real sugar?
Background Research: See above.Â Additionally, I have tried some other drinks (namely Hank’s Root Beer) made with cane sugar, and found them to be very tasty.
Hypothesis: Despite all the context I’ve mentioned, I was skeptical that I could tell the difference.
Experiment: I purchased glass bottles of Mexican Coke and put them in the fridge to chill.Â To isolate the variable (sugar/corn syrup) as much as possible, I also purchased glass bottles of US Coke and put them in the fridge to chill.Â When the bottles were chilled enough, I asked my wife to pour three shot glasses of Coke: 2 of them with one type, and 1 of them with the other type.Â It was up to her what to pour in what, as long as both flavors are in there at least once.Â She hid the bottles from me.Â I drank each shot glass and drank water between each glass.
Results: The first glass was really good.Â The second glass seemed wrong.Â Not terrible, but wrong.Â I was excited that I already had a result!Â The third glass also seemed wrong.Â I guessed that the first glass was US Coke and the second two were Mexican.Â I was exactly right!
Conclusion: There is a difference in taste!Â Even Coke maintains that there is no taste difference, but that clearly is not the case.Â However, as much as I tried to isolate the variables, there are still many differences that I can’t account for: water differences, carbonation amounts, the effect of transport, etc.Â If I were in Mexico, I would not hesitate to drink their Coke–it’s very good.Â But, given the choice, I’ll stick to good old US Coke.