I've been wondering if the Sieve of Eratosthenes would be possible to program into Robotic...
I've been trying to, but I can't do it. But maybe someone else here can...?
First person to do it gets one million internets.
Page 1 of 1
Sieve of Eratosthenes
#2
Posted 30 October 2007 - 07:55 PM
: "sieve"
set "local1" to "LIMIT" (set this number yourself somewhere)
set "local2" to "sqrt&local1&"
goto "#genlist"
set "local3" to 2
: "L"
if "isprime&local3&" = 1 then "#sievelist"
inc "local3" by 1
if "local3" <= "local2" then "L"
goto "#printlist"
end
: "#genlist"
loop start
set "isprime&loopcount&" to 1
loop for "local1"
set "isprime0" to 0
set "isprime1" to 0
goto "#return"
: "#sievelist"
set "local4" to "('local3'*2)"
: "SL"
set "isprime&local4&" to 0
inc "local4" by "local3"
if "local4" <= "local1" then "SL"
goto "#return"
: "#printlist"
set "$list" to ""
loop start
if "isprime&loopcount&" = 0 then "PS"
inc "$list" by "&loopcount& "
: "PS"
loop for "local1"
set "local3" to 0
if "$list.length" <= 80 then "EN"
: "PL"
goto "#findspace"
write overlay c0f "&$list#('local4'+1)&" at 0 "local3"
set "$list" to "$list+('local4'+1)"
inc "local3" by 1
if "$list.length" > 80 then "PL"
: "EN"
write overlay c0f "&$list&" at 0 "local3"
goto "#return"
: "#findspace"
set "local4" to 79
: "F"
if "$list.&local4&" = 32 then "#return"
dec "local4" by 1
if "local4" > 0 then "F"
set "local4" to 79
goto "#return"Written without testing. So it may have typos, or bugs. But something like this should work.
EDIT: And there's one of them, in the string printing code.
EDIT 2: Added some more code to help print out the primes in a more readable form than the message row. This will dump them on the overlay and does some simple wrapping. Try a number like 10000, should take less than a second to run with commands set to 32767.
"Robotic is not a GCS!"
To lie is to change the truth.
..Ignorance is to be unaware of the truth.
....Incompetence is to be unable to grasp the truth.
......And escape is to run away from the truth.
It is useless to run, since the truth is right next to you.
-Wervyn
..Ignorance is to be unaware of the truth.
....Incompetence is to be unable to grasp the truth.
......And escape is to run away from the truth.
It is useless to run, since the truth is right next to you.
-Wervyn
#6
Posted 31 October 2007 - 12:30 PM
Ooh, ooh, now do sieve of atkin!
-RoSS
<img src="http://ross.box43.net/sig.php/sig.png" border="0" class="linked-sig-image" />
<img src="http://ross.box43.net/sig.php/sig.png" border="0" class="linked-sig-image" />
Share this topic:
Page 1 of 1

Help







