Archive for April, 2008

Project Euler

Recently I’ve become addicted to solving math problems at Project Euler. Yes, I know this is incredibly dorky, but I am a computer science grad student, and it is probably a good sign that I am doing math problems in my spare time.

Project Euler keeps a list of math problems to which there is a numeric solution. You register on the web site, and then you can submit an answer for a problem. If your answer is correct, then you are given access to an official solution and also a forum where others have posted their solutions.

The problems get increasingly difficult, from (relatively) simple questions like “What is the largest prime factor of the number 600851475143 ?” (solved by brute-force factorization) to much more difficult problems.

I got hooked on this by a post at a programming forum I frequent. The poster could not find a solution to problem 185 and was looking for suggestions. His initial idea was to basically try guess-and-check with some hill climbing to look for local solutions. I didn’t think that would work because the search space is too large (10^16). My idea was to use the hints to construct the number.

Let’s look at the hints. Given the hint with 0 digits correct, you can eliminate each of those digits from the possible answers. Now look at a hint with 1 digit correct. We don’t know which digit is correct, so let’s assume it’s the first. Then we know the first digit and can eliminate another possible digit for the remaining digits. Now look at the next hing. Again, assume the first digit is correct. If it is the same as the first one, then this is an OK guess and we can continue. If not, then we assume the second digit is the correct one and continue our search.

So basically we want to construct a search tree using all the hints, looking for a consistent set of assumptions about which digits in each hint are correct. The depth of the tree is the number of hints given, and the fan-out depends on the number correct in each hint — if n is the number correct, then the fan out for that level is 16 choose n. We short circuit a branch if we encounter an inconsistent assumption. If we ever reach a leaf node and have a fully constrained assumption, then that should be our answer.

The worst-case running time of this algorithm is horrendous because of the fan out. The fan-out for the sample problem can be as bad as 16 choose 3 = 560, so if you actually have to explore every path, you’re looking at a running time of at worst 560^22 steps. In reality it’s not nearly that bad, partly because not every hint causes a fan-out of 560, but mostly because you can skip large parts of the tree because they lead to inconsistent assumptions early on.

I coded this algorithm up in Java, but not without some difficulty. Specifically, I don’t think I chose good representations for my guesses and for my the combinations of possible correct digits. Regardless, my program chugged away for 4 hours and finally spit out the correct answer. Success!

There’s a lot of optimization I could do. One thing I didn’t exploit was ordering the hints to reduce the search space. I tried to do this by ordering the hints from least to most digits correct, but I think a better strategy would be to choose the hint that constrains the problem the most. That way you will have to explore less of the lower part of the tree.

I’ve been thinking about this problem for several days now, and I’m very pleased to have solved it. I’ll be working on more Project Euler problems, and if I come across any particularly interesting ones, I will post my solution here.

Comments (1)

Women’s Olympic Marathon Trials

The Women’s Olympic Marathon Trials were this morning in Boston, the day before the marathon. I dragged myself out of bed on a Sunday morning and went down to Memorial Drive in Cambridge to watch. It was really cool to see all the elite runners running 5-10 feet away from you. I was standing on the corner of Ames and Memorial Drive and had a great view of the runners.

I was able to take some great pictures. This is Deena Kastor catching the leader, Magdalena Lewy Boulet, at mile 23-24. Deena went on to win in 2:29:35, with Lewy Boulet finishing second in 2:30:19.
IMG_3210

This is the legendary Joan Benoit Samuelson, who at age 50 finished in an awesome 2:49:08.
IMG_3222

More pictures here.

Leave a Comment

Playoff prognostication

Time for my yearly NBA playoff picks!

First Round
Eastern Conference
Celtics over Hawks
Pistons over Sixers
Magic over Raptors
Wizards over Cavs

Western Conference
Lakers over Nuggets
Mavs over Hornets
Suns over Spurs
Jazz over Rockets

Second Round
Eastern Conference
Celtics over Wizards
Pistons over Magic

Western Conference
Lakers over Jazz
Suns over Mavs

Conference Finals
Celtics over Pistons
Lakers over Suns

NBA Finals
Celtics over Lakers

Leave a Comment

It’s funny ’cause it’s true

<

Leave a Comment

Fueling and hydrating during a long run

I just got back from my weekly long run, and one thing I’ve learned as I’ve started to run longer is that fueling and hydrating are very important. As your runs start pushing past the one hour and especially the one-and-a-half hour marks, you really need to think about how to keep your body working efficiently enough to complete the workout. I wanted to talk a bit about what works well for me, as well as some techniques others suggest.

Hydration
Hydration becomes important as both the length of your run increases and as temperatures get warmer. When your runs get long enough, you will need to start taking liquids. There are many ways to do this:

  • Carry a water bottle. Some people run with a water bottle in their hand. Others use a carrying system like a Fuel Belt or a Camelbak. I personally use a Fuel Belt, but I’ve heard good things about Camelbaks. Another option is a belt that holds a single large water bottle in the back; I don’t recommend these because they bounce around and drive you crazy.
  • Purchase water or Gatorade during your run. Just bring some cash and duck into a gas station.
  • Stash water bottles along your route. Many people will drive out on their route beforehand and stash water bottles in the bushes along their path. Make sure the seal is still intact when you pick up a bottle, though.
  • Plan your route to pass by places you can get water. There are many water fountains along the Charles River in Cambridge and Boston, for example. Another possibility is to do a cloverleaf route that brings you by your house a few times, so you can pick up water there.

The next thing to consider is what to drink. Is water sufficient, or do you need a sports drink like Gatorade? I like to drink Gatorade because it has carbohydrates that fuel me during the run, so I don’t need to bring Gus or Shot Bloks or whatever. It also contains electrolytes to help avoid hyponatremia. I usually buy a tub of powered Gatorade and mix a quart of it each week before my long run.

Fueling
Runners burn about 100 calories for each mile they run. A ten-mile long run will burn more than a thousand calories, 40% of the 2500 calories a typical man eats in a day. How can you stay strong when you’re running long (sorry, couldn’t help it with the rhyming there)? Your goal should be to take in some carbohydrate calories during the run. For my half marathon, I don’t think I will be running long enough to deplete my glycogen stores, so I plan to stick with Gatorade alone. However, for longer races like the marathon, proper fueling can help put off “hitting the wall.” The typical advice is to consume 30-60 grams of carbs (roughly 125-250 calories) per hour; your body cannot absorb more than that.

Here are some products people recommend:

  • Gus. These little packets of a gel-like goo don’t look very appetizing, but they seem to be widely used.
  • Shot Bloks. These are small gummy candies designed for endurance athletes. They taste kind of like gummy bears. Not bad at all, but very sweet.
  • Jelly Belly Sport Beans. These jelly beans are also designed for endurance athletes. You can get them with caffeine; some people like that.

That’s all I’ve got. Hopefully this will be helpful for others who are starting to increase their mileage.

Leave a Comment

Half marathon training continues

Catherine was harassing me because I haven’t posted since February, so here is an update on my half marathon training. I’ve been slowly upping the mileage and intensity of my workouts, and I feel like I am in pretty good shape now.

Last week I had some pain in my right foot that got severe enough to keep me from running on Saturday. Friday was a scheduled day off, and when Saturday rolled around I decided that my Sunday 11-miler was more important than 3.5 easy miles, so I skipped it. Sunday my long run went really well; I completed the 11 miles without feeling that tired.

My speedwork has consisted of increasing-length tempo runs at around 7:50/mi pace and 1600m repeats on the track at around 7:20/mi. This week, for example, I did a 5-mile tempo run at 7:51/mi, bookended with 1.1 mile warmups and cooldowns. These workouts are difficult, but I’m sure they’re improving my fitness. I’m excited because I think my 1:45 half marathon goal (8:00/mi) may be within reach.

Leave a Comment

Top 10 Beers

Here is a quick post with my top 10 beer list. They are in no particular order, and they only include beers that I’ve drunk a reasonable amount of (not just samples at a beer fest, for example). The list is skewed toward Northeastern beers because that’s where I live — sorry, West Coasters. I’ve avoided special-edition and one-off beers because you won’t be able to find them, and I’ve also tried to avoid picking multiple beers in the same style.

These are the beers I keep coming back to:

  • Ayinger Celebrator Doppelbock
  • Berkshire Oktoberfest Lager
  • Brooklyn Black Chocolate Stout
  • Houblon Chouffe Dobbelen IPA Tripel
  • Ipswich Oatmeal Stout
  • Sierra Nevada Bigfoot Barleywine
  • St. Bernardus ABT 12
  • Stone Ruination IPA
  • The Tap Leatherlips IPA
  • Smuttynose Pumpkin Ale

Comments (1)