aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/paulo-custodio/basic/ch-2.bas
blob: e2e14cece564f6b454502119be4aca8bf33c9771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
' Challenge 003
'
' Challenge #2
' Create a script that generates Pascal Triangle. Accept number of rows from
' the command line. The Pascal Triangle should have at least 3 rows. For more
' information about Pascal Triangle, check this wikipedia page.

sub draw_pascal(rows as integer)
    dim n(1, rows) as integer
    dim cur as integer, row as integer, col as integer

    cur = 0
    n(cur, 0) = 1
    for row=1 to rows
        ' print current row
        print space(rows-row);
        for col=0 to row-1: print n(cur,col);" ";: next col: print

        ' compute next row
        n(1-cur, 0) = 1: n(1-cur,row) = 1
        for col=1 to row-1: n(1-cur,col) = n(cur,col-1)+n(cur,col): next col
        cur = 1-cur
    next row
end sub

draw_pascal val(command(1))