Thue-Morse: Difference between revisions
→{{header|AppleScript}}
Line 72:
{{Trans|JavaScript}}
<lang AppleScript>--
-- thueMorse :: Int -> String
on thueMorse(nCycles)
script concatBinaryInverse
on
script binaryInverse
on
1 - x
end
end script
xs & map(binaryInverse, xs)
end
end script
intercalate("", ¬
foldl(concatBinaryInverse, [0],
end thueMorse
-- TEST ----------------------------------------------------------------------
on run
Line 102 ⟶ 104:
-- GENERIC LIBRARY FUNCTIONS
--
on
set
else▼
set lst to {}▼
end if▼
set end of lst to lambda(item i of xs, i, xs)▼
set lst to
repeat with i from
set end
end
return lst▼
end enumFromTo
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 120 ⟶ 124:
set lng to length of xs
repeat with i from 1 to lng
set v to
end repeat
return v
Line 134 ⟶ 138:
end intercalate
--
on
set
▲ set lst to {}
▲ else
▲ end if
▲ return lst
-- Lift 2nd class handler function into 1st class script wrapper
Line 155 ⟶ 157:
else
script
property
end script
end if
end mReturn</lang>
<pre>"0110100110010110100101100110100110010110011010010110100110010110"</pre>
|