Created
August 2, 2018 19:48
-
-
Save DanielCardonaRojas/69e6b9faf52f22514c18f9bbe3156bb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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