Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
28
Task/M-bius-function/ANSI-BASIC/m-bius-function.basic
Normal file
28
Task/M-bius-function/ANSI-BASIC/m-bius-function.basic
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
100 REM Moebius function
|
||||
110 DECLARE EXTERNAL FUNCTION Moebius
|
||||
120 FOR T = 0 TO 9
|
||||
130 FOR U = 1 TO 10
|
||||
140 PRINT USING "## ": Moebius(10 * T + U);
|
||||
150 NEXT U
|
||||
160 PRINT
|
||||
170 NEXT T
|
||||
180 END
|
||||
190 REM ***
|
||||
200 EXTERNAL FUNCTION Moebius(N)
|
||||
210 LET M = 1
|
||||
220 IF N <> 1 THEN
|
||||
230 LET F = 2
|
||||
240 DO
|
||||
250 IF MOD(N, (F * F)) = 0 THEN
|
||||
260 LET M = 0
|
||||
270 ELSE
|
||||
280 IF MOD(N, F) = 0 THEN
|
||||
290 LET M = -M
|
||||
300 LET N = N / F
|
||||
310 END IF
|
||||
320 LET F = F + 1
|
||||
330 END IF
|
||||
340 LOOP WHILE (F <= N) AND (M <> 0)
|
||||
350 END IF
|
||||
360 LET Moebius = M
|
||||
370 END FUNCTION
|
||||
37
Task/M-bius-function/ASIC/m-bius-function.asic
Normal file
37
Task/M-bius-function/ASIC/m-bius-function.asic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
REM Moebius function
|
||||
FOR T = 0 TO 9
|
||||
FOR U = 1 TO 10
|
||||
N = 10 * T
|
||||
N = N + U
|
||||
GOSUB CalcMoebius:
|
||||
PRINT M;
|
||||
NEXT U
|
||||
PRINT
|
||||
NEXT T
|
||||
END
|
||||
|
||||
CalcMoebius:
|
||||
REM Calculate Moebius(N). Result in M.
|
||||
REM NOTE. N changes its value.
|
||||
M = 1
|
||||
IF N <> 1 THEN
|
||||
F = 2
|
||||
StartLoop:
|
||||
FTo2 = F * F
|
||||
NModFTo2 = N MOD FTo2
|
||||
IF NModFTo2 = 0 THEN
|
||||
M = 0
|
||||
ELSE
|
||||
NModF = N MOD F
|
||||
IF NModF = 0 THEN
|
||||
M = -M
|
||||
N = N / F
|
||||
ENDIF
|
||||
F = F + 1
|
||||
ENDIF
|
||||
IF M = 0 THEN AfterLoop:
|
||||
IF F > N THEN AfterLoop:
|
||||
GOTO StartLoop:
|
||||
AfterLoop:
|
||||
ENDIF
|
||||
RETURN
|
||||
|
|
@ -6,12 +6,8 @@ for i to mu_max
|
|||
.
|
||||
for i = 2 to sqroot
|
||||
if mu[i] = 1
|
||||
for j = i step i to mu_max
|
||||
mu[j] *= -i
|
||||
.
|
||||
for j = i * i step i * i to mu_max
|
||||
mu[j] = 0
|
||||
.
|
||||
for j = i step i to mu_max : mu[j] *= -i
|
||||
for j = i * i step i * i to mu_max : mu[j] = 0
|
||||
.
|
||||
.
|
||||
for i = 2 to mu_max
|
||||
|
|
@ -25,10 +21,8 @@ for i = 2 to mu_max
|
|||
mu[i] = -1
|
||||
.
|
||||
.
|
||||
numfmt 0 3
|
||||
numfmt 3 0
|
||||
for i = 1 to 100
|
||||
write mu[i]
|
||||
if i mod 10 = 0
|
||||
print ""
|
||||
.
|
||||
if i mod 10 = 0 : print ""
|
||||
.
|
||||
|
|
|
|||
32
Task/M-bius-function/JavaScript/m-bius-function-1.js
Normal file
32
Task/M-bius-function/JavaScript/m-bius-function-1.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Moebius function
|
||||
|
||||
function moebius(n) {
|
||||
m = 1;
|
||||
if (n != 1) {
|
||||
f = 2;
|
||||
do {
|
||||
if (n % (f * f) == 0) {
|
||||
m = 0;
|
||||
} else {
|
||||
if (n % f == 0) {
|
||||
m = -m;
|
||||
n /= f;
|
||||
}
|
||||
f++;
|
||||
}
|
||||
} while (f <= n && m != 0);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
document.write("<table style=\"text-align:right\">");
|
||||
for (t = 0; t <= 9; t++) {
|
||||
document.write("<tr>");
|
||||
for (u = 1; u <= 10; u++) {
|
||||
document.write("<td>");
|
||||
document.write(moebius(10 * t + u));
|
||||
document.write("</td>");
|
||||
}
|
||||
document.write("</tr>");
|
||||
}
|
||||
document.write("</table>");
|
||||
7
Task/M-bius-function/JavaScript/m-bius-function-2.js
Normal file
7
Task/M-bius-function/JavaScript/m-bius-function-2.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script src="moebius.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
8
Task/M-bius-function/K/m-bius-function.k
Normal file
8
Task/M-bius-function/K/m-bius-function.k
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
mus:{ / values of mu(i) for i below x
|
||||
(~~!x) { / initial value: 0 1 1 1 1 ...
|
||||
y[z *1+!(-z )!x-1]*:-1 / flip sign
|
||||
y[z*z*1+!(-z*z)!x-1]:0 / set squares to zero
|
||||
y}[x]/ `pri x} / for each prime below x
|
||||
(μ:):{mus[1+0|/,//x]x}
|
||||
`0:"The first 100 values of the μ function:"
|
||||
`0:,/'-3$$μ 10 10#1+!100
|
||||
41
Task/M-bius-function/Modula-2/m-bius-function.mod2
Normal file
41
Task/M-bius-function/Modula-2/m-bius-function.mod2
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
MODULE Moebius;
|
||||
(* Moebius function *)
|
||||
FROM STextIO IMPORT
|
||||
WriteLn, WriteString;
|
||||
FROM SWholeIO IMPORT
|
||||
WriteInt;
|
||||
|
||||
VAR
|
||||
T, U: INTEGER;
|
||||
|
||||
PROCEDURE Moebius(N: INTEGER): INTEGER;
|
||||
VAR
|
||||
M, F: INTEGER;
|
||||
BEGIN
|
||||
M := 1;
|
||||
IF N <> 1 THEN
|
||||
F := 2;
|
||||
REPEAT
|
||||
IF N MOD (F * F) = 0 THEN
|
||||
M := 0
|
||||
ELSE
|
||||
IF N MOD F = 0 THEN
|
||||
M := -M;
|
||||
N := N DIV F
|
||||
END;
|
||||
F := F + 1
|
||||
END
|
||||
UNTIL (F > N) OR (M = 0)
|
||||
END;
|
||||
RETURN M
|
||||
END Moebius;
|
||||
|
||||
BEGIN
|
||||
FOR T := 0 TO 9 DO
|
||||
FOR U := 1 TO 10 DO
|
||||
WriteInt(Moebius(10 * T + U), 2);
|
||||
WriteString(' ')
|
||||
END;
|
||||
WriteLn
|
||||
END
|
||||
END Moebius.
|
||||
29
Task/M-bius-function/PHP/m-bius-function.php
Normal file
29
Task/M-bius-function/PHP/m-bius-function.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
// Moebius function
|
||||
|
||||
function moebius($n) {
|
||||
$m = 1;
|
||||
if ($n != 1) {
|
||||
$f = 2;
|
||||
do {
|
||||
if ($n % ($f * $f) == 0) {
|
||||
$m = 0;
|
||||
} else {
|
||||
if ($n % $f == 0) {
|
||||
$m = -$m;
|
||||
$n /= $f;
|
||||
}
|
||||
$f++;
|
||||
}
|
||||
} while ($f <= $n && $m != 0);
|
||||
}
|
||||
return $m;
|
||||
}
|
||||
|
||||
for ($t = 0; $t <= 9; $t++) {
|
||||
for ($u = 1; $u <= 10; $u++) {
|
||||
echo str_pad(moebius(10 * $t + $u), 2, " ", STR_PAD_LEFT)." ";
|
||||
}
|
||||
echo PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*REXX pgm computes & shows a value grid of the Möbius function for a range of integers.*/
|
||||
call time('r')
|
||||
parse arg LO HI grp . /*obtain optional arguments from the CL*/
|
||||
numeric digits 100
|
||||
if LO=='' | LO=="," then LO= 0 /*Not specified? Then use the default.*/
|
||||
if HI=='' | HI=="," then HI= 199 /* " " " " " " */
|
||||
if grp=='' | grp=="," then grp= 20 /* " " " " " " */
|
||||
/* uuuuuuuuuuuu */
|
||||
call genP HI /*generate primes up to the v HI */
|
||||
say center(' The Moebius sequence from ' LO " --> " HI" ", max(50, grp*3), '=') /*title*/
|
||||
dd='' /*variable holds output grid of GRP hhs.*/
|
||||
do j=LO to HI; dd= dd right( moebius(j), 2) /*process some numbers from LO --> HI.*/
|
||||
if words(dd)==grp then do; say substr(dd, 2); dd='' /*show grid if fully populated,*/
|
||||
end /* and nullify it for more hhs.*/
|
||||
end /*j*/ /*for small grids, using wordCnt is OK.*/
|
||||
|
||||
if dd\=='' then say substr(dd, 2) /*handle any residual numbers not shown*/
|
||||
say format(time('e'),,3) 'seconds'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*--------------------------------------------------------------------------------------*/
|
||||
moebius: procedure expose aa.; parse arg x /*obtain a integer to be tested for mu.*/
|
||||
if x<1 then return '*' /*special? Then return symbol for null.*/
|
||||
hh= 0 /*start with a value of zero. */
|
||||
do k=1; p= aa.k /*get the Kth (pre-generated) prime.*/
|
||||
if p>x then leave /*prime (P) > X? Then we're done. */
|
||||
if p*p>x then do; hh= hh+1; leave /*prime (P**2 > X? Bump hh and leave.*/
|
||||
end
|
||||
if x//p==0 then do; hh= hh+1 /*X divisible by P? Bump mu number. */
|
||||
x= x % p /* Divide by prime. */
|
||||
if x//p==0 then return 0 /*X÷by P? Then return zero*/
|
||||
end
|
||||
end /*k*/ /*hh (below) is almost always small, <9*/
|
||||
if hh//2==0 then return 1 /*Is hh even? Then return postive 1 */
|
||||
return -1 /* " " odd? " " negative 1. */
|
||||
/*--------------------------------------------------------------------------------------*/
|
||||
genP: aa.1=2; aa.2=3; aa.3=5; aa.4=7; aa.5=11; aa.6= 13; nP=6 /*assign low primes; hh primes.*/
|
||||
do lim=nP until lim*lim>=HI /*only keep primes up to the sqrt(HI).*/
|
||||
end /*lim*/
|
||||
do j=aa.nP+4 by 2 to HI /*only find odd primes from here on. */
|
||||
parse var j '' -1 uu;if uu==5 then iterate /*Is last digit a "5"? Then not prime*/
|
||||
if j// 3==0 then iterate /*is J divisible by 3? " " " */
|
||||
if j// 7==0 then iterate /* " " " " 7? " " " */
|
||||
if j//11==0 then iterate /* " " " " 11? " " " */
|
||||
if j//13==0 then iterate /* " " " " 13? " " " */
|
||||
do k=7 while k*k<=j /*divide by some generated odd primes. */
|
||||
if j // aa.k==0 then iterate j /*Is J divisible by P? Then not prime*/
|
||||
end /*k*/ /* [?] a prime (J) has been found. */
|
||||
nP= nP+1; if nP<=HI then aa.nP= j /*bump prime count; assign prime to aa.*/
|
||||
end /*j*/; return
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
include Settings
|
||||
|
||||
say version; say 'Moebius sequence'; say
|
||||
parse arg LO HI grp . /*obtain optional arguments from the CL*/
|
||||
numeric digits 100
|
||||
if LO=='' | LO=="," then LO= 0 /*Not specified? Then use the default.*/
|
||||
if HI=='' | HI=="," then HI= 199 /* " " " " " " */
|
||||
if grp=='' | grp=="," then grp= 20 /* " " " " " " */
|
||||
/* ______ */
|
||||
say Center(' The Moebius sequence from ' LO " --> " HI" ", Max(50, grp*3), '=') /*title*/
|
||||
dd='' /*variable holds output grid of GRP #s.*/
|
||||
do j=LO to HI; dd= dd Right( Moebius(j), 2) /*process some numbers from LO --> HI.*/
|
||||
if Words(dd)==grp then do; say Substr(dd, 2); dd='' /*show grid if fully populated,*/
|
||||
end /* and nullify it for more #s.*/
|
||||
end /*j*/ /*for small grids, using wordCnt is OK.*/
|
||||
if dd\=='' then say Substr(dd, 2) /*handle any residual numbers not shown*/
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
|
||||
Moebius:
|
||||
/* Moebius sequence */
|
||||
procedure expose fact. ufac.
|
||||
arg x
|
||||
/* Special value */
|
||||
if x = 0 then
|
||||
return '*'
|
||||
/* Using # of (unique) prime factors */
|
||||
call Factors(x)
|
||||
call Ufactors(x)
|
||||
if fact.0 = ufac.0 then
|
||||
if IsEven(fact.factor.0) then
|
||||
return 1
|
||||
else
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
|
||||
include Functions
|
||||
include Numbers
|
||||
include Sequences
|
||||
include Abend
|
||||
30
Task/M-bius-function/REXX/m-bius-function.rexx
Normal file
30
Task/M-bius-function/REXX/m-bius-function.rexx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
include Settings
|
||||
|
||||
say 'MOEBIUS FUNCTION - 4 Mar 2025'
|
||||
say version
|
||||
say
|
||||
numeric digits 100
|
||||
call sequence 1,200
|
||||
call sequence 100001,100200
|
||||
call sequence 1000000001,1000000200
|
||||
call sequence 10000000000001,10000000000200
|
||||
exit
|
||||
|
||||
Sequence:
|
||||
arg x,y
|
||||
say 'Moebius sequence from' x 'to' y
|
||||
n = 0
|
||||
do i = x to y
|
||||
n = n+1
|
||||
call charout ,right(Moebius(i),3)
|
||||
if n//20 = 0 then
|
||||
say
|
||||
end
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
say
|
||||
return
|
||||
|
||||
include Functions
|
||||
include Numbers
|
||||
include Sequences
|
||||
include Abend
|
||||
36
Task/M-bius-function/RapidQ/m-bius-function.rapidq
Normal file
36
Task/M-bius-function/RapidQ/m-bius-function.rapidq
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
REM Levenshtein distance
|
||||
DECLARE FUNCTION LevDist(S$, T$) AS INTEGER
|
||||
DECLARE FUNCTION MIN(A, B) AS INTEGER
|
||||
PRINT "The Levenshtein distance..."
|
||||
PRINT "between 'kitten' and 'sitting' is "; LevDist("kitten","sitting")
|
||||
PRINT "between 'rosettacode' and 'raisethysword' is "; LevDist("rosettacode","raisethysword")
|
||||
END
|
||||
|
||||
FUNCTION LevDist(S$, T$) AS INTEGER
|
||||
N = LEN(T$): M = LEN(S$)
|
||||
DIM D(0 TO N, 0 TO N)
|
||||
FOR I = 0 TO M
|
||||
D(I, 0) = I
|
||||
NEXT I
|
||||
FOR J = 0 TO N
|
||||
D(0, J) = J
|
||||
NEXT J
|
||||
FOR J = 1 TO N
|
||||
FOR I = 1 TO M
|
||||
IF MID$(S$, I, 1) = MID$(T$, J, 1) THEN
|
||||
D(I, J) = D(I - 1, J - 1)
|
||||
ELSE
|
||||
D(I, J) = Min(D(I - 1, J) + 1, Min(D(I, J - 1) + 1, D(I - 1, J - 1) + 1))
|
||||
END IF
|
||||
NEXT I
|
||||
NEXT J
|
||||
LevDist = D(M, N)
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Min(A, B) AS INTEGER
|
||||
IF A < B THEN
|
||||
Min = A
|
||||
ELSE
|
||||
Min = B
|
||||
END IF
|
||||
END FUNCTION
|
||||
Loading…
Add table
Add a link
Reference in a new issue