elm/exercises/pascals-triangle/Triangle.example.elm

24 lines
401 B
Elm
Raw Permalink Normal View History

2017-10-07 18:38:24 +00:00
module Triangle exposing (rows)
import List
nextRow : List Int -> List Int
nextRow row =
List.map2 (+) (0 :: row) (row ++ [ 0 ])
rows : Int -> List (List Int)
rows n =
let
loop i row =
if i == n then
[]
else
row :: loop (i + 1) (nextRow row)
in
2017-10-07 23:52:05 +00:00
if n < 0 then
[]
else
loop 0 [ 1 ]