Two identical strings: Difference between revisions
m
→{{header|AppleScript}}: →Idiomatic: Minor optimisation.
(→{{header|AppleScript}}: Added an idiomatic solution.) |
m (→{{header|AppleScript}}: →Idiomatic: Minor optimisation.) |
||
Line 786:
----
===Idiomatic===
<lang applescript><lang applescript>on task(maxN)
set startWith0 to false -- Change to true to start with 0 and "00".
set rhv to -(startWith0 as integer) -- Start value of "right hand" string.
script o
property bits : {
property output : {}
end script
Line 795 ⟶ 797:
set AppleScript's text item delimiters to ""
repeat
-- Add 1 to the binary-digit list's LSD and perform any carries.
set carry to 1
repeat with i from (count o's bits) to 1 by -1
Line 804 ⟶ 806:
end repeat
if (carry = 1) then set beginning of o's bits to carry
--
set
set n to rhv * (2 ^ (count o's bits)) div 1 + rhv
-- Unless n exceeds
if (n > maxN) then exit repeat
set end of o's output to (n as text) & ": " & o's bits & o's bits
|