Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Digital-root/Jq/digital-root-1.jq
Normal file
20
Task/Digital-root/Jq/digital-root-1.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def do_until(condition; next):
|
||||
def u: if condition then . else (next|u) end;
|
||||
u;
|
||||
|
||||
# n may be a decimal number or a string representing a decimal number
|
||||
def digital_root(n):
|
||||
# string-only version
|
||||
def dr:
|
||||
# state: [mdr, persist]
|
||||
do_until( .[0] | length == 1;
|
||||
[ (.[0] | explode | map(.-48) | add | tostring), .[1] + 1 ]
|
||||
);
|
||||
[n|tostring, 0] | dr | .[0] |= tonumber;
|
||||
|
||||
def neatly:
|
||||
. as $in
|
||||
| range(0;length)
|
||||
| "\(.): \($in[.])";
|
||||
|
||||
def rjust(n): tostring | (n-length)*" " + .;
|
||||
8
Task/Digital-root/Jq/digital-root-2.jq
Normal file
8
Task/Digital-root/Jq/digital-root-2.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(
|
||||
" i : [DR, P]",
|
||||
(961038, 923594037444, 670033, 448944221089
|
||||
) as $i
|
||||
| "\($i|rjust(12)): \(digital_root($i))"
|
||||
),
|
||||
"",
|
||||
"digital_root(\"1\" * 100000) => \(digital_root( "1" * 100000))"
|
||||
9
Task/Digital-root/Jq/digital-root-3.jq
Normal file
9
Task/Digital-root/Jq/digital-root-3.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$ jq -M -n -r -c -f Digital_root.jq
|
||||
|
||||
i : [DR, P]
|
||||
961038: [9,2]
|
||||
923594037444: [9,2]
|
||||
670033: [1,3]
|
||||
448944221089: [1,3]
|
||||
|
||||
digital_root("1" * 100000) => [1,2]
|
||||
Loading…
Add table
Add a link
Reference in a new issue