[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> MSWLOGO Prime numbers



Here is a solution for printing the prime numbers in MSWLOGO using filter:

Prime is the one line procedere doing the job of
printing a prime and erasing all the multiples.

To feed prime , you have to give a list of intergers,starting from 2 .

that's what integers is doing.

primes calls prime and feed prime with the result
of integers.

 

to integers :from :to
op ifelse :from > :to [[]][fput :from integers  :from + 1 :to ]
end

to prime :l 
if not emptyp :l ~
  [pr first :l prime filter [(remainder ? first :l ) > 0] :l ]
end

to primes  :n
prime integers 2 :n
end


Try: 
show integers   1 10
[1 2 3 4 5 6 7 8 9 10]

show integers   2 10
[2 3 4 5 6 7 8 9 10]

prime [ 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ]
2
3
5
7
11
13


primes 50
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47

Regards 

P-A Dreyfuss


 



Free web-based email, Forever, From anywhere!
http://www.mailexcite.com
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home