Mix.install([
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"},
{:tested_cell, github: "brooklinjazz/tested_cell"},
{:utils, path: "#{__DIR__}/../utils"}
])
Ensure you type the ea
keyboard shortcut to evaluate all Elixir cells before starting. Alternatively you can evaluate the Elixir cells as you read.
In this exercise, you're going to generate Pascal's Triangle for a certain number of rows.
In Pascal's Triangle, each number is the sum of the two integers above it.
flowchart
a[1]
b1[1]
b2[1]
c1[1]
c2[2]
c3[1]
d1[1]
d2[3]
d3[3]
d4[1]
e1[1]
e2[4]
e3[6]
e4[4]
e5[1]
a --> b1
a --> b2
b1 --> c1
b1 --> c2
b2 --> c2
b2 --> c3
c1 --> d1
c1 --> d2
c2 --> d2
c2 --> d3
c3 --> d3
c3 --> d4
d1 --> e1
d1 --> e2
d2 --> e2
d2 --> e3
d3 --> e3
d3 --> e4
d4 --> e4
d4 --> e5
We can also represent Pascal's triangle as a list of lists.
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 3, 6, 3, 1]]
In the Elixir cell below, finish the of/1
function in the Pascal
module which will
return Pascal's triangle in a list for n
number of rows.
Pascal.of(1)
[
[1]
]
Pascal.of(2)
[
[1],
[1, 1],
]
Pascal.of(5)
[
[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1]
]
Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.
$ git add .
$ git commit -m "finish pascals triangle exercise"
Previous | Next |
---|---|
Factorial | Computer Hardware |