It was really nice question at Math Kangaroo Contest 2013
Four cars enter a roundabout at the same time, each one from a different direction, as shown in the diagram. Each of the cars drives less than a full round of the roundabout, and no two cars leave the roundabout in the same direction. How many different ways are there for the cars to leave the roundabout?
I would like to introduce elegant solution in scheme
(let ([src '(A B C D)])
(length ( filter-not
(lambda(x)
(ormap eq? x src))
(permutations src)) )
)
So you can find correct answer for four cars (9) , five cars (44) and more
Enjoy!
No comments:
Post a Comment