Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,89 @@
|
|||
(*
|
||||
This observes the task requirement that colorful numbers be identified using a test handler,
|
||||
but uses the information regarding 1s and 0s and some logic to skip obvious non-starters
|
||||
and save a few minutes' running time. Since multiplication is commutative, every number's
|
||||
"colorful" status is the same as its reverse's. Working up from 0, the lower number of each
|
||||
mirrored colorful pair is met first and its reverse derived. If the largest reversed number
|
||||
obtained so far is actually reached, it's the last colorful number at that magnitude. The
|
||||
search either end there or jumps to the lowest number worth trying at the next level.
|
||||
*)
|
||||
on isColorful(n)
|
||||
if ((n > 98765432) or (n < 0) or (n mod 1 > 0)) then return false
|
||||
set products to {n mod 10}
|
||||
repeat while (n > 9)
|
||||
set n to n div 10
|
||||
set digit to n mod 10
|
||||
if ((digit < 2) or (digit is in products)) then return false
|
||||
set end of products to digit
|
||||
end repeat
|
||||
set nDigits to (count products)
|
||||
repeat with i from 1 to (nDigits - 1)
|
||||
set prod to products's item i
|
||||
repeat with j from (i + 1) to nDigits
|
||||
set prod to prod * (products's item j)
|
||||
if (prod is in products) then return false
|
||||
set end of products to prod
|
||||
end repeat
|
||||
end repeat
|
||||
|
||||
return true
|
||||
end isColorful
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on task()
|
||||
set colorfuls to {}
|
||||
set counter to 0
|
||||
set counts to {}
|
||||
set magnitude to 1 -- 10 ^ (number of digits - 1).
|
||||
set largestReverse to 9 -- Largest reverse of a single-digit number!
|
||||
set n to 0
|
||||
repeat
|
||||
if (isColorful(n)) then
|
||||
if (n < 100) then set end of colorfuls to text -3 thru -1 of (" " & n)
|
||||
set counter to counter + 1
|
||||
if (n = largestReverse) then
|
||||
set end of counts to counter
|
||||
set counter to 0
|
||||
set magnitude to magnitude * 10
|
||||
if (magnitude > 98765432) then exit repeat
|
||||
set n to 2.3456789 * magnitude div 1 - 1
|
||||
else
|
||||
set temp to n
|
||||
set |reverse| to temp mod 10
|
||||
repeat while (temp > 9)
|
||||
set temp to temp div 10
|
||||
set |reverse| to |reverse| * 10 + temp mod 10
|
||||
end repeat
|
||||
if (|reverse| > largestReverse) then set largestReverse to |reverse|
|
||||
end if
|
||||
end if
|
||||
if (n mod 10 = 9) then
|
||||
set n to n + 3
|
||||
else
|
||||
set n to n + 1
|
||||
end if
|
||||
end repeat
|
||||
|
||||
set output to {"The colorful numbers below 100:"}
|
||||
repeat with i from 1 to 66 by 11
|
||||
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 " & largestReverse
|
||||
set counter to 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 counts)
|
||||
set end of output to "The number with " & i & " digits is " & (counts's item i)
|
||||
set counter to counter + (counts's item i)
|
||||
end repeat
|
||||
set end of output to "The total number overall is " & counter
|
||||
return join(output, linefeed)
|
||||
end task
|
||||
|
||||
task()
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
"The colorful numbers below 100:
|
||||
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
|
||||
|
||||
The largest colorful number is 98746253
|
||||
|
||||
The number of them with 1 digit is 10
|
||||
The number with 2 digits is 56
|
||||
The number with 3 digits is 328
|
||||
The number with 4 digits is 1540
|
||||
The number with 5 digits is 5514
|
||||
The number with 6 digits is 13956
|
||||
The number with 7 digits is 21596
|
||||
The number with 8 digits is 14256
|
||||
The total number overall is 57256"
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
on isColorful(n)
|
||||
if ((n > 98765432) or (n < 0) or (n mod 1 > 0)) then return false
|
||||
set products to {n mod 10}
|
||||
repeat while (n > 9)
|
||||
set n to n div 10
|
||||
set digit to n mod 10
|
||||
if ((digit < 2) or (digit is in products)) then return false
|
||||
set end of products to digit
|
||||
end repeat
|
||||
set nDigits to (count products)
|
||||
repeat with i from 1 to (nDigits - 1)
|
||||
set prod to products's item i
|
||||
repeat with j from (i + 1) to nDigits
|
||||
set prod to prod * (products's item j)
|
||||
if (prod is in products) then return false
|
||||
set end of products to prod
|
||||
end repeat
|
||||
end repeat
|
||||
|
||||
return true
|
||||
end isColorful
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on task()
|
||||
set colorfuls to {}
|
||||
repeat with n from 0 to 100
|
||||
if (isColorful(n)) then set end of colorfuls to (" " & n)'s text -3 thru -1
|
||||
end repeat
|
||||
|
||||
script cc
|
||||
property used : {false, false, false, false, false, false, false, false, false, false}
|
||||
property counts : {0, 0, 0, 0, 0, 0, 0, 0}
|
||||
property largest : 0
|
||||
|
||||
on count_colourful(taken, x, n)
|
||||
set used's item x to true
|
||||
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 > 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
|
||||
count_colourful(taken + 1, dx, n * 10 + digit)
|
||||
end if
|
||||
end repeat
|
||||
end if
|
||||
set used's item x to false
|
||||
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)
|
||||
end repeat
|
||||
|
||||
set output to {"The colorful numbers below 100:"}
|
||||
repeat with i from 1 to 66 by 11
|
||||
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
|
||||
return join(output, linefeed)
|
||||
end task
|
||||
|
||||
task()
|
||||
Loading…
Add table
Add a link
Reference in a new issue