I am doing project euler question 136, and came up with the following to test the example given:
module Main where
import Data.List
unsum x y z n = (y > 0) && (z > 0) && (((x*x) - (y*y)- (z*z)) == n) && ((x - y) == (y - z))
answer = snub $ takeWhile (<100) [n|x<-[1..],d<-[1..x`div`2],n<-[x..100],y<-[x-d],z<-[y-d], unsum x y z n ]
where
snub [] = []
snub (x:xs) | elem x xs = snub (filter (/=x) xs)
| otherwise = x : snub xs
snub
will remove any numbers that are duplicates from a list.
The example is supposed to give 25 solutions for n
where x^2 - y^2 - z^2 == n
and all numbers are positive (or so I gather from the question) and are an arithmetic progression such that x-y == y-z
. But when I use the code, a list of 11 solutions for n
are returned.
What have I done wrong in my list comprehension and are there any optimisations I have missed out?