rich_m wrote:
There are 22 pegs on a wall, You are given infinite number of hangers of 2 types
First type--> requires 1 peg
Second type-->requires 2 pegs(each peg beside the other)
In how many different ways can you occupy all the pegs?
Any1 got any idea how tht^ is done? ???
Requires one peg: Each can either contain a hanger or not contain a hanger. So, that's 2^22 == 4194304 possible ways.
Requires two pegs: That's harder. From the start you can either hang one on and skip two pegs, or you can not hang one there and skip one peg. So, for length(N) the options are 1*length(N-1) (for not hanging one) + 1*length(N-2) (for hanging one). That's identical to the Fibonacci series, so you take the 22nd number (0,1 pegs correspond to 1 option, 2 pegs has 2 options, 3 pegs has 3 options, 4 pegs has 5 options etc.) and that is:
[(0,1),(1,1),(2,2),(3,3),(4,5),(5,8),(6,13),(7,21),
(8,34),(9,55),(10,89),(11,144),(12,233),(13,377),
(14,610),(15,987),(16,1597),(17,2584),(18,4181),
(19,6765),(20,10946),(21,17711),(22,28657),
(23,46368),(24,75025),(25,121393),(26,196418),
(27,317811),(28,514229),(29,832040)]
So, that's 28657. No, I didn't calculate that row myself, I let haskell do it for me:
Code: Select all
numfibrow :: [(Int, Integer)]
numfibrow = zip [0..] fibrow
fibrow :: [Integer]
fibrow = 1 : 1 : zipWith (+) fibrow (tail fibrow)