Try it out with your hand, where size = 5. To count from your pinky to your thumb and back is 8 … (5-1)*2. Do it again and you’re at 16, then 24, etc. Using %% to get the remainder avoids the time of walking the scanner back through all of these full periods. It only walks the final period of (x-1)*2 or fewer steps.

]]>Thanks

]]>I calculate the scanner’s position, but that’s not important. All that matters is whether the scanner’s position is 1, which can be determined by the period of the scanner’s oscillation and returned as a logical.

]]>I’d estimate it’s 1/10th the characters and 1/1000th the runtime. Humbling & inspiring.

]]>For my twitter bots (made in R), I define a cronjob and call the Rscript function.

Hope it helps.

Best,

Yannick ]]>