Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Floyds-triangle/Jq/floyds-triangle-1.jq
Normal file
23
Task/Floyds-triangle/Jq/floyds-triangle-1.jq
Normal 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] ) ;
|
||||
1
Task/Floyds-triangle/Jq/floyds-triangle-2.jq
Normal file
1
Task/Floyds-triangle/Jq/floyds-triangle-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
(5,14) | "floyd(\(.)): \(floyd(.))\n"
|
||||
23
Task/Floyds-triangle/Jq/floyds-triangle-3.jq
Normal file
23
Task/Floyds-triangle/Jq/floyds-triangle-3.jq
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue