Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
27
Task/Flatten-a-list/Elm/flatten-a-list.elm
Normal file
27
Task/Flatten-a-list/Elm/flatten-a-list.elm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import Graphics.Element exposing (show)
|
||||
|
||||
type Tree a
|
||||
= Leaf a
|
||||
| Node (List (Tree a))
|
||||
|
||||
flatten : Tree a -> List a
|
||||
flatten tree =
|
||||
case tree of
|
||||
Leaf a -> [a]
|
||||
Node list -> List.concatMap flatten list
|
||||
|
||||
-- [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
|
||||
tree : Tree Int
|
||||
tree = Node
|
||||
[ Node [Leaf 1]
|
||||
, Leaf 2
|
||||
, Node [Node [Leaf 3, Leaf 4], Leaf 5]
|
||||
, Node [Node [Node []]]
|
||||
, Node [Node [Node [Leaf 6]]]
|
||||
, Leaf 7
|
||||
, Leaf 8
|
||||
, Node []
|
||||
]
|
||||
|
||||
main =
|
||||
show (flatten tree)
|
||||
Loading…
Add table
Add a link
Reference in a new issue