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,19 @@
def sum(s): reduce s as $x (null; . + $x);
def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
# input: an array
# output: number of crossings at $value
def count_crossings($value):
. as $a
| reduce range(0; length) as $i ({};
if $a[$i] == $value
then if $i == 0 or .prev != $value then .count += 1 else . end
else .
end
| .prev = $a[$i] )
| .count;

View file

@ -0,0 +1,8 @@
# Input: $max >= 1
# Output: an array of size $max with $max mertenNumbers beginning with 1
def mertensNumbers:
. as $max
| reduce range(2; $max + 1) as $n ( [1];
.[$n-1]=1
| reduce range(2; $n+1) as $k (.;
.[$n-1] -= .[($n / $k) | floor - 1] ));

View file

@ -0,0 +1,22 @@
# Task 0:
def mertens_number:
mertensNumbers[.-1];
def task1:
"The first \(.) Mertens numbers are:",
(mertensNumbers | nwise(10) | map(lpad(2)) | join(" ") );
def task2:
. as $n
| sum(mertensNumbers[] | select(.==0) | 1)
| "M(n) is zero \(.) times for 1 <= n <= \($n)\n";
def task3:
. as $n
| mertensNumbers
| count_crossings(0)
| "M(n) crosses zero \(.) times for 1 <= n <= \($n).\n" ;
(99|task1),
"",
(1000 | (task2, task3))