Factorions: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 33: Line 33:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V fact = [1]
<syntaxhighlight lang="11l">V fact = [1]
L(n) 1..11
L(n) 1..11
fact.append(fact[n-1] * n)
fact.append(fact[n-1] * n)
Line 48: Line 48:
I fact_sum == i
I fact_sum == i
print(i, end' ‘ ’)
print(i, end' ‘ ’)
print("\n")</lang>
print("\n")</syntaxhighlight>


{{out}}
{{out}}
Line 67: Line 67:


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
<lang 360asm>* Factorions 26/04/2020
<syntaxhighlight lang="360asm">* Factorions 26/04/2020
FACTORIO CSECT
FACTORIO CSECT
USING FACTORIO,R13 base register
USING FACTORIO,R13 base register
Line 127: Line 127:
XDEC DS CL12 temp fo xdeco
XDEC DS CL12 temp fo xdeco
REGEQU
REGEQU
END FACTORIO </lang>
END FACTORIO </syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 138: Line 138:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{trans|C}}
{{trans|C}}
<lang algol68>BEGIN
<syntaxhighlight lang="algol68">BEGIN
# cache factorials from 0 to 11 #
# cache factorials from 0 to 11 #
[ 0 : 11 ]INT fact;
[ 0 : 11 ]INT fact;
Line 158: Line 158:
print( ( newline ) )
print( ( newline ) )
OD
OD
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 171: Line 171:


=={{header|Applesoft BASIC}}==
=={{header|Applesoft BASIC}}==
<lang basic>100 DIM FACT(12)
<syntaxhighlight lang="basic">100 DIM FACT(12)
110 FACT(0) = 1
110 FACT(0) = 1
120 FOR N = 1 TO 11
120 FOR N = 1 TO 11
Line 190: Line 190:
300 NEXT I
300 NEXT I
310 PRINT : PRINT
310 PRINT : PRINT
320 NEXT B</lang>
320 NEXT B</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>factorials: [1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800]
<syntaxhighlight lang="rebol">factorials: [1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800]


factorion?: function [n, base][
factorion?: function [n, base][
Line 208: Line 208:
loop 9..12 'base ->
loop 9..12 'base ->
print ["Base" base "factorions:" select 1..45000 'z -> factorion? z base]
print ["Base" base "factorions:" select 1..45000 'z -> factorion? z base]
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 219: Line 219:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{trans|C}}
{{trans|C}}
<lang AutoHotkey>fact:=[]
<syntaxhighlight lang="autohotkey">fact:=[]
fact[0] := 1
fact[0] := 1
while (A_Index < 12)
while (A_Index < 12)
Line 241: Line 241:
}
}
MsgBox % res
MsgBox % res
return</lang>
return</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 250: Line 250:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FACTORIONS.AWK
# syntax: GAWK -f FACTORIONS.AWK
# converted from C
# converted from C
Line 276: Line 276:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 287: Line 287:
=={{header|C}}==
=={{header|C}}==
{{trans|Go}}
{{trans|Go}}
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int main() {
int main() {
Line 313: Line 313:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 332: Line 332:
=={{header|C++}}==
=={{header|C++}}==
{{trans|C}}
{{trans|C}}
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


class factorion_t {
class factorion_t {
Line 363: Line 363:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>factorions for base 9: 1 2 41282
<pre>factorions for base 9: 1 2 41282
Line 371: Line 371:
</pre>
</pre>
=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>(defparameter *bases* '(9 10 11 12))
<syntaxhighlight lang="lisp">(defparameter *bases* '(9 10 11 12))
(defparameter *limit* 1500000)
(defparameter *limit* 1500000)


Line 401: Line 401:
(if (/= base 10) (format t " (decimal ~a)" n))
(if (/= base 10) (format t " (decimal ~a)" n))
(format t "~%"))
(format t "~%"))
(format t "~%")))</lang>
(format t "~%")))</syntaxhighlight>


{{Out}}
{{Out}}
Line 431: Line 431:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{Trans|C}}
{{Trans|C}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Factorions;
program Factorions;


Line 466: Line 466:
end;
end;
readln;
readln;
end.</lang>
end.</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Factorians. Nigel Galloway: October 22nd., 2021
// Factorians. Nigel Galloway: October 22nd., 2021
let N=[|let mutable n=1 in yield n; for g in 1..11 do n<-n*g; yield n|]
let N=[|let mutable n=1 in yield n; for g in 1..11 do n<-n*g; yield n|]
let fG n g=let rec fN g=function i when i<n->g+N.[i] |i->fN(g+N.[i%n])(i/n) in fN 0 g
let fG n g=let rec fN g=function i when i<n->g+N.[i] |i->fN(g+N.[i%n])(i/n) in fN 0 g
{9..12}|>Seq.iter(fun n->printf $"In base %d{n} Factorians are:"; {1..1500000}|>Seq.iter(fun g->if g=fG n g then printf $" %d{g}"); printfn "")
{9..12}|>Seq.iter(fun n->printf $"In base %d{n} Factorians are:"; {1..1500000}|>Seq.iter(fun g->if g=fG n g then printf $" %d{g}"); printfn "")
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>In base 9 Factorians are: 1 2 41282
<pre>In base 9 Factorians are: 1 2 41282
Line 483: Line 483:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: formatting io kernel math math.parser math.ranges memoize
<syntaxhighlight lang="factor">USING: formatting io kernel math math.parser math.ranges memoize
prettyprint sequences ;
prettyprint sequences ;
IN: rosetta-code.factorions
IN: rosetta-code.factorions
Line 498: Line 498:
curry each nl ;
curry each nl ;


1,500,000 9 12 [a,b] [ show-factorions nl ] with each</lang>
1,500,000 9 12 [a,b] [ show-factorions nl ] with each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 523: Line 523:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Dim As Integer fact(12), suma, d, j
<syntaxhighlight lang="freebasic">Dim As Integer fact(12), suma, d, j
fact(0) = 1
fact(0) = 1
For n As Integer = 1 To 11
For n As Integer = 1 To 11
Line 542: Line 542:
Print : Print
Print : Print
Next b
Next b
Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 559: Line 559:


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>factorion[n, base] := sum[map["factorial", integerDigits[n, base]]]
<syntaxhighlight lang="frink">factorion[n, base] := sum[map["factorial", integerDigits[n, base]]]


for base = 9 to 12
for base = 9 to 12
Line 566: Line 566:
if n == factorion[n, base]
if n == factorion[n, base]
println["$base\t$n"]
println["$base\t$n"]
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 586: Line 586:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 619: Line 619:
fmt.Println("\n")
fmt.Println("\n")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 636: Line 636:
</pre>
</pre>
=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Text.Printf (printf)
<syntaxhighlight lang="haskell">import Text.Printf (printf)
import Data.List (unfoldr)
import Data.List (unfoldr)
import Control.Monad (guard)
import Control.Monad (guard)
Line 650: Line 650:
where
where
factorions b = filter (factorion b) [1..]
factorions b = filter (factorion b) [1..]
result n = show . take n . factorions</lang>
result n = show . take n . factorions</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 660: Line 660:


=={{header|J}}==
=={{header|J}}==
<syntaxhighlight lang="j">
<lang J>
index=: $ #: I.@:,
index=: $ #: I.@:,
factorion=: 10&$: :(] = [: +/ [: ! #.^:_1)&>
factorion=: 10&$: :(] = [: +/ [: ! #.^:_1)&>
Line 689: Line 689:
11 5
11 5
12 2
12 2
</syntaxhighlight>
</lang>


=={{header|Java}}==
=={{header|Java}}==
<lang java>
<syntaxhighlight lang="java">
public class Factorion {
public class Factorion {
public static void main(String [] args){
public static void main(String [] args){
Line 765: Line 765:
}
}
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 779: Line 779:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>isfactorian(n, base) = mapreduce(factorial, +, map(c -> parse(Int, c, base=16), split(string(n, base=base), ""))) == n
<syntaxhighlight lang="julia">isfactorian(n, base) = mapreduce(factorial, +, map(c -> parse(Int, c, base=16), split(string(n, base=base), ""))) == n


printallfactorian(base) = println("Factorians for base $base: ", [n for n in 1:100000 if isfactorian(n, base)])
printallfactorian(base) = println("Factorians for base $base: ", [n for n in 1:100000 if isfactorian(n, base)])


foreach(printallfactorian, 9:12)
foreach(printallfactorian, 9:12)
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Factorians for base 9: [1, 2, 41282]
Factorians for base 9: [1, 2, 41282]
Line 793: Line 793:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ClearAll[FactorionQ]
<syntaxhighlight lang="mathematica">ClearAll[FactorionQ]
FactorionQ[n_,b_:10]:=Total[IntegerDigits[n,b]!]==n
FactorionQ[n_,b_:10]:=Total[IntegerDigits[n,b]!]==n
Select[Range[1500000],FactorionQ[#,9]&]
Select[Range[1500000],FactorionQ[#,9]&]
Select[Range[1500000],FactorionQ[#,10]&]
Select[Range[1500000],FactorionQ[#,10]&]
Select[Range[1500000],FactorionQ[#,11]&]
Select[Range[1500000],FactorionQ[#,11]&]
Select[Range[1500000],FactorionQ[#,12]&]</lang>
Select[Range[1500000],FactorionQ[#,12]&]</syntaxhighlight>
{{out}}
{{out}}
<pre>{1, 2, 41282}
<pre>{1, 2, 41282}
Line 807: Line 807:
=={{header|Nim}}==
=={{header|Nim}}==
Note that the library has precomputed the values of factorial, so there is no need for caching.
Note that the library has precomputed the values of factorial, so there is no need for caching.
<lang Nim>from math import fac
<syntaxhighlight lang="nim">from math import fac
from strutils import join
from strutils import join


Line 834: Line 834:
for base in 9..12:
for base in 9..12:
echo "Factorions for base ", base, ':'
echo "Factorions for base ", base, ':'
echo factorions(base, 1_500_000 - 1).join(" ")</lang>
echo factorions(base, 1_500_000 - 1).join(" ")</syntaxhighlight>


{{out}}
{{out}}
Line 848: Line 848:
=={{header|OCaml}}==
=={{header|OCaml}}==
{{trans|C}}
{{trans|C}}
<lang ocaml>let () =
<syntaxhighlight lang="ocaml">let () =
(* cache factorials from 0 to 11 *)
(* cache factorials from 0 to 11 *)
let fact = Array.make 12 0 in
let fact = Array.make 12 0 in
Line 869: Line 869:
done;
done;
print_string "\n\n";
print_string "\n\n";
done</lang>
done</syntaxhighlight>
=={{header|Pascal}}==
=={{header|Pascal}}==
modified [[munchhausen numbers#Pascal]].
modified [[munchhausen numbers#Pascal]].
output in base and 0! == 1!, so in Base 10 40585 has the same digits as 14558.
output in base and 0! == 1!, so in Base 10 40585 has the same digits as 14558.
<lang pascal>program munchhausennumber;
<syntaxhighlight lang="pascal">program munchhausennumber;
{$IFDEF FPC}{$MODE objFPC}{$Optimization,On,all}{$ELSE}{$APPTYPE CONSOLE}{$ENDIF}
{$IFDEF FPC}{$MODE objFPC}{$Optimization,On,all}{$ELSE}{$APPTYPE CONSOLE}{$ENDIF}
uses
uses
Line 987: Line 987:
end;
end;
writeln('Check Count ',cnt);
writeln('Check Count ',cnt);
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,063: Line 1,063:
{{trans|Raku}}
{{trans|Raku}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use ntheory qw/factorial todigits/;
use ntheory qw/factorial todigits/;
Line 1,086: Line 1,086:
}
}
print "\n\n";
print "\n\n";
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Factorions in base 9:
<pre>Factorions in base 9:
Line 1,104: Line 1,104:
{{trans|Sidef}}
{{trans|Sidef}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use 5.020;
<syntaxhighlight lang="perl">use 5.020;
use ntheory qw(:all);
use ntheory qw(:all);
use experimental qw(signatures);
use experimental qw(signatures);
Line 1,140: Line 1,140:
my @r = factorions($base);
my @r = factorions($base);
say "Factorions in base $base are (@r)";
say "Factorions in base $base are (@r)";
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,161: Line 1,161:
{{trans|C}}
{{trans|C}}
As per talk page (ok, ''and'' the task description), this is incorrectly using the base 10 limit for bases 9, 11, and 12.
As per talk page (ok, ''and'' the task description), this is incorrectly using the base 10 limit for bases 9, 11, and 12.
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">base</span><span style="color: #0000FF;">=</span><span style="color: #000000;">9</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">base</span><span style="color: #0000FF;">=</span><span style="color: #000000;">9</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
Line 1,176: Line 1,176:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,186: Line 1,186:
{{trans|Sidef}}
{{trans|Sidef}}
Using the correct limits and much faster, or at least it was until I upped the bases to 14.
Using the correct limits and much faster, or at least it was until I upped the bases to 14.
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">max_power</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">base</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">max_power</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">base</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
Line 1,224: Line 1,224:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Base %2d factorions: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">base</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">factorions</span><span style="color: #0000FF;">(</span><span style="color: #000000;">base</span><span style="color: #0000FF;">))})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Base %2d factorions: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">base</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">factorions</span><span style="color: #0000FF;">(</span><span style="color: #000000;">base</span><span style="color: #0000FF;">))})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,250: Line 1,250:
=={{header|PureBasic}}==
=={{header|PureBasic}}==
{{trans|C}}
{{trans|C}}
<lang PureBasic>Declare main()
<syntaxhighlight lang="purebasic">Declare main()


If OpenConsole() : main() : Else : End 1 : EndIf
If OpenConsole() : main() : Else : End 1 : EndIf
Line 1,273: Line 1,273:
Print(~"\n\n")
Print(~"\n\n")
Next
Next
EndProcedure</lang>
EndProcedure</syntaxhighlight>
{{out}}
{{out}}
<pre>The factorions for base 9 are:
<pre>The factorions for base 9 are:
Line 1,289: Line 1,289:
=={{header|Python}}==
=={{header|Python}}==
{{trans|C}}
{{trans|C}}
<lang Python>fact = [1] # cache factorials from 0 to 11
<syntaxhighlight lang="python">fact = [1] # cache factorials from 0 to 11
for n in range(1, 12):
for n in range(1, 12):
fact.append(fact[n-1] * n)
fact.append(fact[n-1] * n)
Line 1,305: Line 1,305:
print(i, end=" ")
print(i, end=" ")
print("\n")
print("\n")
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,324: Line 1,324:
=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ table ] is results ( n --> s )
<syntaxhighlight lang="quackery"> [ table ] is results ( n --> s )
4 times
4 times
[ ' [ stack [ ] ]
[ ' [ stack [ ] ]
Line 1,361: Line 1,361:
[ say "Factorions for base "
[ say "Factorions for base "
i^ radix echo say ": "
i^ radix echo say ": "
i^ results take echo cr ]</lang>
i^ results take echo cr ]</syntaxhighlight>


{{out}}
{{out}}
Line 1,375: Line 1,375:


{{trans|C}}
{{trans|C}}
<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(define fact
(define fact
Line 1,389: Line 1,389:
[(positive? n) (loop (+ sum (fact (modulo n b))) (quotient n b))]
[(positive? n) (loop (+ sum (fact (modulo n b))) (quotient n b))]
[(= sum i) (printf "~a " i)])))
[(= sum i) (printf "~a " i)])))
(newline))</lang>
(newline))</syntaxhighlight>


{{out}}
{{out}}
Line 1,407: Line 1,407:
{{works with|Rakudo|2019.07.1}}
{{works with|Rakudo|2019.07.1}}


<lang perl6>constant @factorial = 1, |[\*] 1..*;
<syntaxhighlight lang="raku" line>constant @factorial = 1, |[\*] 1..*;


constant $limit = 1500000;
constant $limit = 1500000;
Line 1,439: Line 1,439:
}
}


.say for @result[$bases];</lang>
.say for @result[$bases];</syntaxhighlight>
{{out}}
{{out}}
<pre>Factorions in base 9:
<pre>Factorions in base 9:
Line 1,455: Line 1,455:
=={{header|REXX}}==
=={{header|REXX}}==
{{trans|C}}
{{trans|C}}
<lang rexx>/*REXX program calculates and displays factorions in bases nine ───► twelve. */
<syntaxhighlight lang="rexx">/*REXX program calculates and displays factorions in bases nine ───► twelve. */
parse arg LOb HIb lim . /*obtain optional arguments from the CL*/
parse arg LOb HIb lim . /*obtain optional arguments from the CL*/
if LOb=='' | LOb=="," then LOb= 9 /*Not specified? Then use the default.*/
if LOb=='' | LOb=="," then LOb= 9 /*Not specified? Then use the default.*/
Line 1,479: Line 1,479:
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x; !=1; do j=2 to x; !=!*j; end; return ! /*factorials*/</lang>
!: procedure; parse arg x; !=1; do j=2 to x; !=!*j; end; return ! /*factorials*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,492: Line 1,492:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>
<syntaxhighlight lang="ruby">
def factorion?(n, base)
def factorion?(n, base)
n.digits(base).sum{|digit| (1..digit).inject(1, :*)} == n
n.digits(base).sum{|digit| (1..digit).inject(1, :*)} == n
Line 1,500: Line 1,500:
puts "Base #{base} factorions: #{(1..1_500_000).select{|n| factorion?(n, base)}.join(" ")} "
puts "Base #{base} factorions: #{(1..1_500_000).select{|n| factorion?(n, base)}.join(" ")} "
end
end
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>Base 9 factorions: 1 2 41282
<pre>Base 9 factorions: 1 2 41282
Line 1,510: Line 1,510:
=={{header|Scala}}==
=={{header|Scala}}==
{{trans|C++}}
{{trans|C++}}
<lang scala>object Factorion extends App {
<syntaxhighlight lang="scala">object Factorion extends App {
private def is_factorion(i: Int, b: Int): Boolean = {
private def is_factorion(i: Int, b: Int): Boolean = {
var sum = 0L
var sum = 0L
Line 1,529: Line 1,529:
println
println
})
})
}</lang>
}</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func max_power(b = 10) {
<syntaxhighlight lang="ruby">func max_power(b = 10) {
var m = 1
var m = 1
var f = (b-1)!
var f = (b-1)!
Line 1,562: Line 1,562:
var r = factorions(b)
var r = factorions(b)
say "Base #{'%2d' % b} factorions: #{r}"
say "Base #{'%2d' % b} factorions: #{r}"
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,582: Line 1,582:
{{trans|C}}
{{trans|C}}


<lang swift>var fact = Array(repeating: 0, count: 12)
<syntaxhighlight lang="swift">var fact = Array(repeating: 0, count: 12)


fact[0] = 1
fact[0] = 1
Line 1,609: Line 1,609:


print("\n")
print("\n")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,627: Line 1,627:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|Go}}
{{trans|Go}}
<lang vlang>import strconv
<syntaxhighlight lang="vlang">import strconv


fn main() {
fn main() {
Line 1,655: Line 1,655:
println("\n")
println("\n")
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,674: Line 1,674:
=={{header|Wren}}==
=={{header|Wren}}==
{{trans|C}}
{{trans|C}}
<lang ecmascript>// cache factorials from 0 to 11
<syntaxhighlight lang="ecmascript">// cache factorials from 0 to 11
var fact = List.filled(12, 0)
var fact = List.filled(12, 0)
fact[0] = 1
fact[0] = 1
Line 1,692: Line 1,692:
}
}
System.print("\n")
System.print("\n")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,710: Line 1,710:


=={{header|VBScript}}==
=={{header|VBScript}}==
<lang vb>' Factorions - VBScript - PG - 26/04/2020
<syntaxhighlight lang="vb">' Factorions - VBScript - PG - 26/04/2020
Dim fact()
Dim fact()
nn1=9 : nn2=12
nn1=9 : nn2=12
Line 1,732: Line 1,732:
Next
Next
Wscript.Echo "the factorions for base "& right(" "& base,2) &" are: "& list
Wscript.Echo "the factorions for base "& right(" "& base,2) &" are: "& list
Next </lang>
Next </syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,744: Line 1,744:
=={{header|zkl}}==
=={{header|zkl}}==
{{trans|C}}
{{trans|C}}
<lang zkl>var facts=[0..12].pump(List,fcn(n){ (1).reduce(n,fcn(N,n){ N*n },1) }); #(1,1,2,6....)
<syntaxhighlight lang="zkl">var facts=[0..12].pump(List,fcn(n){ (1).reduce(n,fcn(N,n){ N*n },1) }); #(1,1,2,6....)
fcn factorions(base){
fcn factorions(base){
fs:=List();
fs:=List();
Line 1,756: Line 1,756:
}
}
fs
fs
}</lang>
}</syntaxhighlight>
<lang zkl>foreach n in ([9..12]){
<syntaxhighlight lang="zkl">foreach n in ([9..12]){
println("The factorions for base %2d are: ".fmt(n),factorions(n).concat(" "));
println("The factorions for base %2d are: ".fmt(n),factorions(n).concat(" "));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>