Magic numbers: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Added libheader)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by one other user not shown)
Line 527:
All magic numbers that are pan-digital in 0 through 9 with no repeats:
3816547290
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">function findmagics(maxdig = 26)
magics = [Int128[] for _ in 1:maxdig-1]
pushfirst!(magics, collect(one(Int128):9))
for n in 2:maxdig, i in magics[n - 1], j in 0:9
k = 10i + j
k % n == 0 && push!(magics[n], k)
end
pushfirst!(first(magics), 0) # zero is a one-digit magic number?
return magics
end
 
const magics = findmagics()
 
for (n, arr) in enumerate(magics)
println("There are $(length(arr)) magic numbers with $n digits",
isempty(arr) ? "." : " with the largest $(last(arr)).")
end
println("\nIn all, there are $(sum(map(length, magics))) magic numbers.\n")
 
println("Magic number(s) pan-digital in 1 through 9 with no repeats: ",
join(filter(n -> (d = digits(n); all(i -> count(==(i), d) == 1, 1:9)), magics[9])))
println("Magic number(s) pan-digital in 0 through 9 with no repeats: ",
join(filter(n -> (d = digits(n); all(i -> count(==(i), d) == 1, 0:9)), magics[10])))
 
</syntaxhighlight>{{out}}
<pre>
There are 10 magic numbers with 1 digits with the largest 9.
There are 45 magic numbers with 2 digits with the largest 98.
There are 150 magic numbers with 3 digits with the largest 987.
There are 375 magic numbers with 4 digits with the largest 9876.
There are 750 magic numbers with 5 digits with the largest 98765.
There are 1200 magic numbers with 6 digits with the largest 987654.
There are 1713 magic numbers with 7 digits with the largest 9876545.
There are 2227 magic numbers with 8 digits with the largest 98765456.
There are 2492 magic numbers with 9 digits with the largest 987654564.
There are 2492 magic numbers with 10 digits with the largest 9876545640.
There are 2225 magic numbers with 11 digits with the largest 98765456405.
There are 2041 magic numbers with 12 digits with the largest 987606963096.
There are 1575 magic numbers with 13 digits with the largest 9876069630960.
There are 1132 magic numbers with 14 digits with the largest 98760696309604.
There are 770 magic numbers with 15 digits with the largest 987606963096045.
There are 571 magic numbers with 16 digits with the largest 9876062430364208.
There are 335 magic numbers with 17 digits with the largest 98485872309636009.
There are 180 magic numbers with 18 digits with the largest 984450645096105672.
There are 90 magic numbers with 19 digits with the largest 9812523240364656789.
There are 44 magic numbers with 20 digits with the largest 96685896604836004260.
There are 18 magic numbers with 21 digits with the largest 966858966048360042609.
There are 12 magic numbers with 22 digits with the largest 9668589660483600426096.
There are 6 magic numbers with 23 digits with the largest 72645656402410567240820.
There are 3 magic numbers with 24 digits with the largest 402852168072900828009216.
There are 1 magic numbers with 25 digits with the largest 3608528850368400786036725.
There are 0 magic numbers with 26 digits.
 
In all, there are 20457 magic numbers.
 
Magic number(s) pan-digital in 1 through 9 with no repeats: 381654729
Magic number(s) pan-digital in 0 through 9 with no repeats: 3816547290
</pre>
 
Line 1,133 ⟶ 1,193:
{{libheader|Wren-fmt}}
This is based on the Python code in the Wikipedia article.
<syntaxhighlight lang="ecmascriptwren">import "./big" for BigInt
import "./fmt" for Fmt
 
9,476

edits