Thue-Morse: Difference between revisions

→‎{{header|AppleScript}}: Added an idiomatic solution.
(Added Wren)
(→‎{{header|AppleScript}}: Added an idiomatic solution.)
Line 115:
 
=={{header|AppleScript}}==
===Functional===
 
{{Trans|JavaScript}}
Line 208 ⟶ 209:
end mReturn</lang>
<pre>"0110100110010110100101100110100110010110011010010110100110010110"</pre>
----
 
===Idiomatic===
 
Implements the "flip previous cycles" method, stopping at a specified sequence length.
 
<lang applescript>on ThueMorse(sequenceLength)
if (sequenceLength < 1) then return ""
script o
property sequence : {0}
end script
set counter to 1
set cycleEnd to 1
set i to 1
repeat until (counter = sequenceLength)
set end of o's sequence to ((item i of o's sequence) + 1) mod 2
set counter to counter + 1
if (i < cycleEnd) then
set i to i + 1
else
set i to 1
set cycleEnd to counter
end if
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set sequence to o's sequence as text
set AppleScript's text item delimiters to astid
return sequence
end ThueMorse
 
return linefeed & ThueMorse(64) & (linefeed & ThueMorse(65))</lang>
 
{{output}}
<lang applescript>"
0110100110010110100101100110100110010110011010010110100110010110
01101001100101101001011001101001100101100110100101101001100101101"</lang>
 
=={{header|AWK}}==
557

edits