The pronlem is from a book and the ans is hard to follow, in fact I can't quite see it yet. Ans turns out to be = 1 - 1/2! + 1/3! - ... + 1/39! - 1/40! where n! = n factorial ie n(n-1)(n-2)...1 and this is the first 41 terms in the expansion of exp(-1). It is like the Fibonacci sequence that governs the whorls of a seashell. Math is a beautifil thing.
You are on the right track cerhob and Anna. It is usually called The Hat-Matching Pronlem.
Anna, you must swing both ways, moi aussi! would love to get together.