Skip to content

Instantly share code, notes, and snippets.

@cohama
Created April 11, 2014 11:15
Show Gist options
  • Save cohama/10459391 to your computer and use it in GitHub Desktop.
Save cohama/10459391 to your computer and use it in GitHub Desktop.
type Birds = Int
type Pole = (Birds, Birds)
-- 左に鳥が止まる
landLeft :: Birds -> Pole -> Maybe Pole
landLeft n (left, right)
| abs ((left + n) - right) < 4 = Just (left + n, right)
| otherwise = Nothing
-- 右に鳥が止まる
landRight :: Birds -> Pole -> Maybe Pole
landRight n (left, right)
| abs (left - (right + n)) < 4 = Just (left, right + n)
| otherwise = Nothing
(-:) :: a -> (a -> b) -> b
x -: f = f x
main :: IO ()
main = do
print $
(0, 0) -: landLeft 1 -: landRight 1 -: landLeft 2
print $
(0, 0) -: landLeft 1 -: landRight 4 -: landLeft (-1) -: landRight (-2)
banana :: Pole -> Maybe Pole
banana _ = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment