## Archive for June, 2008

### Puzzle – shortest road system

Thursday, June 19th, 2008

Let's say you're contracted to build roads to connect four towns that are at the corners of an imaginary square with sides 1 mile. What's the shortest length of road system you can build so that every town can get to every other town? [ddet Answer] The first answers that ...

### Puzzle – Clock

Saturday, June 14th, 2008

It's 3 O'Clock. What will be the time when the minute and hour hands are next in the same position (coincident)? [expand title=Answer] The Plodder's way: Let's start with the minute hand at the 12 and hour hand at the 3. Let's call x the number of minute ...

### More puzzles…

Saturday, June 14th, 2008

A few more brainteasers.. Some of these are from Heard on the Street - a book of interview questions for Quants I'm trying to get through. Well worth a read if you're into this sort of thing... 1. Two ropes of different lengths, and you know that if you were to ...

### Dice puzzle – redux

Friday, June 13th, 2008

I'd blogged previously about rolling a die and being given whatever you roll in dollars. You get given two more chances if you don't like what you get the first time, or the second time, for a max of 3 rolls. What's your strategy? You can see the answer in ...

### Mth to last – a recursive approach

Thursday, June 12th, 2008

A collegue of mine was pondering the mthToLast problem for a LinkedList I'd blogged about previously and sent me the following IM message: just a guess - but can you use recursion to solve your link list m problem? a method to track through the list which calls itself, then ...

### Reverse a string using recursion

Thursday, June 12th, 2008

Very basic - take a string and reverse it using simple recursion. I'm sure there's a bunch of ways to do it, but like the fibonacci you should aim to be able to code something like the below in about 20 seconds... >>> def reverse(str): if len(str)==1: ...

### Deep copy and recursive references

Tuesday, June 10th, 2008

Quick one about coding a deep copy and avoiding recursive references... Let's say we have an instance a which has a reference to an instance b and we have to do a deep copy of a. To do this, we need a deep copy of b as well. But let's say ...

### Bootstrapping Zero Curves

Sunday, June 8th, 2008

A yield curve is a representation of what interest rates you could lock in today for investments over different periods. It's effectively a set of yields for securities of different maturities (typically cash rates at the short end, futures and then swaps at the longer maturities - see the ...

### The “Mathematical Constant” and Continuously Compouding Interest

Sunday, June 8th, 2008

One of the (many) aspects of the "Mathematical Constant" $$e$$ is that: $$\lim_{x\to\infty} (1+\frac{1}{x})^x = e$$ This property makes $$e$$ very useful for working on compounding interest problems. How so? Let's start with the basic time value of money formula giving the relationship between the PV (present value) and FV (future value) given R (the ...

### Probability Puzzles…

Sunday, June 1st, 2008

Some probability questions/puzzles: 1. I have two children. One of my children is a girl. What are the chances I have two girls? [expand title=Answer] The answer to the question as stated is not 50/50. After being told that one of your children is a girl, you know there are 3 options (with ...