'How can I make this mountain Haskell code work?
How can I put the 2 list in 1 list, because this code only give me back the fisrt list.
mountain :: Int -> [Int]
mountain 0 = [0]
mountain 1 = [0]
mountain 2 = [0,2,0]
mountain 3 = [0,2,0]
mountain x
| x `mod` 2 == 0 = [0,2..x] ++ [x-2..0]
| otherwise = [0,2..x-1] ++ [x-3..0]
Examples:
--mountain 0 == [0]
--mountain 6 == [0,2,4,6,4,2,0]
--mountain 7 == [0,2,4,6,4,2,0]
--mountain 10 == [0,2,4,6,8,10,8,6,4,2,0]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
