Thue-Morse: Difference between revisions
→AppleScript :: Functional: Tidied.
(→{{header|AppleScript}}: Added an idiomatic solution.) |
(→AppleScript :: Functional: Tidied.) |
||
Line 119:
{{Trans|JavaScript}}
<lang AppleScript>
-- thueMorse :: Int -> String
Line 136:
intercalate("", ¬
foldl(concatBinaryInverse, [0],
enumFromTo(1, nCycles)))
end thueMorse
on run
Line 149 ⟶ 150:
------------------------- GENERIC ------------------------
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m
set
set end of lst to i▼
end repeat▼
else
end if
▲ repeat with i from m to n by d
▲ set end of lst to i
▲ end repeat
▲ return lst
end enumFromTo
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 176 ⟶ 177:
end tell
end foldl
-- intercalate :: Text -> [Text] -> Text
Line 184 ⟶ 186:
return strJoined
end intercalate
-- map :: (a -> b) -> [a] -> [b]
Line 196 ⟶ 199:
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
|