You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to respectfully suggest an answer for question 70. But there are always better ways, even if this may work, and I'd be grateful for such thoughts.
%assign limit 15 ; limit can be no higher than 63 with this code
%assign primestring 0 ; bit-string holding our primes 1=prime; 0=composite
%assign n 3
%rep limit
%assign primeflag 1 ; 1 = n is prime; 0 = n is composite
%assign i 1
%rep n/2
%assign i i+1
%if n % i = 0
%assign primeflag 0
%exitrep
%endif
%endrep
%assign primestring primestring | (primeflag << n)
%assign n n+1
%endrep
dq primestring
%define isprime(n) (primestring >> n) & 1
; test the function with some outputs
db 15, isprime(15) ; expect 0
db 17, isprime(17) ; expect 1
I would like to respectfully suggest an answer for question 70. But there are always better ways, even if this may work, and I'd be grateful for such thoughts.
produces
The text was updated successfully, but these errors were encountered: