Skip to content

Instantly share code, notes, and snippets.

@na2hiro
Last active August 29, 2015 14:02
Show Gist options
  • Save na2hiro/644abf412359521851d7 to your computer and use it in GitHub Desktop.
Save na2hiro/644abf412359521851d7 to your computer and use it in GitHub Desktop.
import Data.List(sort, nub)
makeNumByN :: [[Integer]]
makeNumByN = [0..9] : map f [0..] -- memoize
where f k = nub$sort$ do
l<-[0..k]
a<-makeNumByN!!l
b<-makeNumByN!!(k-l)
[a*b, a+b, if a>b then a-b else b-a] -- negative value has no meaning
search :: Integer->Integer
search n = fst. head. dropWhile(\(_,xs)->not$ elem n xs). zip [1..]$ makeNumByN
main = print$ search 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment