Jump to content

Thue-Morse: Difference between revisions

(→‎{{header|AppleScript}}: Added an idiomatic solution.)
Line 119:
{{Trans|JavaScript}}
 
<lang AppleScript>-- THUE MORSE ------------------------------------------ THUE MORSE ----------------------
 
-- thueMorse :: Int -> String
Line 136:
intercalate("", ¬
foldl(concatBinaryInverse, [0], enumFromTo(1, nCycles)))¬
enumFromTo(1, nCycles)))
end thueMorse
 
 
-- TEST --------------------------------------------- TEST -------------------------
on run
Line 149 ⟶ 150:
 
 
------------------------- GENERIC ------------------------
-- GENERIC LIBRARY FUNCTIONS
 
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m > n then
set dlst to -1{}
repeat with i from m to n by d
set end of lst to i
end repeat
return lst
else
set d to 1{}
end if
set lst to {}
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
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.