Factorions: Difference between revisions
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
|||
Line 33: | Line 33: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<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")</ |
print("\n")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 67: | Line 67: | ||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
< |
<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 </ |
END FACTORIO </syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 138: | Line 138: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 171: | Line 171: | ||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |
||
< |
<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</ |
320 NEXT B</syntaxhighlight> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<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] |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 219: | Line 219: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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</ |
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}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
int main() { |
int main() { |
||
Line 313: | Line 313: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 332: | Line 332: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
class factorion_t { |
class factorion_t { |
||
Line 363: | Line 363: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</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}}== |
||
< |
<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 "~%")))</ |
(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.</ |
end.</syntaxhighlight> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<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}}== |
||
< |
<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</ |
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}}== |
||
< |
<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</ |
Sleep</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 559: | Line 559: | ||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
< |
<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"] |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 586: | Line 586: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 619: | Line 619: | ||
fmt.Println("\n") |
fmt.Println("\n") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 636: | Line 636: | ||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<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</ |
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}}== |
||
< |
<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}}== |
||
< |
<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) |
||
</ |
</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}}== |
||
< |
<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]&]</ |
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. |
||
< |
<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(" ")</ |
echo factorions(base, 1_500_000 - 1).join(" ")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 848: | Line 848: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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</ |
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. |
||
< |
<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.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,063: | Line 1,063: | ||
{{trans|Raku}} |
{{trans|Raku}} |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<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"; |
||
}</ |
}</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}} |
||
< |
<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)"; |
||
}</ |
}</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. |
||
<!--< |
<!--<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> |
||
<!--</ |
<!--</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. |
||
<!--< |
<!--<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,250: | Line 1,250: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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</ |
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}} |
||
< |
<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}}== |
||
< |
<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 ]</ |
i^ results take echo cr ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,375: | Line 1,375: | ||
{{trans|C}} |
{{trans|C}} |
||
< |
<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))</ |
(newline))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,407: | Line 1,407: | ||
{{works with|Rakudo|2019.07.1}} |
{{works with|Rakudo|2019.07.1}} |
||
<lang |
<syntaxhighlight lang="raku" line>constant @factorial = 1, |[\*] 1..*; |
||
constant $limit = 1500000; |
constant $limit = 1500000; |
||
Line 1,439: | Line 1,439: | ||
} |
} |
||
.say for @result[$bases];</ |
.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}} |
||
< |
<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*/</ |
!: procedure; parse arg x; !=1; do j=2 to x; !=!*j; end; return ! /*factorials*/</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,492: | Line 1,492: | ||
=={{header|Ruby}}== |
=={{header|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++}} |
||
< |
<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 |
||
}) |
}) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<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}" |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,582: | Line 1,582: | ||
{{trans|C}} |
{{trans|C}} |
||
< |
<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") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,627: | Line 1,627: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="vlang">import strconv |
||
fn main() { |
fn main() { |
||
Line 1,655: | Line 1,655: | ||
println("\n") |
println("\n") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,674: | Line 1,674: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,710: | Line 1,710: | ||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
< |
<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 </ |
Next </syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,744: | Line 1,744: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<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 |
||
}</ |
}</syntaxhighlight> |
||
< |
<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(" ")); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
Revision as of 11:17, 27 August 2022
You are encouraged to solve this task according to the task description, using any language you may know.
- Definition
A factorion is a natural number that equals the sum of the factorials of its digits.
- Example
145 is a factorion in base 10 because:
1! + 4! + 5! = 1 + 24 + 120 = 145
It can be shown (see talk page) that no factorion in base 10 can exceed 1,499,999.
- Task
Write a program in your language to demonstrate, by calculating and printing out the factorions, that:
- There are 3 factorions in base 9
- There are 4 factorions in base 10
- There are 5 factorions in base 11
- There are 2 factorions in base 12 (up to the same upper bound as for base 10)
11l
V fact = [1]
L(n) 1..11
fact.append(fact[n-1] * n)
L(b) 9..12
print(‘The factorions for base ’b‘ are:’)
L(i) 1..1'499'999
V fact_sum = 0
V j = i
L j > 0
V d = j % b
fact_sum += fact[d]
j I/= b
I fact_sum == i
print(i, end' ‘ ’)
print("\n")
- Output:
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
360 Assembly
* Factorions 26/04/2020
FACTORIO CSECT
USING FACTORIO,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
ST R15,8(R13) link forward
LR R13,R15 set addressability
XR R4,R4 ~
LA R5,1 f=1
LA R3,FACT+4 @fact(1)
LA R6,1 i=1
DO WHILE=(C,R6,LE,=A(NN2)) do i=1 to nn2
MR R4,R6 fact(i-1)*i
ST R5,0(R3) fact(i)=fact(i-1)*i
LA R3,4(R3) @fact(i+1)
LA R6,1(R6) i++
ENDDO , enddo i
LA R7,NN1 base=nn1
DO WHILE=(C,R7,LE,=A(NN2)) do base=nn1 to nn2
MVC PG,PGX init buffer
LA R3,PG+6 @buffer
XDECO R7,XDEC edit base
MVC PG+5(2),XDEC+10 output base
LA R3,PG+10 @buffer
LA R6,1 i=1
DO WHILE=(C,R6,LE,LIM) do i=1 to lim
LA R9,0 s=0
LR R8,R6 t=i
DO WHILE=(C,R8,NE,=F'0') while t<>0
XR R4,R4 ~
LR R5,R8 t
DR R4,R7 r5=t/base; r4=d=(t mod base)
LR R1,R4 d
SLA R1,2 ~
L R2,FACT(R1) fact(d)
AR R9,R2 s=s+fact(d)
LR R8,R5 t=t/base
ENDDO , endwhile
IF CR,R9,EQ,R6 THEN if s=i then
XDECO R6,XDEC edit i
MVC 0(6,R3),XDEC+6 output i
LA R3,7(R3) @buffer
ENDIF , endif
LA R6,1(R6) i++
ENDDO , enddo i
XPRNT PG,L'PG print buffer
LA R7,1(R7) base++
ENDDO , enddo base
L R13,4(0,R13) restore previous savearea pointer
RETURN (14,12),RC=0 restore registers from calling save
NN1 EQU 9 nn1=9
NN2 EQU 12 nn2=12
LIM DC f'1499999' lim=1499999
FACT DC (NN2+1)F'1' fact(0:12)
PG DS CL80 buffer
PGX DC CL80'Base .. : ' buffer init
XDEC DS CL12 temp fo xdeco
REGEQU
END FACTORIO
- Output:
Base 9 : 1 2 41282 Base 10 : 1 2 145 40585 Base 11 : 1 2 26 48 40472 Base 12 : 1 2
ALGOL 68
BEGIN
# cache factorials from 0 to 11 #
[ 0 : 11 ]INT fact;
fact[0] := 1;
FOR n TO 11 DO
fact[n] := fact[n-1] * n
OD;
FOR b FROM 9 TO 12 DO
print( ( "The factorions for base ", whole( b, 0 ), " are:", newline ) );
FOR i TO 1500000 - 1 DO
INT sum := 0;
INT j := i;
WHILE j > 0 DO
sum +:= fact[ j MOD b ];
j OVERAB b
OD;
IF sum = i THEN print( ( whole( i, 0 ), " " ) ) FI
OD;
print( ( newline ) )
OD
END
- Output:
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
Applesoft 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
Arturo
factorials: [1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800]
factorion?: function [n, base][
try? [
n = sum map digits.base:base n 'x -> factorials\[x]
]
else [
print ["n:" n "base:" base]
false
]
]
loop 9..12 'base ->
print ["Base" base "factorions:" select 1..45000 'z -> factorion? z base]
]
- Output:
Base 9 factorions: [1 2 41282] Base 10 factorions: [1 2 145 40585] Base 11 factorions: [1 2 26 48 40472] Base 12 factorions: [1 2]
AutoHotkey
fact:=[]
fact[0] := 1
while (A_Index < 12)
fact[A_Index] := fact[A_Index-1] * A_Index
b := 9
while (b <= 12) {
res .= "base " b " factorions: `t"
while (A_Index < 1500000){
sum := 0
j := A_Index
while (j > 0){
d := Mod(j, b)
sum += fact[d]
j /= b
}
if (sum = A_Index)
res .= A_Index " "
}
b++
res .= "`n"
}
MsgBox % res
return
- Output:
base 9 factorions: 1 2 41282 base 10 factorions: 1 2 145 40585 base 11 factorions: 1 2 26 48 40472 base 12 factorions: 1 2
AWK
# syntax: GAWK -f FACTORIONS.AWK
# converted from C
BEGIN {
fact[0] = 1 # cache factorials from 0 to 11
for (n=1; n<12; ++n) {
fact[n] = fact[n-1] * n
}
for (b=9; b<=12; ++b) {
printf("base %d factorions:",b)
for (i=1; i<1500000; ++i) {
sum = 0
j = i
while (j > 0) {
d = j % b
sum += fact[d]
j = int(j/b)
}
if (sum == i) {
printf(" %d",i)
}
}
printf("\n")
}
exit(0)
}
- Output:
base 9 factorions: 1 2 41282 base 10 factorions: 1 2 145 40585 base 11 factorions: 1 2 26 48 40472 base 12 factorions: 1 2
C
#include <stdio.h>
int main() {
int n, b, d;
unsigned long long i, j, sum, fact[12];
// cache factorials from 0 to 11
fact[0] = 1;
for (n = 1; n < 12; ++n) {
fact[n] = fact[n-1] * n;
}
for (b = 9; b <= 12; ++b) {
printf("The factorions for base %d are:\n", b);
for (i = 1; i < 1500000; ++i) {
sum = 0;
j = i;
while (j > 0) {
d = j % b;
sum += fact[d];
j /= b;
}
if (sum == i) printf("%llu ", i);
}
printf("\n\n");
}
return 0;
}
- Output:
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
C++
#include <iostream>
class factorion_t {
public:
factorion_t() {
f[0] = 1u;
for (uint n = 1u; n < 12u; n++)
f[n] = f[n - 1] * n;
}
bool operator()(uint i, uint b) const {
uint sum = 0;
for (uint j = i; j > 0u; j /= b)
sum += f[j % b];
return sum == i;
}
private:
ulong f[12]; //< cache factorials from 0 to 11
};
int main() {
factorion_t factorion;
for (uint b = 9u; b <= 12u; ++b) {
std::cout << "factorions for base " << b << ':';
for (uint i = 1u; i < 1500000u; ++i)
if (factorion(i, b))
std::cout << ' ' << i;
std::cout << std::endl;
}
return 0;
}
- Output:
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
Common Lisp
(defparameter *bases* '(9 10 11 12))
(defparameter *limit* 1500000)
(defun ! (n) (apply #'* (loop for i from 2 to n collect i)))
(defparameter *digit-factorials* (mapcar #'! (loop for i from 0 to (1- (apply #'max *bases*)) collect i)))
(defun fact (n) (nth n *digit-factorials*))
(defun digit-value (digit)
(let ((decimal (digit-char-p digit)))
(cond ((not (null decimal)) decimal)
((char>= #\Z digit #\A) (+ (char-code digit) (- (char-code #\A)) 10))
((char>= #\z digit #\a) (+ (char-code digit) (- (char-code #\a)) 10))
(t nil))))
(defun factorionp (n &optional (base 10))
(= n (apply #'+
(mapcar #'fact
(map 'list #'digit-value
(write-to-string n :base base))))))
(loop for base in *bases* do
(let ((factorions
(loop for i from 1 while (< i *limit*) if (factorionp i base) collect i)))
(format t "In base ~a there are ~a factorions:~%" base (list-length factorions))
(loop for n in factorions do
(format t "~c~a" #\Tab (write-to-string n :base base))
(if (/= base 10) (format t " (decimal ~a)" n))
(format t "~%"))
(format t "~%")))
- Output:
In base 9 there are 3 factorions: 1 (decimal 1) 2 (decimal 2) 62558 (decimal 41282) In base 10 there are 4 factorions: 1 2 145 40585 In base 11 there are 5 factorions: 1 (decimal 1) 2 (decimal 2) 24 (decimal 26) 44 (decimal 48) 28453 (decimal 40472) In base 12 there are 2 factorions: 1 (decimal 1) 2 (decimal 2)
Delphi
program Factorions;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
begin
var fact: TArray<UInt64>;
SetLength(fact, 12);
fact[0] := 0;
for var n := 1 to 11 do
fact[n] := fact[n - 1] * n;
for var b := 9 to 12 do
begin
writeln('The factorions for base ', b, ' are:');
for var i := 1 to 1499999 do
begin
var sum := 0;
var j := i;
while j > 0 do
begin
var d := j mod b;
sum := sum + fact[d];
j := j div b;
end;
if sum = i then
writeln(i, ' ');
end;
writeln(#10);
end;
readln;
end.
F#
// 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 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 "")
- Output:
In base 9 Factorians are: 1 2 41282 In base 10 Factorians are: 1 2 145 40585 In base 11 Factorians are: 1 2 26 48 40472 In base 12 Factorians are: 1 2
Factor
USING: formatting io kernel math math.parser math.ranges memoize
prettyprint sequences ;
IN: rosetta-code.factorions
! Memoize factorial function
MEMO: factorial ( n -- n! ) [ 1 ] [ [1,b] product ] if-zero ;
: factorion? ( n base -- ? )
dupd >base string>digits [ factorial ] map-sum = ;
: show-factorions ( limit base -- )
dup "The factorions for base %d are:\n" printf
[ [1,b) ] dip [ dupd factorion? [ pprint bl ] [ drop ] if ]
curry each nl ;
1,500,000 9 12 [a,b] [ show-factorions nl ] with each
- Output:
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
Fōrmulæ
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 —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.
Programs in Fōrmulæ are created/edited online in its 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.
In this page you can see the program(s) related to this task and their results.
FreeBASIC
Dim As Integer fact(12), suma, d, j
fact(0) = 1
For n As Integer = 1 To 11
fact(n) = fact(n-1) * n
Next n
For b As Integer = 9 To 12
Print "Los factoriones para base " & b & " son: "
For i As Integer = 1 To 1499999
suma = 0
j = i
While j > 0
d = j Mod b
suma += fact(d)
j \= b
Wend
If suma = i Then Print i & " ";
Next i
Print : Print
Next b
Sleep
- Output:
Los factoriones para base 9 son: 1 2 41282 Los factoriones para base 10 son: 1 2 145 40585 Los factoriones para base 11 son: 1 2 26 48 40472 Los factoriones para base 12 son: 1 2
Frink
factorion[n, base] := sum[map["factorial", integerDigits[n, base]]]
for base = 9 to 12
{
for n = 1 to 1_499_999
if n == factorion[n, base]
println["$base\t$n"]
}
- Output:
9 1 9 2 9 41282 10 1 10 2 10 145 10 40585 11 1 11 2 11 26 11 48 11 40472 12 1 12 2
Go
package main
import (
"fmt"
"strconv"
)
func main() {
// cache factorials from 0 to 11
var fact [12]uint64
fact[0] = 1
for n := uint64(1); n < 12; n++ {
fact[n] = fact[n-1] * n
}
for b := 9; b <= 12; b++ {
fmt.Printf("The factorions for base %d are:\n", b)
for i := uint64(1); i < 1500000; i++ {
digits := strconv.FormatUint(i, b)
sum := uint64(0)
for _, digit := range digits {
if digit < 'a' {
sum += fact[digit-'0']
} else {
sum += fact[digit+10-'a']
}
}
if sum == i {
fmt.Printf("%d ", i)
}
}
fmt.Println("\n")
}
}
- Output:
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
Haskell
import Text.Printf (printf)
import Data.List (unfoldr)
import Control.Monad (guard)
factorion :: Int -> Int -> Bool
factorion b n = f b n == n
where
f b = sum . map (product . enumFromTo 1) . unfoldr (\x -> guard (x > 0) >> pure (x `mod` b, x `div` b))
main :: IO ()
main = mapM_ (uncurry (printf "Factorions for base %2d: %s\n") . (\(a, b) -> (b, result a b)))
[(3,9), (4,10), (5,11), (2,12)]
where
factorions b = filter (factorion b) [1..]
result n = show . take n . factorions
- Output:
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]
J
index=: $ #: I.@:,
factorion=: 10&$: :(] = [: +/ [: ! #.^:_1)&>
FACTORIONS=: 9 0 +"1 index Q=: 9 10 11 12 factorion/ i. 1500000
NB. columns: base, factorion in base 10, factorion in base
(,. ".@:((Num_j_,26}.Alpha_j_) {~ #.inv/)"1) FACTORIONS
9 1 1
9 2 2
9 41282 62558
10 1 1
10 2 2
10 145 145
10 40585 40585
11 1 1
11 2 2
11 26 24
11 48 44
11 40472 28453
12 1 1
12 2 2
NB. tallies of factorions in the bases
(9+i.4),.+/"1 Q
9 3
10 4
11 5
12 2
Java
public class Factorion {
public static void main(String [] args){
System.out.println("Base 9:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,9);
if(multiplied == i){
System.out.print(i + "\t");
}
}
System.out.println("\nBase 10:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,10);
if(multiplied == i){
System.out.print(i + "\t");
}
}
System.out.println("\nBase 11:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,11);
if(multiplied == i){
System.out.print(i + "\t");
}
}
System.out.println("\nBase 12:");
for(int i = 1; i <= 1499999; i++){
String iStri = String.valueOf(i);
int multiplied = operate(iStri,12);
if(multiplied == i){
System.out.print(i + "\t");
}
}
}
public static int factorialRec(int n){
int result = 1;
return n == 0 ? result : result * n * factorialRec(n-1);
}
public static int operate(String s, int base){
int sum = 0;
String strx = fromDeci(base, Integer.parseInt(s));
for(int i = 0; i < strx.length(); i++){
if(strx.charAt(i) == 'A'){
sum += factorialRec(10);
}else if(strx.charAt(i) == 'B') {
sum += factorialRec(11);
}else if(strx.charAt(i) == 'C') {
sum += factorialRec(12);
}else {
sum += factorialRec(Integer.parseInt(String.valueOf(strx.charAt(i)), base));
}
}
return sum;
}
// Ln 57-71 from Geeks for Geeks @ https://www.geeksforgeeks.org/convert-base-decimal-vice-versa/
static char reVal(int num) {
if (num >= 0 && num <= 9)
return (char)(num + 48);
else
return (char)(num - 10 + 65);
}
static String fromDeci(int base, int num){
StringBuilder s = new StringBuilder();
while (num > 0) {
s.append(reVal(num % base));
num /= base;
}
return new String(new StringBuilder(s).reverse());
}
}
- Output:
Base 9: 1 2 41282 Base 10: 1 2 145 40585 Base 11: 1 2 26 48 40472 Base 12: 1 2
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)])
foreach(printallfactorian, 9:12)
- Output:
Factorians for base 9: [1, 2, 41282] Factorians for base 10: [1, 2, 145, 40585] Factorians for base 11: [1, 2, 26, 48, 40472] Factorians for base 12: [1, 2]
Mathematica / Wolfram Language
ClearAll[FactorionQ]
FactorionQ[n_,b_:10]:=Total[IntegerDigits[n,b]!]==n
Select[Range[1500000],FactorionQ[#,9]&]
Select[Range[1500000],FactorionQ[#,10]&]
Select[Range[1500000],FactorionQ[#,11]&]
Select[Range[1500000],FactorionQ[#,12]&]
- Output:
{1, 2, 41282} {1, 2, 145, 40585} {1, 2, 26, 48, 40472} {1, 2}
Nim
Note that the library has precomputed the values of factorial, so there is no need for caching.
from math import fac
from strutils import join
iterator digits(n, base: Natural): Natural =
## Yield the digits of "n" in base "base".
var n = n
while true:
yield n mod base
n = n div base
if n == 0: break
func isFactorion(n, base: Natural): bool =
## Return true if "n" is a factorion for base "base".
var s = 0
for d in n.digits(base):
inc s, fac(d)
result = s == n
func factorions(base, limit: Natural): seq[Natural] =
## Return the list of factorions for base "base" up to "limit".
for n in 1..limit:
if n.isFactorion(base):
result.add(n)
for base in 9..12:
echo "Factorions for base ", base, ':'
echo factorions(base, 1_500_000 - 1).join(" ")
- Output:
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
OCaml
let () =
(* cache factorials from 0 to 11 *)
let fact = Array.make 12 0 in
fact.(0) <- 1;
for n = 1 to pred 12 do
fact.(n) <- fact.(n-1) * n;
done;
for b = 9 to 12 do
Printf.printf "The factorions for base %d are:\n" b;
for i = 1 to pred 1_500_000 do
let sum = ref 0 in
let j = ref i in
while !j > 0 do
let d = !j mod b in
sum := !sum + fact.(d);
j := !j / b;
done;
if !sum = i then (print_int i; print_string " ")
done;
print_string "\n\n";
done
Pascal
modified munchhausen numbers#Pascal. output in base and 0! == 1!, so in Base 10 40585 has the same digits as 14558.
program munchhausennumber;
{$IFDEF FPC}{$MODE objFPC}{$Optimization,On,all}{$ELSE}{$APPTYPE CONSOLE}{$ENDIF}
uses
sysutils;
type
tdigit = byte;
const
MAXBASE = 17;
var
DgtPotDgt : array[0..MAXBASE-1] of NativeUint;
dgtCnt : array[0..MAXBASE-1] of NativeInt;
cnt: NativeUint;
function convertToString(n:NativeUint;base:byte):AnsiString;
const
cBASEDIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz';
var
r,dgt: NativeUint;
begin
IF base > length(cBASEDIGITS) then
EXIT('Base to big');
result := '';
repeat
r := n div base;
dgt := n-r*base;
result := cBASEDIGITS[dgt+1]+result;
n := r;
until n =0;
end;
function CheckSameDigits(n1,n2,base:NativeUInt):boolean;
var
i : NativeUInt;
Begin
fillchar(dgtCnt,SizeOf(dgtCnt),#0);
repeat
//increment digit of n1
i := n1;n1 := n1 div base;i := i-n1*base;inc(dgtCnt[i]);
//decrement digit of n2
i := n2;n2 := n2 div base;i := i-n2*base;dec(dgtCnt[i]);
until (n1=0) AND (n2= 0);
result := true;
For i := 2 to Base-1 do
result := result AND (dgtCnt[i]=0);
result := result AND (dgtCnt[0]+dgtCnt[1]=0);
end;
procedure Munch(number,DgtPowSum,minDigit:NativeUInt;digits,base:NativeInt);
var
i: NativeUint;
s1,s2: AnsiString;
begin
inc(cnt);
number := number*base;
IF digits > 1 then
Begin
For i := minDigit to base-1 do
Munch(number+i,DgtPowSum+DgtPotDgt[i],i,digits-1,base);
end
else
For i := minDigit to base-1 do
//number is always the arrangement of the digits leading to smallest number
IF (number+i)<= (DgtPowSum+DgtPotDgt[i]) then
IF CheckSameDigits(number+i,DgtPowSum+DgtPotDgt[i],base) then
iF number+i>0 then
begin
s1 := convertToString(DgtPowSum+DgtPotDgt[i],base);
s2 := convertToString(number+i,base);
If length(s1)= length(s2) then
writeln(Format('%*d %*s %*s',[Base-1,DgtPowSum+DgtPotDgt[i],Base-1,s1,Base-1,s2]));
end;
end;
//factorions
procedure InitDgtPotDgt(base:byte);
var
i: NativeUint;
Begin
DgtPotDgt[0]:= 1;
For i := 1 to Base-1 do
DgtPotDgt[i] := DgtPotDgt[i-1]*i;
DgtPotDgt[0]:= 0;
end;
{
//Munchhausen numbers
procedure InitDgtPotDgt;
var
i,k,dgtpow: NativeUint;
Begin
// digit ^ digit ,special case 0^0 here 0
DgtPotDgt[0]:= 0;
For i := 1 to Base-1 do
Begin
dgtpow := i;
For k := 2 to i do
dgtpow := dgtpow*i;
DgtPotDgt[i] := dgtpow;
end;
end;
}
var
base : byte;
begin
cnt := 0;
For base := 2 to MAXBASE do
begin
writeln('Base = ',base);
InitDgtPotDgt(base);
Munch(0,0,0,base,base);
end;
writeln('Check Count ',cnt);
end.
- Output:
TIO.RUN Real time: 45.701 s User time: 44.968 s Sys. time: 0.055 s CPU share: 98.51 % Base = 2 1 1 1 Base = 3 1 1 1 2 2 2 Base = 4 1 1 1 2 2 2 7 13 13 Base = 5 1 1 1 2 2 2 49 144 144 Base = 6 1 1 1 2 2 2 25 41 14 26 42 24 Base = 7 1 1 1 2 2 2 Base = 8 1 1 1 2 2 2 Base = 9 1 1 1 2 2 2 41282 62558 25568 Base = 10 1 1 1 2 2 2 145 145 145 40585 40585 14558 Base = 11 1 1 1 2 2 2 26 24 24 48 44 44 40472 28453 23458 Base = 12 1 1 1 2 2 2 Base = 13 1 1 1 2 2 2 519326767 83790C5B 135789BC Base = 14 1 1 1 2 2 2 12973363226 8B0DD409C 11489BCDD Base = 15 1 1 1 2 2 2 1441 661 166 1442 662 266 Base = 16 1 1 1 2 2 2 2615428934649 260F3B66BF9 1236669BBFF Base = 17 1 1 1 2 2 2 40465 8405 1458 43153254185213 146F2G8500G4 111244568FGG 43153254226251 146F2G8586G4 124456688FGG Check Count 1571990934
Perl
Raku version
use strict;
use warnings;
use ntheory qw/factorial todigits/;
my $limit = 1500000;
for my $b (9 .. 12) {
print "Factorions in base $b:\n";
$_ == factorial($_) and print "$_ " for 0..$b-1;
for my $i (1 .. int $limit/$b) {
my $sum;
my $prod = $i * $b;
for (reverse todigits($i, $b)) {
$sum += factorial($_);
$sum = 0 && last if $sum > $prod;
}
next if $sum == 0;
($sum + factorial($_) == $prod + $_) and print $prod+$_ . ' ' for 0..$b-1;
}
print "\n\n";
}
- Output:
Factorions in base 9: 1 2 41282 Factorions in base 10: 1 2 145 40585 Factorions in base 11: 1 2 26 48 40472 Factorions in base 12: 1 2
Sidef version
Alternatively, a more efficient approach:
use 5.020;
use ntheory qw(:all);
use experimental qw(signatures);
use Algorithm::Combinatorics qw(combinations_with_repetition);
sub max_power ($base = 10) {
my $m = 1;
my $f = factorial($base - 1);
while ($m * $f >= $base**($m-1)) {
$m += 1;
}
return $m-1;
}
sub factorions ($base = 10) {
my @result;
my @digits = (0 .. $base-1);
my @factorial = map { factorial($_) } @digits;
foreach my $k (1 .. max_power($base)) {
my $iter = combinations_with_repetition(\@digits, $k);
while (my $comb = $iter->next) {
my $n = vecsum(map { $factorial[$_] } @$comb);
if (join(' ', sort { $a <=> $b } todigits($n, $base)) eq join(' ', @$comb)) {
push @result, $n;
}
}
}
return @result;
}
foreach my $base (2 .. 14) {
my @r = factorions($base);
say "Factorions in base $base are (@r)";
}
- Output:
Factorions in base 2 are (1 2) Factorions in base 3 are (1 2) Factorions in base 4 are (1 2 7) Factorions in base 5 are (1 2 49) Factorions in base 6 are (1 2 25 26) Factorions in base 7 are (1 2) Factorions in base 8 are (1 2) Factorions in base 9 are (1 2 41282) Factorions in base 10 are (1 2 145 40585) Factorions in base 11 are (1 2 26 48 40472) Factorions in base 12 are (1 2) Factorions in base 13 are (1 2 519326767) Factorions in base 14 are (1 2 12973363226)
Phix
As per talk page (ok, and the task description), this is incorrectly using the base 10 limit for bases 9, 11, and 12.
with javascript_semantics for base=9 to 12 do printf(1,"The factorions for base %d are: ", base) for i=1 to 1499999 do atom total = 0, j = i, d while j>0 and total<=i do d = remainder(j,base) total += factorial(d) j = floor(j/base) end while if total==i then printf(1,"%d ", i) end if end for printf(1,"\n") end for
- Output:
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
Using the correct limits and much faster, or at least it was until I upped the bases to 14.
with javascript_semantics function max_power(integer base = 10) integer m = 1 atom f = factorial(base-1) while m*f >= power(base,m-1) do m += 1 end while return m-1 end function constant digits = "0123456789abcd" function fcomb(sequence res, integer base, n, at=1, atom fsum=0, string chosen="") if length(chosen)=n then string fs = sort(sprintf("%a",{{base,fsum}})) if fs=chosen then res = append(res,sprintf("%d",fsum)) end if else for i=at to base do res = fcomb(res,base,n,i,fsum+factorial(i-1),chosen&digits[i]) end for end if return res end function function factorions(integer base = 10) sequence result = {} for k=1 to max_power(base) do result &= fcomb({},base,k) end for return result end function for base=2 to 14 do printf(1,"Base %2d factorions: %s\n",{base,join(factorions(base))}) end for
- Output:
Base 2 factorions: 1 2 Base 3 factorions: 1 2 Base 4 factorions: 1 2 7 Base 5 factorions: 1 2 49 Base 6 factorions: 1 2 25 26 Base 7 factorions: 1 2 Base 8 factorions: 1 2 Base 9 factorions: 1 2 41282 Base 10 factorions: 1 2 145 40585 Base 11 factorions: 1 2 26 48 40472 Base 12 factorions: 1 2 Base 13 factorions: 1 2 519326767 Base 14 factorions: 1 2 12973363226
It will in fact go all the way to 17, though I don't recommend it:
Base 15 factorions: 1 2 1441 1442 Base 16 factorions: 1 2 2615428934649 Base 17 factorions: 1 2 40465 43153254185213 43153254226251
PureBasic
Declare main()
If OpenConsole() : main() : Else : End 1 : EndIf
Input() : End
Procedure main()
Define.i n,b,d,i,j,sum
Dim fact.i(12)
fact(0)=1
For n=1 To 11 : fact(n)=fact(n-1)*n : Next
For b=9 To 12
PrintN("The factorions for base "+Str(b)+" are: ")
For i=1 To 1500000-1
sum=0 : j=i
While j>0
d=j%b : sum+fact(d) : j/b
Wend
If sum=i : Print(Str(i)+" ") : EndIf
Next
Print(~"\n\n")
Next
EndProcedure
- Output:
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
Python
fact = [1] # cache factorials from 0 to 11
for n in range(1, 12):
fact.append(fact[n-1] * n)
for b in range(9, 12+1):
print(f"The factorions for base {b} are:")
for i in range(1, 1500000):
fact_sum = 0
j = i
while j > 0:
d = j % b
fact_sum += fact[d]
j = j//b
if fact_sum == i:
print(i, end=" ")
print("\n")
- Output:
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
Quackery
[ table ] is results ( n --> s )
4 times
[ ' [ stack [ ] ]
copy
' results put ]
[ results dup take
rot join swap put ] is addresult ( n n --> )
[ table 9 10 11 12 ] is radix ( n --> n )
[ table 1 ] is ! ( n --> n )
1 11 times
[ i^ 1+ * dup
' ! put ]
drop
[ dip dup
0 temp put
[ tuck /mod !
temp tally
swap over 0 =
until ]
2drop
temp take = ] is factorion ( n n --> b )
1500000 times
[ i^ 4 times
[ dup
i^ radix
factorion if
[ dup i^
addresult ] ]
drop ]
4 times
[ say "Factorions for base "
i^ radix echo say ": "
i^ results take echo cr ]
- Output:
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 ]
Racket
#lang racket
(define fact
(curry list-ref (for/fold ([result (list 1)] #:result (reverse result))
([x (in-range 1 20)])
(cons (* x (first result)) result))))
(for ([b (in-range 9 13)])
(printf "The factorions for base ~a are:\n" b)
(for ([i (in-range 1 1500000)])
(let loop ([sum 0] [n i])
(cond
[(positive? n) (loop (+ sum (fact (modulo n b))) (quotient n b))]
[(= sum i) (printf "~a " i)])))
(newline))
- Output:
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
Raku
(formerly Perl 6)
constant @factorial = 1, |[\*] 1..*;
constant $limit = 1500000;
constant $bases = 9 .. 12;
my @result;
$bases.map: -> $base {
@result[$base] = "\nFactorions in base $base:\n1 2";
sink (1 .. $limit div $base).map: -> $i {
my $product = $i * $base;
my $partial;
for $i.polymod($base xx *) {
$partial += @factorial[$_];
last if $partial > $product
}
next if $partial > $product;
my $sum;
for ^$base {
last if ($sum = $partial + @factorial[$_]) > $product + $_;
@result[$base] ~= " $sum" and last if $sum == $product + $_
}
}
}
.say for @result[$bases];
- Output:
Factorions in base 9: 1 2 41282 Factorions in base 10: 1 2 145 40585 Factorions in base 11: 1 2 26 48 40472 Factorions in base 12: 1 2
REXX
/*REXX program calculates and displays factorions in bases nine ───► twelve. */
parse arg LOb HIb lim . /*obtain optional arguments from the CL*/
if LOb=='' | LOb=="," then LOb= 9 /*Not specified? Then use the default.*/
if HIb=='' | HIb=="," then HIb= 12 /* " " " " " " */
if lim=='' | lim=="," then lim= 1500000 - 1 /* " " " " " " */
do fact=0 to HIb; !.fact= !(fact) /*use memoization for factorials. */
end /*fact*/
do base=LOb to HIb /*process all the required bases. */
@= 1 2 /*initialize the list (@) to 1 & 2. */
do j=3 for lim-2; $= 0 /*initialize the sum ($) to zero. */
t= j /*define the target (for the sum !'s).*/
do until t==0; d= t // base /*obtain a "digit".*/
$= $ + !.d /*add !(d) to sum.*/
t= t % base /*get a new target.*/
end /*until*/
if $==j then @= @ j /*Good factorial sum? Then add to list.*/
end /*i*/
say
say 'The factorions for base ' right( base, length(HIb) ) " are: " @
end /*base*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
!: procedure; parse arg x; !=1; do j=2 to x; !=!*j; end; return ! /*factorials*/
- output when using the default inputs:
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
Ruby
def factorion?(n, base)
n.digits(base).sum{|digit| (1..digit).inject(1, :*)} == n
end
(9..12).each do |base|
puts "Base #{base} factorions: #{(1..1_500_000).select{|n| factorion?(n, base)}.join(" ")} "
end
- Output:
Base 9 factorions: 1 2 41282 Base 10 factorions: 1 2 145 40585 Base 11 factorions: 1 2 26 48 40472 Base 12 factorions: 1 2
Scala
object Factorion extends App {
private def is_factorion(i: Int, b: Int): Boolean = {
var sum = 0L
var j = i
while (j > 0) {
sum += f(j % b)
j /= b
}
sum == i
}
private val f = Array.ofDim[Long](12)
f(0) = 1L
(1 until 12).foreach(n => f(n) = f(n - 1) * n)
(9 to 12).foreach(b => {
print(s"factorions for base $b:")
(1 to 1500000).filter(is_factorion(_, b)).foreach(i => print(s" $i"))
println
})
}
Sidef
func max_power(b = 10) {
var m = 1
var f = (b-1)!
while (m*f >= b**(m-1)) {
m += 1
}
return m-1
}
func factorions(b = 10) {
var result = []
var digits = @^b
var fact = digits.map { _! }
for k in (1 .. max_power(b)) {
digits.combinations_with_repetition(k, {|*comb|
var n = comb.sum_by { fact[_] }
if (n.digits(b).sort == comb) {
result << n
}
})
}
return result
}
for b in (2..12) {
var r = factorions(b)
say "Base #{'%2d' % b} factorions: #{r}"
}
- Output:
Base 2 factorions: [1, 2] Base 3 factorions: [1, 2] Base 4 factorions: [1, 2, 7] Base 5 factorions: [1, 2, 49] Base 6 factorions: [1, 2, 25, 26] Base 7 factorions: [1, 2] Base 8 factorions: [1, 2] Base 9 factorions: [1, 2, 41282] Base 10 factorions: [1, 2, 145, 40585] Base 11 factorions: [1, 2, 26, 48, 40472] Base 12 factorions: [1, 2]
Swift
var fact = Array(repeating: 0, count: 12)
fact[0] = 1
for n in 1..<12 {
fact[n] = fact[n - 1] * n
}
for b in 9...12 {
print("The factorions for base \(b) are:")
for i in 1..<1500000 {
var sum = 0
var j = i
while j > 0 {
sum += fact[j % b]
j /= b
}
if sum == i {
print("\(i)", terminator: " ")
fflush(stdout)
}
}
print("\n")
}
- Output:
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
Vlang
import strconv
fn main() {
// cache factorials from 0 to 11
mut fact := [12]u64{}
fact[0] = 1
for n := u64(1); n < 12; n++ {
fact[n] = fact[n-1] * n
}
for b := 9; b <= 12; b++ {
println("The factorions for base $b are:")
for i := u64(1); i < 1500000; i++ {
digits := strconv.format_uint(i, b)
mut sum := u64(0)
for digit in digits {
if digit < `a` {
sum += fact[digit-`0`]
} else {
sum += fact[digit+10-`a`]
}
}
if sum == i {
print("$i ")
}
}
println("\n")
}
}
- Output:
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
Wren
// cache factorials from 0 to 11
var fact = List.filled(12, 0)
fact[0] = 1
for (n in 1..11) fact[n] = fact[n-1] * n
for (b in 9..12) {
System.print("The factorions for base %(b) are:")
for (i in 1...1500000) {
var sum = 0
var j = i
while (j > 0) {
var d = j % b
sum = sum + fact[d]
j = (j/b).floor
}
if (sum == i) System.write("%(i) ")
}
System.print("\n")
}
- Output:
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
VBScript
' 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
- Output:
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
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){
fs:=List();
foreach n in ([1..1_499_999]){
sum,j := 0,n;
while(j){
sum+=facts[j%base];
j/=base;
}
if(sum==n) fs.append(n);
}
fs
}
foreach n in ([9..12]){
println("The factorions for base %2d are: ".fmt(n),factorions(n).concat(" "));
}
- Output:
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
- Programming Tasks
- Solutions by Programming Task
- 11l
- 360 Assembly
- ALGOL 68
- Applesoft BASIC
- Arturo
- AutoHotkey
- AWK
- C
- C++
- Common Lisp
- Delphi
- System.SysUtils
- F Sharp
- Factor
- Fōrmulæ
- FreeBASIC
- Frink
- Go
- Haskell
- J
- Java
- Julia
- Mathematica
- Wolfram Language
- Nim
- OCaml
- Pascal
- Perl
- Ntheory
- Phix
- PureBasic
- Python
- Quackery
- Racket
- Raku
- REXX
- Ruby
- Scala
- Sidef
- Swift
- Vlang
- Wren
- VBScript
- Zkl