Möbius function: Difference between revisions

Added various BASIC dialects (Gambas, MSX Basic, PureBasic and XBasic)
(Added Quackery.)
(Added various BASIC dialects (Gambas, MSX Basic, PureBasic and XBasic))
 
(33 intermediate revisions by 13 users not shown)
Line 29:
:*; [[Mertens function]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
F isPrime(n)
I n < 2
R 0B
L(i) 2 .. n
I i * i <= n & n % i == 0
R 0B
R 1B
 
F mobius(n)
I n == 1
R 1
 
V p = 0
L(i) 1 .. n
I n % i == 0 & isPrime(i)
I n % (i * i) == 0
R 0
E
p = p + 1
 
I p % 2 != 0
R -1
E
R 1
 
print(‘Mobius numbers from 1..99:’)
 
L(i) 1..99
print(f:‘{mobius(i):4}’, end' ‘’)
 
I i % 20 == 0
print()
</syntaxhighlight>
 
{{out}}
<pre>
Mobius numbers from 1..99:
1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1 0
1 1 -1 0 0 1 0 0 -1 -1 -1 0 1 1 1 0 -1 1 1 0
-1 -1 -1 0 0 1 -1 0 0 0 1 0 -1 0 1 0 1 1 -1 0
-1 1 0 0 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1 -1 -1 0
0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0
</pre>
 
=={{header|ALGOL 68}}==
Line 72 ⟶ 120:
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1
</pre>
 
=={{header|Amazing Hopper}}==
{{Trans|Python}}
<syntaxhighlight lang="c">
#include <basico.h>
 
#proto cálculodeMobius(_X_)
#synon _cálculodeMobius calcularMobius
 
algoritmo
imprimir ("Mobius numbers from 1..199\n")
i=0, s=1
iterar grupo( ++i, #(i<=199), calcular Mobius (i), \
solo si (#( iszero(s%20) ), NL;s=0 ), imprimir, ++s )
saltar
terminar
 
subrutinas
 
cálculo de Mobius (n)
si( #(n==0) ) ; tomar '" "'
sino si( #(n==1) ); tomar '" 1"'
sino; p=0
iterar para (i=1, #(i<=n+1), ++i)
si ( #( iszero(n%i) && isprime(i)) )
cuando ( #( iszero(n%(i*i)) ) ){
tomar '" 0"'; ir a (herejía) /* ¡! */
} ++p
fin si
siguiente
tomar si ( es impar(p), " -1", " 1" )
fin si
 
/* ¡Dios! ¡Purifica esta mierda! ----+ */
/* | */
herejía: /* <----------------------+ */
retornar
</syntaxhighlight>
{{out}}
<pre>
Mobius numbers from 1..199
1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1
0 1 1 -1 0 0 1 0 0 -1 -1 -1 0 1 1 1 0 -1 1 1
0 -1 -1 -1 0 0 1 -1 0 0 0 1 0 -1 0 1 0 1 1 -1
0 -1 1 0 0 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1 -1 -1
0 0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0
0 -1 -1 -1 0 -1 1 -1 0 -1 -1 1 0 -1 -1 1 0 0 1 1
0 0 1 1 0 0 0 -1 0 1 -1 -1 0 1 1 0 0 -1 -1 -1
0 1 1 1 0 1 1 0 0 -1 0 -1 0 0 -1 1 0 -1 1 1
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1
</pre>
 
Line 226 ⟶ 327:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="qbasic">10 HOME
20 FOR t = 0 TO 9
30 FOR u = 1 TO 10
40 n = 10*t+u
50 GOSUB 130
60 IF STR$(m) = "0" THEN PRINT " 0";
70 IF STR$(m) = "1" THEN PRINT " 1";
80 IF STR$(m) = "-1" THEN PRINT " -1";
90 NEXT u
100 PRINT
110 NEXT t
120 END
130 IF n = 1 THEN m = 1 : RETURN
140 m = 1 : f = 2
150 IF (n-INT(n/(f*f))*(f*f)) = 0 THEN m = 0 : RETURN
160 IF (n-INT(n/(f))*(f)) = 0 THEN GOSUB 200
170 f = f+1
180 IF f <= n THEN GOTO 150
190 RETURN
200 m = -m
210 n = n/f
220 RETURN
230 END</syntaxhighlight>
{{out}}
<pre>Same as GW-BASIC entry.</pre>
 
==={{header|BASIC256}}===
Line 251 ⟶ 378:
end</syntaxhighlight>
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
<pre>
 
Igual que la entrada de FreeBASIC.
==={{header|Chipmunk Basic}}===
</pre>
{{works with|Chipmunk Basic|3.6.4}}
{{works with|GW-BASIC}}
{{works with|QBasic}}
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 CLS
20 FOR t = 0 TO 9
30 FOR u = 1 TO 10
40 n = 10 * t + u
50 GOSUB 110
60 PRINT USING "## "; m;
70 NEXT u
80 PRINT
90 NEXT t
100 END
110 IF n = 1 THEN m = 1: RETURN
120 m = 1: f = 2
130 IF n MOD (f * f) = 0 THEN m = 0: RETURN
140 IF n MOD f = 0 THEN GOSUB 180
150 f = f + 1
160 IF f <= n THEN GOTO 130
170 RETURN
180 m = -m
190 n = n / f
200 RETURN
210 END</syntaxhighlight>
{{out}}
<pre>Same as GW-BASIC entry.</pre>
 
==={{header|FreeBASIC}}===
Line 352 ⟶ 506:
0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0 0
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
{{works with|Windows}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim outstr As String = " . "
 
For i As Integer = 1 To 200
If mobius(i) >= 0 Then outstr &= " "
outstr &= Str(mobius(i)) & " "
If i Mod 10 = 9 Then
Print outstr
outstr = ""
End If
Next
End
 
Function mobius(n As Integer) As Integer
 
If n = 1 Then Return 1
For d As Integer = 2 To Int(Sqr(n))
If n Mod d = 0 Then
If n Mod (d * d) = 0 Then Return 0
Return -mobius(n / d)
End If
Next
Return -1
 
End Function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
Line 390 ⟶ 577:
==={{header|Minimal BASIC}}===
{{trans|GW-BASIC}}
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic|3.6.4}}
{{works with|Commodore BASIC|3.5}}
{{works with|Nascom ROM BASIC|4.7}}
Line 417 ⟶ 606:
230 RETURN
</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">Procedure.i mobius(n)
If n = 1:
ProcedureReturn 1
EndIf
For d = 2 To Int(Sqr(n))
If Mod(n, d) = 0:
If Mod(n, d * d) = 0:
ProcedureReturn 0
EndIf
ProcedureReturn -mobius(n / d)
EndIf
Next d
ProcedureReturn -1
EndProcedure
 
OpenConsole()
outstr$ = " . "
For i = 1 To 200
If mobius(i) >= 0:
outstr$ = outstr$ + " "
EndIf
outstr$ = outstr$ + Str(mobius(i)) + " "
If Mod(i, 10) = 9:
PrintN(outstr$)
outstr$ = ""
EndIf
Next i
 
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Tiny BASIC}}===
Line 440 ⟶ 668:
101 PRINT "1"
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">PROGRAM "Möbius function"
VERSION "0.0000"
IMPORT "xma"
 
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION mobius (n)
 
FUNCTION Entry ()
outstr$ = " . "
FOR i = 1 TO 200
IF mobius(i) >= 0 THEN outstr$ = outstr$
outstr$ = outstr$ + STR$(mobius(i)) + " "
IF i MOD 10 = 9 THEN
PRINT outstr$
outstr$ = ""
END IF
NEXT i
END FUNCTION
 
FUNCTION mobius (n)
IF n = 1 THEN RETURN 1
FOR d = 2 TO INT(SQRT(n))
IF n MOD d = 0 THEN
IF n MOD (d*d) = 0 THEN RETURN 0
RETURN -mobius(n/d)
END IF
NEXT d
RETURN -1
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
Line 675 ⟶ 940:
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Rather than being clever and trying to perform the task in the smallest number of lines possible, this solution breaks the problem down into its fundamental pieces and solves each one in a separate subroutine. This programming style makes the code easier understand, debug and enhance the code. While the technique is not necessary on simple problems like this, it is essential for larger and more complex programs.
 
<syntaxhighlight lang="Delphi">
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
 
function GetNextPrime(var Start: integer): integer;
{Get the next prime number after Start}
{Start is passed by "reference," so the
{original variable is incremented}
begin
repeat Inc(Start)
until IsPrime(Start);
Result:=Start;
end;
 
 
type TIntArray = array of integer;
 
 
procedure StoreNumber(N: integer; var IA: TIntArray);
{Expand and store number in array}
begin
SetLength(IA,Length(IA)+1);
IA[High(IA)]:=N;
end;
 
 
procedure GetPrimeFactors(N: integer; var Facts: TIntArray);
{Get all the prime factors of a number}
var I: integer;
begin
I:=2;
repeat
begin
if (N mod I) = 0 then
begin
StoreNumber(I,Facts);
N:=N div I;
end
else GetNextPrime(I);
end
until N=1;
end;
 
 
 
function HasDuplicates(IA: TIntArray): boolean;
{Look for duplicates factors in array}
var I: integer;
begin
Result:=True;
for I:=0 to Length(IA)-1 do
if IA[I]=IA[I+1] then exit;
Result:=False;
end;
 
 
function Moebius(N: integer): integer;
{Get moebius function of number}
var I: integer;
var Factors: TIntArray;
var Even,Square: boolean;
begin
{Collect all prime factors}
SetLength(Factors,0);
GetPrimeFactors(N,Factors);
{Are there an even number of factors?}
Even:=(Length(Factors) and 1)=0;
{If there are duplicates, there are perfect squares}
Square:=HasDuplicates(Factors);
{Return the Moebius function value}
if Square then Result:=0
else if Even then Result:=1
else Result:=-1;
end;
 
procedure TestMoebiusFactors(Memo: TMemo);
{Test Moebius function for 1..200-1}
var N,M: integer;
var S: string;
begin
S:='';
for N:=1 to 199 do
begin
M:=Moebius(N);
S:=S+Format('%3d',[M]);
if (N mod 20)=19 then S:=S+#$0D#$0A
end;
Memo.Text:=S;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1
0 1 1 -1 0 0 1 0 0 -1 -1 -1 0 1 1 1 0 -1 1 1
0 -1 -1 -1 0 0 1 -1 0 0 0 1 0 -1 0 1 0 1 1 -1
0 -1 1 0 0 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1 -1 -1
0 0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0
0 -1 -1 -1 0 -1 1 -1 0 -1 -1 1 0 -1 -1 1 0 0 1 1
0 0 1 1 0 0 0 -1 0 1 -1 -1 0 1 1 0 0 -1 -1 -1
0 1 1 1 0 1 1 0 0 -1 0 -1 0 0 -1 1 0 -1 1 1
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1
</pre>
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight lang=easylang>
mu_max = 100000
sqroot = floor sqrt mu_max
#
for i to mu_max
mu[] &= 1
.
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 i = 2 to mu_max
if mu[i] = i
mu[i] = 1
elif mu[i] = -i
mu[i] = -1
elif mu[i] < 0
mu[i] = 1
elif mu[i] > 0
mu[i] = -1
.
.
numfmt 0 3
for i = 1 to 100
write mu[i]
if i mod 10 = 0
print ""
.
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 917 ⟶ 1,351:
 
=={{header|J}}==
Implementation:
<syntaxhighlight lang="j">mu=: */@:-@~:@q:</syntaxhighlight>
 
Explanation: <code>q: n</code> gives the list of prime factors of n. (This is an empty list for the number 1, is <code>2 2 5 5</code> for the number 100, and is <code>2 2 2 3 5</code> for the number 120.)
Implementation:
 
In this context <code>~:</code> replaces each prime factor either by 1, if it is its first occurrence, or by 0, if it is a repetition (e.g. <code>2 2 5 5</code> → <code>1 0 1 0</code>). Then, <code>-</code> simply negates this list (e.g. <code>1 0 1 0</code> → <code>_1 0 _1 0</code>), and finally <code>*/</code> multiplies all list elements to get the desired result.
<syntaxhighlight lang="j">mu=: ({{*/1-y>1}} * _1 ^ 2|+/)@q:~&_</syntaxhighlight>
 
Explanation: _ q: n gives the list of exponents of prime factors of n. (This is an empty list for the number 1, is 2 0 2 for the number 100 and is 3 1 1 for the number 120.)
 
In this context +/ is the sum of that list, 2 | +/ is 1 if the sum is odd and 0 if the sum is even. _1^0 is 1 and _1^1 is _1. And, {{*/1-y>1}} returns zero if any exponent is at least 2 in magnitude.
 
Task example:
<syntaxhighlight lang="j"> mu >: i. 10 20
 
<syntaxhighlight lang="j"> mu 1+i.10 20
1 _1 _1 0 _1 1 _1 0 0 1 _1 0 _1 1 1 0 _1 0 _1 0
1 1 _1 0 0 1 0 0 _1 _1 _1 0 1 1 1 0 _1 1 1 0
Line 1,419 ⟶ 1,850:
1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1 0
-1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1 0</pre>
 
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
{
for(i = 1, 99,
print1(moebius(i) " ");
if(i % 10 == 0, print("\n"););
);
}
</syntaxhighlight>
{{out}}
<pre>
1 -1 -1 0 -1 1 -1 0 0 1
 
-1 0 -1 1 1 0 -1 0 -1 0
 
1 1 -1 0 0 1 0 0 -1 -1
 
-1 0 1 1 1 0 -1 1 1 0
 
-1 -1 -1 0 0 1 -1 0 0 0
 
1 0 -1 0 1 0 1 1 -1 0
 
-1 1 0 0 1 -1 -1 0 1 -1
 
-1 0 -1 1 0 0 1 -1 -1 0
 
0 1 -1 0 1 1 1 0 -1 0
 
1 0 1 1 1 0 -1 0 0
</pre>
 
 
=={{header|Pascal}}==
Line 1,580 ⟶ 2,046:
 
The idea is based on efficient program to print all prime factors of a given number. The interesting thing is, we do not need inner while loop here because if a number divides more than once, we can immediately return 0.
 
# BUGS ! mu(1): computes -1, correct 1
# BUGS ! mu(2): computes 1, correct -1
# BUGS ! mu(105): computes 1, correct -1
# BUGS ! ...
# Some other programs say: "Translation of Python", probably of this one.
<syntaxhighlight lang="python"># Python Program to evaluate
Line 1,673 ⟶ 2,145:
[ drop 0 ] done
size odd iff
-1 else 1 ] is mobius ( n --> n )
 
say "First 199 terms:" cr
Line 1,701 ⟶ 2,173:
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|20192022.1112}}
 
Möbius number is not defined for n == 0. Raku arrays are indexed from 0 so store a blank value at position zero to keep n and μ(n) aligned.
Line 1,708 ⟶ 2,180:
 
sub μ (Int \n) {
return 0 if n %% (4 or n %% |9 or n %% |25 or n %% |49 or n %% |121);
my @p = prime-factors(n);
+@p == +@p.unique ?? +@p %% 2 ?? 1 !! -1 !! 0
}
 
my @möbius = lazy flat '', 1, (2..*).hyper.map: -> \n { &μ(n) };
 
# The Task
Line 1,862 ⟶ 2,334:
-1 -1 0 -1 1 -1 0 -1 0 -1
</pre>
 
=={{header|RPL}}==
{{trans|FreeBASIC}}
RPL does not allow that a function returns something whilst in the middle of a branch, so we have to play here with index saturation and flag use to mimic the short returns that many other languages accept.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
'''IF''' DUP 1 ≠ '''THEN''' → n
≪ -1
2 n √ '''FOR''' d
'''IF''' n d MOD NOT '''THEN'''
1 CF '''IF''' n d SQ MOD NOT '''THEN'''
n 'd' STO DROP 0 1 SF '''END'''
'''IF''' 1 FC? '''THEN'''
DROP n d / n 'd' STO '''MU''' NEG '''END'''
'''END'''
'''NEXT'''
≫ '''END'''
≫ '<span style="color:blue">MU</span>' STO
|
<span style="color:blue">MU</span> ''( n -- µ(n) )''
if n = 1 then return 1
// default return value put in stack
for d as uinteger = 2 to int(sqr(n))
if n mod d = 0 then
if n mod (d*d) = 0 then
return 0 // and set flag
// if flag not set,
return -mobius(n/d)
end if
next d
|}
 
≪ 1 100 '''FOR''' li "" li DUP 19 + '''FOR''' j "-0+" j <span style="color:blue">MU</span> 2 + DUP SUB + '''NEXT''' 20 '''STEP''' ≫ EVAL
 
{{out}}
<pre>
5: "+--0-+-00+-0-++0-0-0"
4: "++-00+00---0+++0-++0"
3: "---00+-000+0-0+0++-0"
2: "-+00+--0+--0-+00+--0"
1: "0+-0+++0-0+0+++0-000"
</pre>
{{works with|HP|49/50}}
Improvement of an implementation found on the [https://www.hpmuseum.org/forum/thread-10330-post-93200.html#pid93200 MoHPC forum]
« '''CASE'''
DUP 1 ≤ '''THEN END'''
FACTOR DUP TYPE 9 ≠ '''THEN''' DROP -1 '''END'''
DUP →STR "^" POS '''THEN''' DROP 0 '''END'''
SIZE 1 + 2 / 1 SWAP 2 MOD { NEG } IFT
'''END'''
» '<span style="color:blue">MU</span>' STO
« 1 100 '''FOR''' j
j 20 MOD 1 == "" IFT
"-0+" j <span style="color:blue">MU</span> 2 + DUP SUB +
'''NEXT'''
» '<span style="color:blue">TASK</span>' STO
Same output.
 
=={{header|Ruby}}==
Line 1,887 ⟶ 2,424:
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
fn moebius(mut x: u64) -> i8 {
let mut prime_count = 0;
 
// If x is divisible by the given factor this macro counts the factor and divides it out.
// It then returns zero if x is still divisible by the factor.
macro_rules! divide_x_by {
($factor:expr) => {
if x % $factor == 0 {
x /= $factor;
prime_count += 1;
if x % $factor == 0 {
return 0;
}
}
};
}
 
// Handle 2 and 3 separately,
divide_x_by!(2);
divide_x_by!(3);
 
// then use a wheel sieve to check the remaining factors <= √x.
for i in (5..=isqrt(x)).step_by(6) {
divide_x_by!(i);
divide_x_by!(i + 2);
}
 
// There can exist one prime factor larger than √x,
// in that case we can check if x is still larger than one, and then count it.
if x > 1 {
prime_count += 1;
}
 
if prime_count % 2 == 0 {
1
} else {
-1
}
}
 
/// Returns the largest integer smaller than or equal to `√n`
const fn isqrt(n: u64) -> u64 {
if n <= 1 {
n
} else {
let mut x0 = u64::pow(2, n.ilog2() / 2 + 1);
let mut x1 = (x0 + n / x0) / 2;
while x1 < x0 {
x0 = x1;
x1 = (x0 + n / x0) / 2;
}
x0
}
}
 
fn main() {
const ROWS: u64 = 10;
const COLS: u64 = 20;
println!(
"Values of the Möbius function, μ(x), for x between 0 and {}:",
COLS * ROWS
);
for i in 0..ROWS {
for j in 0..=COLS {
let x = COLS * i + j;
let μ = moebius(x);
if μ >= 0 {
// Print an extra space if there's no minus sign in front of the output
// in order to align the numbers in a nice grid.
print!(" ");
}
print!("{μ} ");
}
println!();
}
let x = u64::MAX;
println!("\nμ({x}) = {}", moebius(x));
}
</syntaxhighlight>
{{out}}
<pre>
Values of the Möbius function, μ(x), for x between 0 and 200:
0 1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 -1 0 -1 0
0 1 1 -1 0 0 1 0 0 -1 -1 -1 0 1 1 1 0 -1 1 1 0
0 -1 -1 -1 0 0 1 -1 0 0 0 1 0 -1 0 1 0 1 1 -1 0
0 -1 1 0 0 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1 -1 -1 0
0 0 1 -1 0 1 1 1 0 -1 0 1 0 1 1 1 0 -1 0 0 0
0 -1 -1 -1 0 -1 1 -1 0 -1 -1 1 0 -1 -1 1 0 0 1 1 0
0 0 1 1 0 0 0 -1 0 1 -1 -1 0 1 1 0 0 -1 -1 -1 0
0 1 1 1 0 1 1 0 0 -1 0 -1 0 0 -1 1 0 -1 1 1 0
0 1 0 -1 0 -1 1 -1 0 0 -1 0 0 -1 -1 0 0 1 1 -1 0
0 -1 -1 1 0 1 -1 1 0 0 -1 -1 0 -1 1 -1 0 -1 0 -1 0
 
μ(18446744073709551615) = -1
</pre>
 
Line 1,926 ⟶ 2,561:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./math" for Int
 
var isSquareFree = Fn.new { |n|
Line 1,954 ⟶ 2,589:
System.write(" ")
} else {
SystemFmt.write("%(Fmt.dm(3$ 3d ", mu.call(i*20 + j))) ")
}
}
2,130

edits