aboutsummaryrefslogtreecommitdiff
path: root/challenge-286/asherbhs/haskell/ch-2.hs
blob: 5785cb8ae892fe3107fc7d2ed9195784b1c9bdd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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]