From 9efaf6516bae30ba5dd55474211beb6d6c6d8c1f Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Mon, 27 Nov 2017 19:47:25 -0500 Subject: [PATCH] Created Sieve of Eratosthenes (markdown) --- Sieve-of-Eratosthenes.md | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Sieve-of-Eratosthenes.md 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