diff --git a/Sieve-of-Eratosthenes.md b/Sieve-of-Eratosthenes.md new file mode 100644 index 0000000..e0c19f1 --- /dev/null +++ b/Sieve-of-Eratosthenes.md @@ -0,0 +1,45 @@ +Here is the well-known Sieve of Eratosthenes algorithm for finding prime numbers, written in EightBall: + + ' Sieve of Eratosthenes + + ' Globals + byte nr = 10 + word n = nr * nr + byte A[n] = 1 + + pr.msg "Sieve of Eratosthenes ..."; pr.nl + call doall() + end + + sub doall() + call sieve() + call printresults() + return 0 + + sub sieve() + word i = 0; word j = 0 + for i = 2 : (nr - 1) + if A[i] + j = i * i + while (j < n) + A[j] = 0 + j = j + i + endwhile + endif + endfor + return 0 + + sub printresults() + word i = 0 + for i = 2 : (n - 1) + if A[i] + if i > 2 + pr.msg ", " + endif + pr.dec i + endif + endfor + pr.msg "." + return 0 + + \ No newline at end of file