Colorful numbers: Difference between revisions
m
→{{header|AppleScript}}: Tidied Phix-derived version.
(→{{header|AppleScript}}: Added an alternative using a translation from the Phix solution.) |
m (→{{header|AppleScript}}: Tidied Phix-derived version.) |
||
Line 344:
on task()
set colorfuls to {}
repeat
if (isColorful(n)) then set end of colorfuls to
end repeat
set counts to {0, 0, 0, 0, 0, 0, 0, 0}▼
property used : {false, false, false, false, false, false, false, false, false, false}
property largest : 0
on count_colourful(taken, x, n)
if (isColorful(n))
set dx to digit + 1
count_colourful(
end repeat
▲ set ln to 1
▲ repeat until ((10 ^ ln) > n)
▲ set ln to ln + 1
▲ end repeat
▲ set counts's item ln to (counts's item ln) + 1
▲ if (n > largest) then set largest to n
▲ end if
▲ if (taken < 9) then
▲ repeat with digit from 2 to 9
if (not used's item dx) then▼
end repeat▼
end if
end count_colourful
end script
repeat with digit from 0 to 9
cc's count_colourful(((digit < 2) as integer) * 8 + 1, digit + 1, digit)
set output to {"The colorful numbers below 100:"}
Line 390 ⟶ 382:
set end of output to join(colorfuls's items i thru (i + 10), "")
end repeat
set end of output to linefeed & "The largest colorful number is " & cc's largest
set counter to cc's counts's beginning
set end of output to linefeed & "The number of them with 1 digit is " & counter
repeat with i from 2 to (count cc's counts)
set end of output to "The number with " & i & " digits is " & (cc's counts's item i)
set counter to counter + (cc's counts's item i)
end repeat
set end of output to "The total number overall is " & counter
|