Skip to content

Instantly share code, notes, and snippets.

@dmalikov
Created January 2, 2012 05:32
Show Gist options
  • Save dmalikov/1549475 to your computer and use it in GitHub Desktop.
Save dmalikov/1549475 to your computer and use it in GitHub Desktop.
Project Euler 112 (2s)
import PECore (numToList, listToNum)
import Control.Monad (ap)
import Data.List (sort)
bouncy :: (Num a, Ord a) => [a] -> Bool
bouncy = not . (\x -> all (>=0) x || all (<=0) x) . map (uncurry (-)) . ap zip tail
bouncyNumber :: Integer -> Bool
bouncyNumber = bouncy . numToList
main = print . snd . head . dropWhile ( (/= 990) . fst ) . map ( \(x,y) -> (1000 * x `div` y, y) ) . ( zip `ap` filter bouncyNumber ) $ [1..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment