Colorful numbers: Difference between revisions

Line 777:
"1.9s"
</pre>
 
=={{header|Picat}}==
<lang Picat>colorful_number(N) =>
N < 10 ;
(X = N.to_string,
X.len <= 8,
not membchk('0',X),
not membchk('1',X),
distinct(X),
[prod(S.map(to_int)) : S in findall(S,(append(_,S,_,X),S != [])) ].distinct).
 
distinct(L) =>
L.len == L.remove_dups.len.</lang>
 
'''All colorful numbers <= 100.'''
<lang Picat>main =>
Colorful = [N : N in 0..100, colorful_number(N)],
Len = Colorful.len,
foreach({C,I} in zip(Colorful,1..Len))
printf("%2d%s",C, cond(I mod 10 == 0, "\n"," "))
end,
nl,
println(len=Len)</lang>
 
{{out}}
<pre> 0 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
len = 66</pre>
 
'''Largest colorful number.'''
<lang Picat>main =>
N = 98765431,
Found = false,
while (Found == false)
if colorful_number(N) then
println(N),
Found := true
end,
N := N - 1
end.</lang>
 
{{out}}
<pre>98746253</pre>
 
'''Count of colorful numbers in each magnitude and of total colorful numbers.'''
<lang Picat>main =>
TotalC = 0,
foreach(I in 1..8)
C = 0,
printf("Digits %d: ", I),
foreach(N in lb(I)..ub(I))
if colorful_number(N) then
C := C + 1
end
end,
println(C),
TotalC := TotalC + C
end,
println(total=TotalC),
nl.
 
% Lower and upper bounds.
% For N=3: lb=123 and ub=987
lb(N) = cond(N < 2, 0, [I.to_string : I in 1..N].join('').to_int).
ub(N) = [I.to_string : I in 9..-1..9-N+1].join('').to_int.</lang>
 
{{out}}
<pre>Digits 1: 10
Digits 2: 56
Digits 3: 328
Digits 4: 1540
Digits 5: 5514
Digits 6: 13956
Digits 7: 21596
Digits 8: 14256
total = 57256</pre>
 
 
=={{header|Raku}}==
495

edits