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,28 @@
import strutils, future
template newSeqWith(len: int, init: expr): expr =
var result {.gensym.} = newSeq[type(init)](len)
for i in 0 .. <len:
result[i] = init
result
proc mdroot(n): tuple[mp, mdr: int] =
var mdr = @[n]
while mdr[mdr.high] > 9:
var n = 1
for dig in $mdr[mdr.high]:
n *= parseInt($dig)
mdr.add n
(mdr.high, mdr[mdr.high])
for n in [123321, 7739, 893, 899998]:
echo align($n, 6)," ",mdroot(n)
echo ""
var table = newSeqWith(10, newSeq[int]())
for n in 0..int.high:
if table.map((x: seq[int]) => x.len).min >= 5: break
table[mdroot(n).mdr].add n
for mp, val in table:
echo mp,": ",val[0..4]

View file

@ -0,0 +1,23 @@
func mdroot(n) {
var (mdr, persist) = (n, 0)
while (mdr >= 10) {
mdr = mdr.digits.product
++persist
}
[mdr, persist]
}
say "Number: MDR MP\n====== === =="
[123321, 7739, 893, 899998].each{|n| "%6d: %3d %3d\n" \
.printf(n, mdroot(n)...) }
var counter = Hash()
Inf.times { |i|
var j = i-1
counter{mdroot(j).first} := [] << j
break if counter.values.all {|v| v.len >= 5 }
}
say "\nMDR: [n0..n4]\n=== ========"
10.times {|i| "%3d: %s\n".printf(i-1, counter{i-1}.first(5)) }

View file

@ -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;

View file

@ -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)

View file

@ -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]