Guest User

Untitled

a guest
Apr 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. solve k =
  2. if k == 0
  3. then 0
  4. else extract . dropWhile (notSameOddity k') . dropWhile (notIncludes k') . enhance $ [0..]
  5. where
  6. k' = abs k
  7. sums = scanl (+) 0 [1..]
  8. enhance = zip3 (cycle [0, 1, 1, 0]) sums
  9. first (x, _, _) = x
  10. second (_, x, _) = x
  11. third (_, _, x) = x
  12. notIncludes k = (< k) . second
  13. notSameOddity k = (/= k `rem` 2) . first
  14. extract = third . head
  15.  
  16. assertEq x y =
  17. if x == y
  18. then return ()
  19. else error $ "Assertion violated: first argument is " ++ show x ++ " but second argument is " ++ show y
  20.  
  21. assertEq' = uncurry assertEq
  22.  
  23. main = do
  24. assertEq' (solve 2, 3)
  25. assertEq' (solve 12, 7)
  26. putStrLn "Tests passed"
Add Comment
Please, Sign In to add comment