Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
auto pascal() /*pure nothrow*/ {
|
||||
auto pascal() pure nothrow {
|
||||
return [1].recurrence!q{ zip(a[n - 1] ~ 0, 0 ~ a[n - 1])
|
||||
.map!q{a[0] + a[1]}
|
||||
.map!q{ a[0] + a[1] }
|
||||
.array };
|
||||
}
|
||||
|
||||
|
|
|
|||
40
Task/Pascals-triangle/NetRexx/pascals-triangle.netrexx
Normal file
40
Task/Pascals-triangle/NetRexx/pascals-triangle.netrexx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
numeric digits 1000 -- allow very large numbers
|
||||
parse arg rows .
|
||||
if rows = '' then rows = 11 -- default to 11 rows
|
||||
printPascalTriangle(rows)
|
||||
return
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
method printPascalTriangle(rows = 11) public static
|
||||
lines = ''
|
||||
mx = (factorial(rows - 1) / factorial(rows % 2) / factorial(rows - 1 - rows % 2)).length() -- width of widest number
|
||||
|
||||
loop row = 1 to rows
|
||||
n1 = 1.center(mx)
|
||||
line = n1
|
||||
loop col = 2 to row
|
||||
n2 = col - 1
|
||||
n1 = n1 * (row - n2) / n2
|
||||
line = line n1.center(mx)
|
||||
end col
|
||||
lines[row] = line.strip()
|
||||
end row
|
||||
|
||||
-- display triangle
|
||||
ml = lines[rows].length() -- length of longest line
|
||||
loop row = 1 to rows
|
||||
say lines[row].centre(ml)
|
||||
end row
|
||||
|
||||
return
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
method factorial(n) public static
|
||||
fac = 1
|
||||
loop n_ = 2 to n
|
||||
fac = fac * n_
|
||||
end n_
|
||||
return fac /*calc. factorial*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue