Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Created November 14, 2016 05:21
Show Gist options
  • Save chrisbuttery/a62adbf0522b831dfc5813b72f2cd3af to your computer and use it in GitHub Desktop.
Save chrisbuttery/a62adbf0522b831dfc5813b72f2cd3af to your computer and use it in GitHub Desktop.
elm-pascal
module Main exposing (..)
import Html exposing (..)
depth : number
depth =
10
main : Html msg
main =
div [] (pascal 1 1 1)
pascal : Int -> Int -> Int -> List (Html msg)
pascal c line i =
let
message =
text <| toString c ++ " "
next =
if i == line then
1
else
c * (line - i) // i
in
if line > depth then
[]
else if i == line then
message :: [ div [] (pascal 1 (line + 1) 1) ]
else
message :: pascal next line (i + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment