Klarner-Rado sequence: Difference between revisions
m
→{{header|AppleScript}}: Minor improvements to the recursive version.
(Created Nim solution.) |
m (→{{header|AppleScript}}: Minor improvements to the recursive version.) |
||
Line 138:
=={{header|AppleScript}}==
One way to test numbers for membership of the sequence is to feed them to a recursive handler which determines whether or not there's a Klarner-Rado route from them down to
<syntaxhighlight lang="applescript">-- Is n in the Klarner-Rado sequence?
-- Fully recursive:
(*
set n to n - 1▼
return ((n =
end isKlarnerRado
*)
--
-- Interestingly, leaving out the 'else's and comparing n mod 2 directly with 0 slows it down!
on isKlarnerRado(n)
set n to n - 1▼
repeat
if ((n =
return true
else if (n mod 2
return false
end if
end repeat
|