Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Created August 2, 2018 19:48
Show Gist options
  • Save DanielCardonaRojas/69e6b9faf52f22514c18f9bbe3156bb2 to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/69e6b9faf52f22514c18f9bbe3156bb2 to your computer and use it in GitHub Desktop.
module Main exposing (main)
import Html exposing (Html)
numberRows = 5
generate : (a -> a) -> a -> Int -> List a
generate f seed n =
if n <= 0 then
[f seed]
else
f seed :: generate f (f seed) (n - 1)
pairwise =
List.scanl (\x acc -> (Tuple.second acc, x)) (1, 1)
>> List.drop 2
pascal =
pairwise
>> List.map (\(x,y) -> x + y) >> (\l -> [1] ++ l) >> (\l -> l ++ [1])
main : Html msg
main =
generate pascal [1, 1] numberRows
|> List.map (String.join " " << List.map toString)
|> List.map (\row -> Html.div [] [ Html.text row ])
|> Html.div []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment