Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import Control.Monad
  2.  
  3. pointsInPolygon = 5
  4.  
  5. pointsInLoopAt n | n < pointsInPolygon = pointsInPolygon
  6. | n < pointsInPolygon * 3 = pointsInPolygon * 2
  7. | otherwise = pointsInPolygon
  8.  
  9. pointsToLoopAt n | n < pointsInPolygon = 0
  10. | n < pointsInPolygon * 3 = pointsInPolygon
  11. | otherwise = pointsInPolygon * 3
  12.  
  13. pointInLoop n = n - pointsToLoopAt(n)
  14.  
  15. direction1 n = (pointInLoop(n)-1)`mod`pointsInLoopAt(n) + pointsToLoopAt(n)
  16. direction2 n = (pointInLoop(n)+1)`mod`pointsInLoopAt(n) + pointsToLoopAt(n)
  17. direction3 n | n < pointsInPolygon = n + nextlink (pointInLoop(n))
  18. | n < pointsInPolygon * 3 && odd n = n - prevlink (pointInLoop(n)`div`2)
  19. | n < pointsInPolygon * 3 && even n = n + nextlink (pointInLoop(n)`div`2)
  20. | otherwise = n - prevlink (pointInLoop(n))
  21. where
  22. nextlink n = 13 - n * 3
  23. prevlink n = n * 3 + 1
  24.  
  25. describe n = putStrLn $ "From "
  26. ++ here
  27. ++ " you can reach "
  28. ++ one
  29. ++ ", "
  30. ++ two
  31. ++ ", or "
  32. ++ three
  33. where
  34. here = show n
  35. one = show (direction1 n)
  36. two = show (direction2 n)
  37. three = show (direction3 n)
  38.  
  39. main = mapM_ describe [0..19]
Add Comment
Please, Sign In to add comment