Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,20 @@
PROGRAM FLOYD
!
! for rosettacode.org
!
BEGIN
N=14
NUM=1
LAST=(N^2-N+2) DIV 2
FOR ROW=1 TO N DO
FOR J=1 TO ROW DO
US$=STRING$(LEN(STR$(LAST-1+J))-1,"#")
WRITE(US$;NUM;)
PRINT(" ";)
NUM+=1
END FOR
PRINT
END FOR
END PROGRAM

View file

@ -0,0 +1,53 @@
' version 19-09-2015
' compile with: fbc -s console
Sub pascal_triangle(n As UInteger)
Dim As UInteger a = 1, b, i, j, switch = n + 1
Dim As String frmt, frmt_1, frmt_2
' last number of the last line
i = (n * (n + 1)) \ 2
frmt_2 = String(Len(Str(i)) + 1, "#")
' first number of the last line
i = ((n - 1) * n) \ 2 + 1
frmt_1 = String(Len(Str(i)) + 1, "#")
' we have 2 different formats strings
' find the point where we have to make the switch
If frmt_1 <> frmt_2 Then
j = i + 1
While Len(Str(i)) = Len(Str(J))
j = j + 1
Wend
switch = j - i
End If
Print "output for "; Str(n) : Print
For i = 1 To n
frmt = frmt_1
b = (i * (i + 1)) \ 2
For j = a To b
' if we have the switching point change format string
If j - a = switch Then frmt = frmt_2
Print Using frmt; j;
Next j
Print
a = b + 1
Next i
Print
End Sub
' ------=< MAIN >=------
pascal_triangle(5)
pascal_triangle(14)
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

View file

@ -0,0 +1,24 @@
define floyds_triangle(n::integer) => {
local(out = array(array(1)),comp = array, num = 1)
while(#out->size < #n) => {
local(new = array)
loop(#out->last->size + 1) => {
#num++
#new->insert(#num)
}
#out->insert(#new)
}
local(pad = #out->last->last->asString->size)
with line in #out do => {
local(lineout = string)
with i in #line do => {
#i != #line->first ? #lineout->append(' ')
#lineout->append((' '*(#pad - #i->asString->size))+#i)
}
#comp->insert(#lineout)
}
return #comp->join('\r')
}
floyds_triangle(5)
'\r\r'
floyds_triangle(14)

View file

@ -0,0 +1,24 @@
import strutils
proc floyd(rowcount = 5): seq[seq[int]] =
result = @[@[1]]
while result.len < rowcount:
let n = result[result.high][result.high] + 1
var row = newSeq[int]()
for i in n .. n + result[result.high].len:
row.add i
result.add row
proc pfloyd(rows) =
var colspace = newSeq[int]()
for n in rows[rows.high]: colspace.add(($n).len)
for row in rows:
for i, x in row:
stdout.write align($x, colspace[i])," "
echo ""
echo floyd()
for i in [5, 14]:
pfloyd(floyd(i))
echo ""

View file

@ -0,0 +1,9 @@
rows = 10
n = 0
for r = 1 to rows
for c = 1 to r
n = n + 1
see string(n) + " "
next
see nl
next

View file

@ -0,0 +1,10 @@
func floyd(rows, n=1) {
var max = Math.range_sum(1, rows);
var widths = (max-rows .. max-1 -> map{(.+n).to_s.len});
{ |r|
say %'#{1..r -> map{|i| "%#{widths[i-1]}d" % n++}.join(" ")}';
} * rows;
}
floyd(5); # or: floyd(5, 88);
floyd(14); # or: floyd(14, 900);

View file

@ -0,0 +1,23 @@
# floyd(n) creates an n-row floyd's triangle
def floyd(n):
def lpad(len): tostring | (((len - length) * " ") + .);
# Construct an array of widths.
# Assuming N is the last integer on the last row (i.e. (n+1)*n/2),
# the last row has n entries from (1+N-n) through N:
def widths:
((n+1)*n/2) as $N
| [range(1 + $N - n; $N + 1) | tostring | length];
# emit line k assuming it starts with the integer "start"
def line(start; k; widths):
reduce range(start; start+k) as $i
(""; . + ($i|lpad(widths[$i - start])) + " ");
widths as $widths
| (reduce range(0;n) as $row
( [0, ""]; # state: i, string
(.[0] + 1) as $i | .[1] as $string
| [ ($i + $row),
($string + "\n" + line($i; $row + 1; $widths )) ] )
| .[1] ) ;

View file

@ -0,0 +1 @@
(5,14) | "floyd(\(.)): \(floyd(.))\n"

View file

@ -0,0 +1,23 @@
$ jq -M -r -n -f floyds_triangle.jq > floyds_triangle.out
floyd(5):
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
floyd(14):
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 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105