aboutsummaryrefslogtreecommitdiff
path: root/challenge-268/asherbhs/haskell/ch-2.hs
blob: f6724f5cbcf189f440f7f56ebf6afe325c567c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import Data.List (sort)

numberGame :: [Int] -> [Int]
numberGame = flipAdjacent . sort
  where
    flipAdjacent :: [Int] -> [Int]
    flipAdjacent [] = []
    flipAdjacent (x : y : t) = y : x : flipAdjacent t

main :: IO ()
main = do
    print $ numberGame [2, 5, 3, 4]
    print $ numberGame [9, 4, 1, 3, 6, 4, 6, 1]
    print $ numberGame [1, 2, 2, 3]