Jordan-Pólya numbers: Difference between revisions

m
→‎{{header|Julia}}: add documentation
m (→‎{{header|Julia}}: formatting)
m (→‎{{header|Julia}}: add documentation)
Line 165:
=={{header|Julia}}==
<syntaxhighlight lang="julia">""" The aupto() function is taken from the Python code at oeis.org/A001013 """
 
function aupto(lim::T, mx::T = zero(T)) where T <: Integer
lim < 2 && return [one(T)]
Line 180 ⟶ 179:
const factorials = map(factorial, 2:18)
 
""" Factor a J-P number into a smallest vector of factorials and their powers """
function factor_as_factorials(n::T) where T <: Integer
fac_exp = Tuple{Int, Int}[]
Line 202:
const superchars = ["\u2070", "\u00b9", "\u00b2", "\u00b3", "\u2074",
"\u2075", "\u2076", "\u2077", "\u2078", "\u2079"]
""" Express a positive integer as Unicode superscript digit characters """
super(n::Integer) = prod([superchars[i + 1] for i in reverse(digits(n))])
 
arr = aupto(2^53)
Line 214 ⟶ 215:
print("\nThe $(n)th Jordan-Pólya number is: $(arr[n])\n= ")
println(join(map(t -> "$(t[1])!$(t[2] > 1 ? super(t[2]) : "")",
factor_as_factorials(arr[n])), " x "))end
end
</syntaxhighlight>{{out}}
<pre>
4,105

edits