Colorful numbers: Difference between revisions

Content added Content deleted
(Added Java solution)
(→‎{{header|Julia}}: Now complete.)
Line 382: Line 382:


=={{header|Julia}}==
=={{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)
function iscolorful(n, base=10)
0 <= n < 10 && return true
0 <= n < 10 && return true
dig = digits(n, base=base)
dig = digits(n, base=base)
Line 392: Line 393:
p in products && return false
p in products && return false
push!(products, p)
push!(products, p)
end
if n > largest
global largest = n
end
end
return true
return true
end
end

function testcolorfuls()
function testcolorfuls()
println("Colorful numbers for 1:25, 26:50, 51:75, and 76:100:")
println("Colorful numbers for 1:25, 26:50, 51:75, and 76:100:")
Line 409: Line 413:
println("The count of colorful numbers between $j and $k is $n.")
println("The count of colorful numbers between $j and $k is $n.")
end
end
println("The largest possible colorful number is $largest.")
println("The total number of colorful numbers is $csum.")
println("The total number of colorful numbers is $csum.")
end
end

testcolorfuls()
testcolorfuls()
</lang>{{out}}
</lang>{{out}}
<pre>
<pre>
Colorful numbers for 1:25, 26:50, 51:75, and 76:100:
Colorful numbers for 1:25, 26:50, 51:75, and 76:100:
1 2 3 4 5 6 7 8 9 23 24 25
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
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
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
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 0 and 9 is 10.
The count of colorful numbers between 10 and 99 is 56.
The count of colorful numbers between 10 and 99 is 56.
Line 428: Line 433:
The count of colorful numbers between 1000000 and 9999999 is 21596.
The count of colorful numbers between 1000000 and 9999999 is 21596.
The count of colorful numbers between 10000000 and 99999999 is 14256.
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.
The total number of colorful numbers is 57256.
</pre>
</pre>