condition x = (~.empty) [y | y <- [100..999] ; divides y x ; (x/y)<1000 ]
isPalindrome len val = (take len (itoa val))=((reverse.drop len) (itoa val))
pali6 = reverse [x| x <- [100000..999999]; isPalindrome 3 x]
answer = hd [x | x <- pali6 ; condition x]
divides y x = (x%y = 0)
Those familiar with haskell should probably be able to understand this. It takes about half a minute to evaluate, which is probably because I first calculate all the palindromes and then check them. Also, it should be possible to do the whole thing in one line, but it gets kinda hard to read that way.
No comments:
Post a Comment