Advertisement
zvoulgaris

Removal of Multiples

Apr 27th, 2021
1,365
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Removal of Multiples drill from Programming Praxis
  2.  
  3. function main(s::Array{Int64, 1}, N::Int64)
  4.     ind = trues(N)
  5.  
  6.     for x in s # iterate over all elements of s
  7.         if ind[x] # x isn't a multiple of the previous elements of s
  8.             for i = x:x:N
  9.                 ind[i] = false
  10.             end
  11.         end
  12.     end
  13.  
  14.     return (1:N)[ind]
  15. end
  16.  
Advertisement
RAW Paste Data Copied
Advertisement