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|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|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}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
Definitions:
In '''[https://formulae.org/?example=Factorions this]''' page you can see the program(s) related to this task and their results.
 
[[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="ecmascriptwren">// cache factorials from 0 to 11
var fact = List.filled(12, 0)
fact[0] = 1
Line 1,961 ⟶ 2,003:
</pre>
 
=={{header|VBScriptXPL0}}==
{{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>
theThe factorions for base 9 are: 1 2 41282
1 2 41282
the factorions for base 10 are: 1 2 145 40585
 
the factorions for base 11 are: 1 2 26 48 40472
theThe factorions for base 1210 are: 1 2
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}}==
9,488

edits