From 0aeac4012e6c7c4f42c722893137c5fe84c0048c Mon Sep 17 00:00:00 2001 From: halw Date: Thu, 4 Mar 2010 20:43:00 +0000 Subject: [PATCH] Added. Author:halw Date:2010-03-04T20:43:00.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@502 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../examples/example-sieve-eratosthenes.wiki | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 documentation/current/examples/example-sieve-eratosthenes.wiki diff --git a/documentation/current/examples/example-sieve-eratosthenes.wiki b/documentation/current/examples/example-sieve-eratosthenes.wiki new file mode 100644 index 00000000..ee2468df --- /dev/null +++ b/documentation/current/examples/example-sieve-eratosthenes.wiki @@ -0,0 +1,65 @@ +[[Property:title|Sieve of Eratosthenes]] +[[Property:link_title|Example: Sieve of Eratosthenes]] +[[Property:weight|0]] +[[Property:uuid|e825c874-4266-b5ee-501c-221e6940dacd]] +{{underconstruction}} + + +==Description== + +Deliver prime numbers up to a specified integer limit. Compute prime numbers using sieve of Eratosthenes. + + +==Source== + +[http://rosettacode.org/wiki/Seive_of_Eratosthenes Rosetta Code] + + +==Solution== + + +class + APPLICATION + +create + make + +feature + make + -- Run application. + do + across primes_through (100) as ic loop print (ic.item.out + " ") end + end + + primes_through (a_limit: INTEGER): LINKED_LIST [INTEGER] + -- Prime numbers through `a_limit' + require + valid_upper_limit: a_limit >= 2 + local + l_tab: ARRAY [BOOLEAN] + do + create Result.make + create l_tab.make (2, a_limit) + across + l_tab as ic + loop + if not ic.item then + Result.extend (ic.target_index) + across ((ic.target_index + ic.target_index) |..| l_tab.upper).new_cursor.with_step (ic.target_index) as id + loop + l_tab [id.item] := True + end + end + end + end +end + + + +==Output== + + +2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 + + +