Better HN
topnewbestaskshowjobs
Log inSign up

ctaylor001

4 karma · joined Dec 15, 2014 (11y ago) · 2 submissions

Submissions

comment 11y ago · link · parent

I feel like this is a roman à clef and I'm missing the clef.

What's the story with the repeated John Carpenter references?

comment 11y ago · link · parent

Haskell -

  fib (Just n) Nothing = Just (fibs !! n)
  fib Nothing (Just x) = let (n, x') = head (filter (\(_,y) -> y >= x) (enumerate fibs))
    in if x == x' then Just n else Nothing

  fibs = 1 : 1 : zipWith (+) fibs (tail fibs)

  enumerate = zip [0..]
I think that should work! It's a bit undefined what happens if you supply both arguments, or neither. It would be better to use Either Integer Integer as the input instead of a pair of Maybe Integer.

Of course there's always the LogicT monad if you want to do it "properly".