Factorions: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(Add lang example) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 169:
The factorions for base 12 are:
1 2</pre>
=={{header|Arturo}}==
Line 284 ⟶ 262:
base 12 factorions: 1 2
</pre>
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="basic">100 DIM FACT(12)
110 FACT(0) = 1
120 FOR N = 1 TO 11
130 FACT(N) = FACT(N - 1) * N
140 NEXT
200 FOR B = 9 TO 12
210 PRINT "THE FACTORIONS ";
215 PRINT "FOR BASE "B" ARE:"
220 FOR I = 1 TO 1499999
230 SUM = 0
240 FOR J = I TO 0 STEP 0
245 M = INT (J / B)
250 D = J - M * B
260 SUM = SUM + FACT(D)
270 J = M
280 NEXT J
290 IF SU = I THEN PRINT I" ";
300 NEXT I
310 PRINT : PRINT
320 NEXT B</syntaxhighlight>
=={{header|C}}==
Line 516 ⟶ 517:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Factorions}}
'''Solution'''
Definitions:
[[File:Fōrmulæ - Factorions 01.png]]
[[File:Fōrmulæ - Factorions 02.png]]
The following calculates factorion lists from bases 9 to 12, with a limit of 1,499,999
[[File:Fōrmulæ - Factorions 03.png]]
[[File:Fōrmulæ - Factorions 04.png]]
=={{header|FreeBASIC}}==
Line 1,795 ⟶ 1,806:
=={{header|Swift}}==
{{trans|C}}
<syntaxhighlight lang="swift">var fact = Array(repeating: 0, count: 12)
Line 1,877 ⟶ 1,886:
0 OK, 0:379</pre>
=={{header|V (Vlang)}}==
{{trans|Go}}
Line 1,922 ⟶ 1,932:
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 9 are: 1 2 41282
the factorions for base 10 are: 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|Wren}}==
{{trans|C}}
<syntaxhighlight lang="
var fact = List.filled(12, 0)
fact[0] = 1
Line 1,961 ⟶ 2,003:
</pre>
=={{header|
{{trans|C}}
<syntaxhighlight lang "XPL0">int N, Base, Digit, I, J, Sum, Factorial(12);
[Factorial(0):= 1; \cache factorials from 0 to 11
for N:= 1 to 12-1 do
Factorial(N):= Factorial(N-1)*N;
for Base:= 9 to 12 do
[Text(0, "The factorions for base "); IntOut(0, Base); Text(0, " are:^m^j");
for I:= 1 to 1_499_999 do
[Sum:= 0;
J:= I;
while J > 0 do
[Digit:= rem(J/Base);
Sum:= Sum + Factorial(Digit);
J:= J/Base;
];
if Sum = I then [IntOut(0, I); ChOut(0, ^ )];
];
CrLf(0); CrLf(0);
];
]</syntaxhighlight>
{{out}}
<pre>
1 2 41282
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}}==
|