Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
15
Task/Pascals-triangle/8th/pascals-triangle-1.8th
Normal file
15
Task/Pascals-triangle/8th/pascals-triangle-1.8th
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
\ print the array
|
||||
: .arr \ a -- a
|
||||
( . space ) a:each ;
|
||||
|
||||
: pasc \ a --
|
||||
\ print the row
|
||||
.arr cr
|
||||
dup
|
||||
\ create two rows from the first, one with a leading the other with a trailing 0
|
||||
[0] 0 a:insert swap 0 a:push
|
||||
\ add the arrays together to make the new one
|
||||
' n:+ a:op ;
|
||||
|
||||
\ print the first 16 rows:
|
||||
[1] ' pasc 16 times
|
||||
21
Task/Pascals-triangle/8th/pascals-triangle-2.8th
Normal file
21
Task/Pascals-triangle/8th/pascals-triangle-2.8th
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
: ratio \ m n -- num denom
|
||||
tuck n:- n:1+ swap ;
|
||||
|
||||
\ one item in the row: n m
|
||||
: pascitem \ n m -- n
|
||||
r@ swap
|
||||
ratio
|
||||
n:*/ n:round int
|
||||
dup . space ;
|
||||
|
||||
\ One row of Pascal's triangle
|
||||
: pascline \ n --
|
||||
>r 1 int dup . space
|
||||
' pascitem
|
||||
1 r@ loop rdrop drop cr ;
|
||||
|
||||
\ Calculate the first 'n' rows of Pascal's triangle:
|
||||
: pasc \ n
|
||||
' pascline 0 rot loop cr ;
|
||||
|
||||
15 pasc
|
||||
Loading…
Add table
Add a link
Reference in a new issue