Now that the eldest is in big school, her maths homework is starting to get fun! Admittedly I think I was more excited than her by one of the questions she came home with recently:

“So-and-so” has a number of CDs [They won’t be able to use this question for much longer, will they?]. When they are put in piles of two, three and four there is one CD left over, but when in piles of seven there are none left over. What is the smallest number of CDs “So-and-so” can have?

I mean, doesn’t this just excite you and get your mental juices flowing? I hope she starts to get more questions like this as opposed to the huge stack of long multiplication and division she has currently; I am very impressed at how quick she can perform her long multiplication and division, far quicker than I can, but it’s just not fun maths.

Any way, this belatedly popped up in my head again as I realised it would be a perfect fit for Haskell’s list comprehensions:

head [x | x <- [7, 14..], 1== mod x 2, 1==mod x 3, 1==mod x 4]

This actually fits the approach she used on paper, i.e. go through the seven times table and for each value check to see if that value minus one was also in the two, three and four times tables. Why don’t schools use Haskell in maths lessons? Seems like a good fit.

[EDIT: 2013-10-12] @pchapuis kindly pointed out that this could be reduced to head [x | x <- [7, 14..], 1==mod x 12] through the use of lowest common multiples. Neat.