All pastes #800415 Raw Edit

Miscellany

public text v1 · immutable
#800415 ·published 2007-11-28 12:51 UTC
rendered paste body
problem4 = head $ sortBy greatestFirst $ filter isPalindrome $ zipWith (*) [999,998..100] [999,998..100]

greatestFirst :: Ord a => a -> a -> Ordering
greatestFirst x y = switch $ compare x y
                    where
                      switch EQ = EQ
                      switch LT = GT
                      switch GT = LT

isPalindrome :: Integer -> Bool
isPalindrome x = digits x == reverse (digits x)

digits :: Integral a => a -> [a]
digits x
  | x < 10    = [x]
  | otherwise = x `mod` 10 : (digits (x `div` 10))