POV-Ray : Newsgroups : povray.newusers : Prime numbers Server Time
26 Dec 2024 06:09:37 EST (-0500)
  Prime numbers (Message 1 to 5 of 5)  
From: Cabesa
Subject: Prime numbers
Date: 13 Jan 2022 15:35:00
Message: <web.61e08be8c47ffadf8f03b8bcfe998140@news.povray.org>
Now, this is quite a simple request- but I ve been unable to do so myself and
have no idea how to accomplish it.
Let me explain:

I have a ".txt" file, with a random number. The idea is to debug a message that
states whether said number is prime or not. Now,this should be quite an easy
task, but i dont seem to wrap my head around it and dont know witch "ifs" or
"whiles" to put so that the programme knows if the number meets with the
condition.

Thanks in advance (for those that read this far)


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Prime numbers
Date: 13 Jan 2022 16:45:00
Message: <web.61e09d2fb91bd52025bd47a389db30a9@news.povray.org>
"Cabesa" <adr### [at] gmailcom> wrote:
> Now, this is quite a simple request- but I ve been unable to do so myself and
> have no idea how to accomplish it.
> Let me explain:
>
> I have a ".txt" file, with a random number. The idea is to debug a message that
> states whether said number is prime or not. Now,this should be quite an easy
> task, but i dont seem to wrap my head around it and dont know witch "ifs" or
> "whiles" to put so that the programme knows if the number meets with the
> condition.
>
> Thanks in advance (for those that read this far)

Hi Cabesa

There are some "ifs" and "whiles" for you in the examples under "Simple
methods" on this page:

https://en.wikipedia.org/wiki/Primality_test

"i ** 2" and "n % (i + 2)" in Python can be written as "pow(i, 2)" and "mod(n, i
+ 2)" in POV-Ray's SDL.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Cabesa
Subject: Re: Prime numbers
Date: 13 Jan 2022 17:00:00
Message: <web.61e0a067b91bd5208f03b8bcfe998140@news.povray.org>
thanks, ill take a look


Post a reply to this message

From: kurtz le pirate
Subject: Re: Prime numbers
Date: 22 Jan 2022 13:25:21
Message: <61ec4c11$1@news.povray.org>
On 13/01/2022 21:30, Cabesa wrote:
> Now, this is quite a simple request- but I ve been unable to do so myself and
> have no idea how to accomplish it.
> Let me explain:
> 
> I have a ".txt" file, with a random number. The idea is to debug a message that
> states whether said number is prime or not. Now,this should be quite an easy
> task, but i dont seem to wrap my head around it and dont know witch "ifs" or
> "whiles" to put so that the programme knows if the number meets with the
> condition.
> 
> Thanks in advance (for those that read this far)
> 

It's not the best way to do it, but it's done in 5mn ... ;)


// -----------------------------------------------------------
// --- unitary test
// -----------------------------------------------------------
#declare num = 98452;
#declare cnt = 0;
#declare i=2;
#while(i<num)
 #if (mod(num,i)=0)
  #declare cnt=cnt+1;
 #end
 #declare i=i+1;
#end
#debug concat(str(num,0,0)," is ")
#if(cnt !=0 )
 #debug "not a prime number\n"
#else
 #debug "a prime number\n"
#end
#debug "\n\n------------\n\n"



// -----------------------------------------------------------
// --- find prime numbers between 0 and ...
// -----------------------------------------------------------
#declare num=0;
#while(num<50)
 #declare cnt = 0;
 #declare i=2;
 #while( i < num)
  #if (mod(num,i)=0)
   #declare cnt=cnt+1;
  #end
  #declare i=i+1;
 #end
 #if(cnt =0 )
  #debug concat("prime number ",str(num,0,0),"\n")
 #end
 #declare num=num+1;
#end
#debug "\n\n------------\n\n"




// -----------------------------------------------------------
// --- macro to test if a it is a prime numbers
// -----------------------------------------------------------
#macro IsPrime(n)
 #local cnt = 0;
 #local i=2;
 #while(i<n)
  #if(mod(n,i)=0)
   #declare cnt=cnt+1;
  #end
  #declare i=i+1;
 #end
 (cnt=0)
#end



// -----------------------------------------------------------
// --- test a number using the macro
// -----------------------------------------------------------
#declare a = 51286;
#debug concat("Is ",str(a,0,0)," a prime number ? ")
#if(IsPrime(a))
  #debug "yes\n"
#else
  #debug "no\n"
#end

#declare a = 51287;
#debug concat("Is ",str(a,0,0)," a prime number ? ")
#if(IsPrime(a))
  #debug "yes\n"
#else
  #debug "no\n"
#end

#declare a = 51288;
#debug concat("Is ",str(a,0,0)," a prime number ? ")
#if(IsPrime(a))
  #debug "yes\n"
#else
  #debug "no\n"
#end
#debug "\n\n------------\n\n"






-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Dick Balaska
Subject: Re: Prime numbers
Date: 28 Jan 2022 15:35:18
Message: <61f45386$1@news.povray.org>
On 1/22/2022 1:25 PM, kurtz le pirate wrote:

Once you've determined a number is not prime, you can skip testing.

> // -----------------------------------------------------------
> // --- macro to test if a it is a prime numbers
> // -----------------------------------------------------------
> #macro IsPrime(n)
>   #local cnt = 0;
>   #local i=2;
>   #while(i<n)
>    #if(mod(n,i)=0)
>     #declare cnt=cnt+1;
       #break
>    #end
>    #declare i=i+1;
>   #end
>   (cnt=0)
> #end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.