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
|
||||
17
Task/Pascals-triangle/ERRE/pascals-triangle.erre
Normal file
17
Task/Pascals-triangle/ERRE/pascals-triangle.erre
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
PROGRAM PASCAL_TRIANGLE
|
||||
|
||||
PROCEDURE PASCAL(R%)
|
||||
LOCAL I%,C%,K%
|
||||
FOR I%=0 TO R%-1 DO
|
||||
C%=1
|
||||
FOR K%=0 TO I% DO
|
||||
WRITE("###";C%;)
|
||||
C%=(C%*(I%-K%)) DIV (K%+1)
|
||||
END FOR
|
||||
PRINT
|
||||
END FOR
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
PASCAL(9)
|
||||
END PROGRAM
|
||||
37
Task/Pascals-triangle/FreeBASIC/pascals-triangle.freebasic
Normal file
37
Task/Pascals-triangle/FreeBASIC/pascals-triangle.freebasic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub pascalTriangle(n As UInteger)
|
||||
If n = 0 Then Return
|
||||
Dim prevRow(1 To n) As UInteger
|
||||
Dim currRow(1 To n) As UInteger
|
||||
Dim start(1 To n) As UInteger ''stores starting column for each row
|
||||
start(n) = 1
|
||||
For i As Integer = n - 1 To 1 Step -1
|
||||
start(i) = start(i + 1) + 3
|
||||
Next
|
||||
prevRow(1) = 1
|
||||
Print Tab(start(1));
|
||||
Print 1U
|
||||
For i As UInteger = 2 To n
|
||||
For j As UInteger = 1 To i
|
||||
If j = 1 Then
|
||||
Print Tab(start(i)); "1";
|
||||
currRow(1) = 1
|
||||
ElseIf j = i Then
|
||||
Print " 1"
|
||||
currRow(i) = 1
|
||||
Else
|
||||
currRow(j) = prevRow(j - 1) + prevRow(j)
|
||||
Print Using "######"; currRow(j); " ";
|
||||
End If
|
||||
Next j
|
||||
For j As UInteger = 1 To i
|
||||
prevRow(j) = currRow(j)
|
||||
Next j
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
pascalTriangle(14)
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
5
Task/Pascals-triangle/FunL/pascals-triangle-1.funl
Normal file
5
Task/Pascals-triangle/FunL/pascals-triangle-1.funl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import lists.zip
|
||||
|
||||
def
|
||||
pascal( 1 ) = [1]
|
||||
pascal( n ) = [1] + map( (a, b) -> a + b, zip(pascal(n-1), pascal(n-1).tail()) ) + [1]
|
||||
3
Task/Pascals-triangle/FunL/pascals-triangle-2.funl
Normal file
3
Task/Pascals-triangle/FunL/pascals-triangle-2.funl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import integers.choose
|
||||
|
||||
def pascal( n ) = [choose( n - 1, k ) | k <- 0..n-1]
|
||||
11
Task/Pascals-triangle/FunL/pascals-triangle-3.funl
Normal file
11
Task/Pascals-triangle/FunL/pascals-triangle-3.funl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def triangle( height ) =
|
||||
width = max( map(a -> a.toString().length(), pascal(height)) )
|
||||
|
||||
if 2|width
|
||||
width++
|
||||
|
||||
for n <- 1..height
|
||||
print( ' '*((width + 1)\2)*(height - n) )
|
||||
println( map(a -> format('%' + width + 'd ', a), pascal(n)).mkString() )
|
||||
|
||||
triangle( 10 )
|
||||
9
Task/Pascals-triangle/Nim/pascals-triangle.nim
Normal file
9
Task/Pascals-triangle/Nim/pascals-triangle.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sequtils
|
||||
|
||||
proc pascal(n: int) =
|
||||
var row = @[1]
|
||||
for r in 1..n:
|
||||
echo row
|
||||
row = zip(row & @[0], @[0] & row).mapIt(int, it[0] + it[1])
|
||||
|
||||
pascal(10)
|
||||
1
Task/Pascals-triangle/Oforth/pascals-triangle.oforth
Normal file
1
Task/Pascals-triangle/Oforth/pascals-triangle.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: pascal(n) [ 1 ] #[ dup println dup 0 + 0 rot + zipWith(#+) ] times(n) drop ;
|
||||
12
Task/Pascals-triangle/Phix/pascals-triangle.phix
Normal file
12
Task/Pascals-triangle/Phix/pascals-triangle.phix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
sequence row = {}
|
||||
for m = 1 to 13 do
|
||||
row = row & 1
|
||||
for n=length(row)-1 to 2 by -1 do
|
||||
row[n] += row[n-1]
|
||||
end for
|
||||
printf(1,repeat(' ',(13-m)*2))
|
||||
for i=1 to length(row) do
|
||||
printf(1," %3d",row[i])
|
||||
end for
|
||||
puts(1,'\n')
|
||||
end for
|
||||
18
Task/Pascals-triangle/Potion/pascals-triangle.potion
Normal file
18
Task/Pascals-triangle/Potion/pascals-triangle.potion
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
printpascal = (n) :
|
||||
if (n < 1) :
|
||||
1 print
|
||||
(1)
|
||||
. else :
|
||||
prev = printpascal(n - 1)
|
||||
prev append(0)
|
||||
curr = (1)
|
||||
n times (i):
|
||||
curr append(prev(i) + prev(i + 1))
|
||||
.
|
||||
"\n" print
|
||||
curr join(", ") print
|
||||
curr
|
||||
.
|
||||
.
|
||||
|
||||
printpascal(read number integer)
|
||||
10
Task/Pascals-triangle/Ring/pascals-triangle.ring
Normal file
10
Task/Pascals-triangle/Ring/pascals-triangle.ring
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
row = 5
|
||||
for i = 0 to row - 1
|
||||
col = 1
|
||||
see left(" ",row-i)
|
||||
for k = 0 to i
|
||||
see "" + col + " "
|
||||
col = col*(i-k)/(k+1)
|
||||
next
|
||||
see nl
|
||||
next
|
||||
9
Task/Pascals-triangle/Sidef/pascals-triangle.sidef
Normal file
9
Task/Pascals-triangle/Sidef/pascals-triangle.sidef
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
func pascal(rows) {
|
||||
var row = [1];
|
||||
{ | n|
|
||||
say row.join(' ');
|
||||
row = [1, 0..(n-2).map {|i| row[i] + row[i+1] }..., 1];
|
||||
} * rows;
|
||||
}
|
||||
|
||||
pascal(10);
|
||||
11
Task/Pascals-triangle/jq/pascals-triangle-1.jq
Normal file
11
Task/Pascals-triangle/jq/pascals-triangle-1.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# pascal(n) for n>=0; pascal(0) emits an empty stream.
|
||||
def pascal(n):
|
||||
def _pascal: # input: the previous row
|
||||
. as $in
|
||||
| .,
|
||||
if length >= n then empty
|
||||
else
|
||||
reduce range(0;length-1) as $i
|
||||
([1]; . + [ $in[$i] + $in[$i + 1] ]) + [1] | _pascal
|
||||
end;
|
||||
if n <= 0 then empty else [1] | _pascal end ;
|
||||
6
Task/Pascals-triangle/jq/pascals-triangle-2.jq
Normal file
6
Task/Pascals-triangle/jq/pascals-triangle-2.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$ jq -c -n -f pascal_triangle.jq
|
||||
[1]
|
||||
[1,1]
|
||||
[1,2,1]
|
||||
[1,3,3,1]
|
||||
[1,4,6,4,1]
|
||||
9
Task/Pascals-triangle/jq/pascals-triangle-3.jq
Normal file
9
Task/Pascals-triangle/jq/pascals-triangle-3.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def pascal(n):
|
||||
if n <= 0 then empty
|
||||
else [1]
|
||||
| recurse( if length >= n then empty
|
||||
else . as $in
|
||||
| reduce range(0;length-1) as $i
|
||||
([1]; . + [ $in[$i] + $in[$i + 1] ]) + [1]
|
||||
end)
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue