Skip to main content

PRIME OR NOT


## A funtion that takes a number
## in as an argument and returns
## the output p=1 if it is prime
## otherwise returns p=0.
function prime_or_not(num)
p=1; ## assume the number is prime.
div=2; ## the smallest divisor.
## since 2*num/2> num. Forbidden
Nsteps=num/2 ; ## Interval of division: the half
## of the num end itself
for i= div:Nsteps ## to divide al the numbers less than
## num/2.
if(rem(num,i)==0) ## any prime num cannot be
## divided with an integer.
p=0; ## otherwise exit the loop.
break;
endif
endfor
if(p == 1) ## prints the result
p=1
else
p=0
endif
endfunction

Comments

Popular posts from this blog

PHYSICS MACHINE

Physics Machine  Ümit Alkuş  Abstract Physics machine is a software which does physics like a physicist. First, all the things human being has developed so far, for doing physics, will be available to this machine. Secondly, all the consistent theories, successful experiments, and published articles will be included into this machine in the form of traced and readable knowledge, in other words, this machine can read and understand these all. Finally, as the last target, this machine can observe the universe and physical events with the aim of creating theories and physical laws.  METU, Physics Department, 06800, Ankara, Turkey   Keywords: Artificial Intelligence, Machine Learning, Data Mining, Artificial Physicist   Introduction There are approximately millions of articles over physics, huge collection of very successful theories, and physics books. In the earth, no physicist could have attempted to read and understand these accumulations since it re...