Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# For the sake of gojq
def _nwise($n):
def nw: if length <= $n then . else .[0:$n] , (.[$n:] | nw) end;
nw;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;

View file

@ -0,0 +1,21 @@
# proper_divisors returns a stream of unordered proper divisors of the input integer.
def proper_divisors:
. as $n
| if $n > 1 then 1,
( range(2; 1 + (sqrt|floor)) as $i
| if ($n % $i) == 0 then $i,
(($n / $i) | if . == $i then empty else . end)
else empty
end)
else empty
end;
def composite:
[limit(2; proper_divisors)] | length == 2;
def arithmetic_numbers:
def average_is_integral(s):
reduce s as $_ ({}; .sum += $_ | .n += 1)
| (.sum % .n) == 0;
1, (range(2; infinite) | select(average_is_integral(., proper_divisors)));

View file

@ -0,0 +1,18 @@
def task1($limit):
[limit($limit; arithmetic_numbers)] | _nwise(10) | map(lpad(4)) | join(" ");
# $points should be a stream of integers, in order, specifying the reporting points
def task2($points):
last($points) as $last
| label $out
| foreach arithmetic_numbers as $n ({count:0};
.count += 1
| if $n | composite then .composite += 1 else . end;
(select( .count | IN( $points) ) | .n = $n),
if .count == $last then break $out else empty end );
task1(100),
"",
(task2( 1000, 10000, 100000, 1000000 )
| "The \(.count)th arithmetic number is \(.n);",
"there are \(.composite) composite arithmetic numbers up to \(.n).\n")