Colorful numbers: Difference between revisions

→‎{{header|Julia}}: Now complete.
(Added Java solution)
(→‎{{header|Julia}}: Now complete.)
Line 382:
 
=={{header|Julia}}==
<lang julia>largest = 0
{{incomplete|Julia|Missing third part of task - Find largest possible colorful number.<br>}}
 
<lang julia>function iscolorful(n, base=10)
0 <= n < 10 && return true
dig = digits(n, base=base)
Line 392 ⟶ 393:
p in products && return false
push!(products, p)
end
if n > largest
global largest = n
end
return true
end
 
function testcolorfuls()
println("Colorful numbers for 1:25, 26:50, 51:75, and 76:100:")
Line 409 ⟶ 413:
println("The count of colorful numbers between $j and $k is $n.")
end
println("The largest possible colorful number is $largest.")
println("The total number of colorful numbers is $csum.")
end
 
testcolorfuls()
</lang>{{out}}
<pre>
Colorful numbers for 1:25, 26:50, 51:75, and 76:100:
1 2 3 4 5 6 7 8 9 23 24 25
26 27 28 29 32 34 35 36 37 38 39 42 43 45 46 47 48 49
52 53 54 56 57 58 59 62 63 64 65 67 68 69 72 73 74 75
76 78 79 82 83 84 85 86 87 89 92 93 94 95 96 97 98
The count of colorful numbers between 0 and 9 is 10.
The count of colorful numbers between 10 and 99 is 56.
Line 428 ⟶ 433:
The count of colorful numbers between 1000000 and 9999999 is 21596.
The count of colorful numbers between 10000000 and 99999999 is 14256.
The largest possible colorful number is 98746253.
The total number of colorful numbers is 57256.
</pre>
9,476

edits