Factorions: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|jq}}: simplify)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 7 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 860 ⟶ 871:
Factorians for base 11: [1, 2, 26, 48, 40472]
Factorians for base 12: [1, 2]
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
 
{def facts
{S.first
{S.map {{lambda {:a :i}
{A.addlast! {* {A.get {- :i 1} :a} :i} :a}
} {A.new 1}}
{S.serie 1 11}}}}
-> facts
 
{def sumfacts
{def sumfacts.r
{lambda {:base :sum :i}
{if {> :i 0}
then {sumfacts.r :base
{+ :sum {A.get {% :i :base} {facts}}}
{floor {/ :i :base}}}
else :sum }}}
{lambda {:base :n}
{sumfacts.r :base 0 :n}}}
-> sumfacts
 
{def show
{lambda {:base}
{S.replace \s by space in
{S.map {{lambda {:base :i}
{if {= {sumfacts :base :i} :i} then :i else}
} :base}
{S.serie 1 50000}}}}}
-> show
 
{S.map {lambda {:base}
{div}factorions for base :base: {show :base}}
9 10 11 12}
->
factorions for base 9: 1 2 41282
factorions for base 10: 1 2 145 40585
factorions for base 11: 1 2 26 48 40472
factorions for base 12: 1 2
 
</syntaxhighlight>
 
=={{header|Lang}}==
{{trans|Python}}
<syntaxhighlight lang="lang">
# Enabling raw variable names boosts the performance massivly [DO NOT RUN WITHOUT enabling raw variable names]
lang.rawVariableNames = 1
 
# Cache factorials from 0 to 11
&fact = fn.listOf(1)
$n = 1
while($n < 12) {
&fact += &fact[-|$n] * $n
$n += 1
}
 
$b = 9
while($b <= 12) {
fn.printf(The factorions for base %d are:%n, $b)
$i = 1
while($i < 1500000) {
$sum = 0
$j = $i
while($j > 0) {
$d $= $j % $b
$sum += &fact[$d]
$j //= $b
}
if($sum == $i) {
fn.print($i\s)
}
$i += 1
}
fn.println(\n)
$b += 1
}
</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>
 
Line 1,559 ⟶ 1,671:
 
The factorions for base 12 are: 1 2
</pre>
 
=={{header|RPL}}==
{{trans|C}}
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! Code
! Comments
|-
|
{ } 1 11 '''FOR''' n n FACT + '''NEXT''' → base fact
≪ { } 1 1500000 '''FOR''' n
0 n '''WHILE''' DUP '''REPEAT'''
fact OVER base MOD 1 MAX GET
ROT + SWAP
base / IP
'''END''' DROP
'''IF''' n == '''THEN''' n + '''END'''
'''NEXT'''
≫ ≫ ‘FTRION’ STO
|
''( base -- { factorions } )''
Cache 1! to 11!
Loop until all digits scanned
Get (last digit)! even if last digit = 0
Add to sum of digits
prepare next loop
Store factorion
|}
The following lines of command deliver what is required:
9 FTRION
10 FTRION
11 FTRION
12 FTRION
{{out}}
<pre>
4: { 1 2 41282 }
3: { 1 2 145 40585 }
2: { 1 2 26 48 40472 }
1: { 1 2 }
</pre>
 
Line 1,649 ⟶ 1,806:
 
=={{header|Swift}}==
 
{{trans|C}}
 
<syntaxhighlight lang="swift">var fact = Array(repeating: 0, count: 12)
 
Line 1,694 ⟶ 1,849:
The factorions for base 12 are:
1 2</pre>
 
=={{header|uBasic/4tH}}==
{{trans|FreeBASIC}}
It will take some time, but it will get there.
<syntaxhighlight lang="uBasic/4tH">Dim @f(12)
 
@f(0) = 1: For n = 1 To 11 : @f(n) = @f(n-1) * n : Next
 
For b = 9 To 12
Print "The factorions for base ";b;" are: "
For i = 1 To 1499999
s = 0
j = i
Do While j > 0
d = j % b
s = s + @f(d)
j = j / b
Loop
If s = i Then Print i;" ";
Next
Print : Print
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
 
 
0 OK, 0:379</pre>
 
=={{header|V (Vlang)}}==
Line 1,740 ⟶ 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,779 ⟶ 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,486

edits