Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
63
Task/Mertens-function/Cowgol/mertens-function.cowgol
Normal file
63
Task/Mertens-function/Cowgol/mertens-function.cowgol
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
include "cowgol.coh";
|
||||
|
||||
const MAX := 1000;
|
||||
|
||||
# Table output
|
||||
sub printtab(n: int8) is
|
||||
if n<0 then
|
||||
print_char('-');
|
||||
n := -n;
|
||||
else
|
||||
print_char(' ');
|
||||
end if;
|
||||
print_char(n as uint8 + '0');
|
||||
print_char(' ');
|
||||
end sub;
|
||||
|
||||
# Generate Merten numbers
|
||||
var M: int8[MAX+1];
|
||||
M[0] := 0;
|
||||
M[1] := 1;
|
||||
|
||||
var n: @indexof M := 2;
|
||||
while n < @sizeof M loop
|
||||
M[n] := 1;
|
||||
var k: @indexof M := 2;
|
||||
while k <= n loop
|
||||
M[n] := M[n] - M[n/k];
|
||||
k := k + 1;
|
||||
end loop;
|
||||
n := n + 1;
|
||||
end loop;
|
||||
|
||||
# Find zeroes and crossings
|
||||
var zero: uint8 := 0;
|
||||
var cross: uint8 := 0;
|
||||
n := 1;
|
||||
while n < @sizeof M loop
|
||||
if M[n] == 0 then
|
||||
zero := zero + 1;
|
||||
if M[n-1] != 0 then
|
||||
cross := cross + 1;
|
||||
end if;
|
||||
end if;
|
||||
n := n + 1;
|
||||
end loop;
|
||||
|
||||
# Print table
|
||||
print("The first 99 Mertens numbers are:\n");
|
||||
print(" ");
|
||||
n := 1;
|
||||
var col: uint8 := 9;
|
||||
while n < 100 loop
|
||||
printtab(M[n]);
|
||||
col := col - 1;
|
||||
if col == 0 then
|
||||
print_nl();
|
||||
col := 10;
|
||||
end if;
|
||||
n := n + 1;
|
||||
end loop;
|
||||
|
||||
print("M(n) is zero "); print_i8(zero); print(" times\n");
|
||||
print("M(n) crosses zero "); print_i8(cross); print(" times\n");
|
||||
Loading…
Add table
Add a link
Reference in a new issue