diff options
Diffstat (limited to 'challenge-286/asherbhs/haskell/ch-2.hs')
| -rw-r--r-- | challenge-286/asherbhs/haskell/ch-2.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-286/asherbhs/haskell/ch-2.hs b/challenge-286/asherbhs/haskell/ch-2.hs new file mode 100644 index 0000000000..5785cb8ae8 --- /dev/null +++ b/challenge-286/asherbhs/haskell/ch-2.hs @@ -0,0 +1,20 @@ +orderGame :: [Int] -> Int +orderGame ints = head $ foldr + (\_ ints -> zipWith + ($) + (cycle $ map uncurry [min, max]) + (pairUp ints) + ) + ints + [1 .. logBase 2 $ fromIntegral $ length ints] + where + pairUp :: [a] -> [(a, a)] + pairUp [] = [] + pairUp (x : y : xs) = (x, y) : pairUp xs + + +main :: IO () +main = do + print $ orderGame [2, 1, 4, 5, 6, 3, 0, 2] + print $ orderGame [0, 5, 3, 2] + print $ orderGame [9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8] |
