mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-02-14 08:48:05 +01:00
add enter
This commit is contained in:
parent
c7329e6bf4
commit
b4d5726791
1 changed files with 7 additions and 0 deletions
|
@ -25,21 +25,28 @@
|
||||||
|
|
||||||
def get_num(row, col)
|
def get_num(row, col)
|
||||||
return 1 if row == 0 || col == 0 || row == col
|
return 1 if row == 0 || col == 0 || row == col
|
||||||
|
|
||||||
get_num(row - 1, col - 1) + get_num(row - 1, col)
|
get_num(row - 1, col - 1) + get_num(row - 1, col)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_row(row_index)
|
def get_row(row_index)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
(row_index + 1).times do |i|
|
(row_index + 1).times do |i|
|
||||||
result.push(get_num(row_index, i))
|
result.push(get_num(row_index, i))
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
row_index = 3
|
row_index = 3
|
||||||
print(get_row(row_index))
|
print(get_row(row_index))
|
||||||
# => [1,3,3,1]
|
# => [1,3,3,1]
|
||||||
|
|
||||||
row_index = 0
|
row_index = 0
|
||||||
print(get_row(row_index))
|
print(get_row(row_index))
|
||||||
# => [1]
|
# => [1]
|
||||||
|
|
||||||
row_index = 1
|
row_index = 1
|
||||||
print(get_row(row_index))
|
print(get_row(row_index))
|
||||||
# => [1,1]
|
# => [1,1]
|
||||||
|
|
Loading…
Add table
Reference in a new issue