primes/primes.e

62 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2011-03-08 08:01:27 +01:00
-- Eiffel version of a Prime Number Finder
-- haplo@mindstab.net
-- Anyone know how to round off doubles? or cast them to integers please
-- email me. I should be able to speed this up then.
class PRIMES
creation make
feature
make is
local
max, i, cnt, isprime : INTEGER;
test: DOUBLE;
stop : BOOLEAN;
do
if argument_count < 1 or else not argument(1).is_integer then
io.put_string("Useage: primese [Max Num]%N");
die_with_code(exit_failure_code);
else
max := argument(1).to_integer;
end;
from
cnt := 3;
until
cnt > max
loop
test := cnt.sqrt;
isprime := 1;
stop := false;
from
i := 3;
until
i > test or stop
loop
from
isprime := cnt;
until
isprime < i
loop
isprime := isprime-i;
end;
--isprime := cnt - (i* do_round_down(cnt/i));
if isprime = 0 then
stop := true
end;
i := i + 2;
end;
if isprime /= 0 then
io.put_integer(cnt);
io.put_string("%N");
end;
cnt := cnt + 2;
end;
end;
end