Factorions: Difference between revisions
Added XPL0 example.
m (Applesoft BASIC moved to the BASIC section.) |
(Added XPL0 example.) |
||
Line 1,796:
=={{header|Swift}}==
{{trans|C}}
<syntaxhighlight lang="swift">var fact = Array(repeating: 0, count: 12)
Line 1,878 ⟶ 1,876:
0 OK, 0:379</pre>
=={{header|V (Vlang)}}==
{{trans|Go}}
Line 1,923 ⟶ 1,922:
The factorions for base 12 are:
1 2
</pre>
=={{header|VBScript}}==
<syntaxhighlight lang="vb">' Factorions - VBScript - PG - 26/04/2020▼
Dim fact()▼
nn1=9 : nn2=12▼
lim=1499999▼
ReDim fact(nn2)▼
fact(0)=1▼
For i=1 To nn2▼
fact(i)=fact(i-1)*i▼
Next▼
For base=nn1 To nn2▼
list=""▼
For i=1 To lim▼
s=0▼
t=i▼
Do While t<>0▼
d=t Mod base▼
s=s+fact(d)▼
t=t\base▼
Loop▼
If s=i Then list=list &" "& i▼
Next▼
Wscript.Echo "the factorions for base "& right(" "& base,2) &" are: "& list▼
Next </syntaxhighlight>▼
{{out}}
<pre>
the factorions for base 11 are: 1 2 26 48 40472
the factorions for base 12 are: 1 2
</pre>
Line 1,962 ⟶ 1,993:
</pre>
=={{header|
{{trans|C}}
▲<syntaxhighlight lang="vb">' Factorions - VBScript - PG - 26/04/2020
<syntaxhighlight lang "XPL0">int N, Base, Digit, I, J, Sum, Factorial(12);
▲ Dim fact()
[Factorial(0):= 1; \cache factorials from 0 to 11
▲ nn1=9 : nn2=12
for N:= 1 to 12-1 do
▲ lim=1499999
Factorial(N):= Factorial(N-1)*N;
▲ ReDim fact(nn2)
for Base:= 9 to 12 do
▲ fact(0)=1
[Text(0, "The factorions for base "); IntOut(0, Base); Text(0, " are:^m^j");
▲ For i=1 To nn2
for I:= 1 to 1_499_999 do
▲ fact(i)=fact(i-1)*i
[Sum:= 0;
▲ Next
J:= I;
▲ For base=nn1 To nn2
while J > 0 do
▲ list=""
[Digit:= rem(J/Base);
▲ For i=1 To lim
Sum:= Sum + Factorial(Digit);
▲ s=0
J:= J/Base;
▲ t=i
];
▲ Do While t<>0
if Sum = I then [IntOut(0, I); ChOut(0, ^ )];
▲ d=t Mod base
];
▲ s=s+fact(d)
CrLf(0); CrLf(0);
▲ t=t\base
];
▲ Loop
]</syntaxhighlight>
▲ If s=i Then list=list &" "& i
▲ Next
▲ Wscript.Echo "the factorions for base "& right(" "& base,2) &" are: "& list
▲ Next </syntaxhighlight>
{{out}}
<pre>
1 2 41282
▲the factorions for base 10 are: 1 2 145 40585
▲the factorions for base 11 are: 1 2 26 48 40472
1 2 145 40585
The factorions for base 11 are:
1 2 26 48 40472
The factorions for base 12 are:
1 2
</pre>
=={{header|zkl}}==
|