Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- pointsInPolygon = 5
- pointsInLoopAt n | n < pointsInPolygon = pointsInPolygon
- | n < pointsInPolygon * 3 = pointsInPolygon * 2
- | otherwise = pointsInPolygon
- pointsToLoopAt n | n < pointsInPolygon = 0
- | n < pointsInPolygon * 3 = pointsInPolygon
- | otherwise = pointsInPolygon * 3
- pointInLoop n = n - pointsToLoopAt(n)
- direction1 n = (pointInLoop(n)-1)`mod`pointsInLoopAt(n) + pointsToLoopAt(n)
- direction2 n = (pointInLoop(n)+1)`mod`pointsInLoopAt(n) + pointsToLoopAt(n)
- direction3 n | n < pointsInPolygon = n + nextlink (pointInLoop(n))
- | n < pointsInPolygon * 3 && odd n = n - prevlink (pointInLoop(n)`div`2)
- | n < pointsInPolygon * 3 && even n = n + nextlink (pointInLoop(n)`div`2)
- | otherwise = n - prevlink (pointInLoop(n))
- where
- nextlink n = 13 - n * 3
- prevlink n = n * 3 + 1
- describe n = putStrLn $ "From "
- ++ here
- ++ " you can reach "
- ++ one
- ++ ", "
- ++ two
- ++ ", or "
- ++ three
- where
- here = show n
- one = show (direction1 n)
- two = show (direction2 n)
- three = show (direction3 n)
- main = mapM_ describe [0..19]
Add Comment
Please, Sign In to add comment