September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,32 @@
|
|||
def do_until(condition; next):
|
||||
def u: if condition then . else (next|u) end;
|
||||
u;
|
||||
|
||||
def mdroot(n):
|
||||
def multiply: reduce .[] as $i (1; .*$i);
|
||||
# state: [mdr, persist]
|
||||
[n, 0]
|
||||
| do_until( .[0] < 10;
|
||||
[(.[0] | tostring | explode | map(.-48) | multiply), .[1] + 1]
|
||||
);
|
||||
|
||||
# Produce a table with 10 rows (numbered from 0),
|
||||
# showing the first n numbers having the row-number as the mdr
|
||||
def tabulate(n):
|
||||
# state: [answer_matrix, next_i]
|
||||
def tab:
|
||||
def minlength: map(length) | min;
|
||||
.[0] as $matrix
|
||||
| .[1] as $i
|
||||
| if (.[0]|minlength) == n then .[0]
|
||||
else (mdroot($i) | .[0]) as $mdr
|
||||
| if $matrix[$mdr]|length < n then
|
||||
($matrix[$mdr] + [$i]) as $row
|
||||
| $matrix | setpath([$mdr]; $row)
|
||||
else $matrix
|
||||
end
|
||||
| [ ., $i + 1 ]
|
||||
| tab
|
||||
end;
|
||||
|
||||
[[], 0] | tab;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
def neatly:
|
||||
. as $in
|
||||
| range(0;length)
|
||||
| "\(.): \($in[.])";
|
||||
|
||||
def rjust(n): tostring | (n-length)*" " + .;
|
||||
|
||||
# The task:
|
||||
" i : [MDR, MP]",
|
||||
((123321, 7739, 893, 899998) as $i
|
||||
| "\($i|rjust(6)): \(mdroot($i))"),
|
||||
"",
|
||||
"Tabulation",
|
||||
"MDR: [n0..n4]",
|
||||
(tabulate(5) | neatly)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
$ jq -n -r -c -f mdr.jq
|
||||
|
||||
i : [MDR, MP]
|
||||
123321: [8,3]
|
||||
7739: [8,3]
|
||||
893: [2,3]
|
||||
899998: [0,2]
|
||||
|
||||
Tabulation
|
||||
MDR: [n0..n4]
|
||||
0: [0,10,20,25,30]
|
||||
1: [1,11,111,1111,11111]
|
||||
2: [2,12,21,26,34]
|
||||
3: [3,13,31,113,131]
|
||||
4: [4,14,22,27,39]
|
||||
5: [5,15,35,51,53]
|
||||
6: [6,16,23,28,32]
|
||||
7: [7,17,71,117,171]
|
||||
8: [8,18,24,29,36]
|
||||
9: [9,19,33,91,119]
|
||||
Loading…
Add table
Add a link
Reference in a new issue