Colorful numbers: Difference between revisions
Content added Content deleted
m (Mention another instance of an incorrect value.) |
|||
Line 900: | Line 900: | ||
total = 57256</pre> |
total = 57256</pre> |
||
=={{header|Python}}== |
|||
<lang python>largest = [0] |
|||
def iscolorful(n): |
|||
if 0 <= n < 10: |
|||
return True |
|||
dig = [int(c) for c in str(n)] |
|||
if 1 in dig or 0 in dig or len(dig) > len(set(dig)): |
|||
return False |
|||
products = list(set(dig)) |
|||
for i in range(len(dig)): |
|||
for j in range(i+1, len(dig)): |
|||
p = prod(dig[i:j+1]) |
|||
if p in products: |
|||
return False |
|||
products.append(p) |
|||
largest[0] = max(n, largest[0]) |
|||
return True |
|||
print('Colorful numbers for 1:25, 26:50, 51:75, and 76:100:') |
|||
for i in range(1, 101, 25): |
|||
for j in range(25): |
|||
if iscolorful(i + j): |
|||
print(f'{i + j: 5,}', end='') |
|||
print() |
|||
csum = 0 |
|||
for i in range(8): |
|||
j = 0 if i == 0 else 10**i |
|||
k = 10**(i+1) - 1 |
|||
n = sum(iscolorful(x) for x in range(j, k+1)) |
|||
csum += n |
|||
print(f'The count of colorful numbers between {j} and {k} is {n}.') |
|||
print(f'The largest possible colorful number is {largest[0]}.') |
|||
print(f'The total number of colorful numbers is {csum}.') |
|||
</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. |
|||
The count of colorful numbers between 100 and 999 is 328. |
|||
The count of colorful numbers between 1000 and 9999 is 1540. |
|||
The count of colorful numbers between 10000 and 99999 is 5514. |
|||
The count of colorful numbers between 100000 and 999999 is 13956. |
|||
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> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |