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 100with timesn from 0 to 100
if (isColorful(n)) then set end of colorfuls to missing(" " & n)'s text -3 thru value-1
end repeat
set counts to {0, 0, 0, 0, 0, 0, 0, 0}
setscript largest to 0cc
script o
property used : {false, false, false, false, false, false, false, false, false, false}
set property counts to: {0, 0, 0, 0, 0, 0, 0, 0}
property largest : 0
on count_colourful(taken, x, n)
ifset (takenused's =item 0)x thento true
if (isColorful(n)) repeat with digit from 0 to 9then
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
set dx to digit + 1
setif (not used's item dx) to truethen
count_colourful((9taken -+ digit)1, divdx, 8n * 810 + 1, digit)
setend used's item dx to falseif
end repeat
else
if (isColorful(n)) then
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 < 100) then set colorfuls's item (n + 1) to (" " & n)'s text -3 thru -1
if (n > largest) then set largest to n
end if
if (taken < 9) then
repeat with digit from 2 to 9
set dx to digit + 1
if (not used's item dx) then
set used's item dx to true
count_colourful(taken + 1, n * 10 + digit)
set used's item dx to false
end if
end repeat
end if
end if
if (notset used's item dx)x to thenfalse
end count_colourful
end script
repeat with digit from 0 to 9
o's count_colourful(0, 0)
cc's count_colourful(((digit < 2) as integer) * 8 + 1, digit + 1, digit)
set colorfuls to colorfuls's every text
end repeat
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
557

edits