Colorful numbers: Difference between revisions

Added 11l
(Added 11l)
Line 33:
 
''Colorful numbers have no real number theory application. They are more a recreational math puzzle than a useful tool.''
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V largest = [0]
 
F iscolorful(n)
I n C 0.<10
R 1B
V dig = String(n).map(c -> Int(c))
I 1 C dig | 0 C dig | dig.len > Set(dig).len
R 0B
V products = Array(Set(dig))
L(i) 0 .< dig.len
L(j) i + 2 .. dig.len
V p = product(dig[i .< j])
I p C products
R 0B
products.append(p)
 
:largest[0] = max(n, :largest[0])
R 1B
 
print(‘Colorful numbers for 1:25, 26:50, 51:75, and 76:100:’)
L(i) (1.<101).step(25)
L(j) 25
I iscolorful(i + j)
print(f:‘{commatize(i + j): 5}’, end' ‘’)
print()
 
V csum = 0
L(i) 8
V j = I i == 0 {0} E 10 ^ i
V k = 10 ^ (i + 1) - 1
V n = sum((j .. k).map(x -> Int(iscolorful(x))))
csum += n
print(‘The count of colorful numbers between ’j‘ and ’k‘ is ’n‘.’)
 
print(‘The largest possible colorful number is ’largest[0]‘.’)
print(‘The total number of colorful numbers is ’csum‘.’)</syntaxhighlight>
 
{{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|C}}==
1,463

edits