narenarya

python Vs Julia (Seive of Eratosthenes)

Mar 6th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #Python code  seive_n.py
  2. def seive_n(N):
  3.     s,is_divis = set(),False
  4.     for i in xrange(2,N+1):
  5.         arr = [i%j for j in s]
  6.         if 0 in arr:
  7.             is_divis = True
  8.         else:
  9.             is_divis = False
  10.         if not is_divis:
  11.             s.add(i)
  12.             is_divis = False
  13.  
  14.     return sorted(s)
  15.  
  16. print seive_n(100000)
  17.  
  18.  
  19. #Julia code sieve_n.jl
  20.  
  21.  
  22. function seive_E(n)
  23.   s,is_divisible = Set(),false
  24.       for i in [2:n]
  25.          arr = [i%j for j in s]
  26.          is_divisible = in(0,arr)?true:false
  27.          if !is_divisible
  28.             push!(s,i)
  29.             is_divisible = false
  30.          end
  31.       end
  32.   sort([i for i in s])
  33. end
  34.  
  35. println(seive_E(100000))
Advertisement
Add Comment
Please, Sign In to add comment