Sunday, July 17, 2011

Light bulbs in a circle

There are 2011 light bulbs in a circle. There is an uber switch that allows you to flip the state of any four consequtive bulbs at a time. Starting with a configuration with all bulbs off, can we end up with all bulbs on , by following a sequence of such flips?

Friday, July 15, 2011

Triangle

Consider a triangle with vertices labelled A,B and C.
We'd like to count the number of paths of a given length say n, that start and end at A.
The interesting part is that there is a closed form solution to this problem,
and whats more this solution can be implemented in two lines of Haskell code.


g = 0:1:zipWith (\x y -> 2*x + y) g (tail g)

f = [2*x | x <- tail(g)] 

eg, f !!6 = 86 (that is , there are 86 distinct paths of length 8 )