Repeat a string: Difference between revisions
Content added Content deleted
(→{{header|JavaScript}}: Updated primitives) |
(→{{header|AppleScript}}: Updated primitives) |
||
Line 98: | Line 98: | ||
{{trans|JavaScript}} |
{{trans|JavaScript}} |
||
<lang AppleScript> |
<lang AppleScript>replicate(5000, "ha") |
||
nreps("ha", 50000) |
|||
end run |
|||
-- Repetition by 'Egyptian multiplication' - |
|||
-- progressively doubling a list, appending |
|||
-- stages of doubling to an accumulator where needed for |
|||
-- binary assembly of a target length. |
|||
-- |
-- replicate :: Int -> String -> String |
||
on |
on replicate(n, s) |
||
set |
set out to "" |
||
if n < 1 then return |
if n < 1 then return out |
||
set dbl to s |
|||
repeat while (n > 1) |
repeat while (n > 1) |
||
if (n mod 2) > 0 then set |
if (n mod 2) > 0 then set out to out & dbl |
||
set n to (n div 2) |
set n to (n div 2) |
||
set |
set dbl to (dbl & dbl) |
||
end repeat |
end repeat |
||
return |
return out & dbl |
||
end replicate</lang> |
|||
end nreps |
|||
</lang> |
|||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |