POV-Ray : Newsgroups : povray.text.scene-files : greatest common divisor Server Time
28 Mar 2024 07:37:15 EDT (-0400)
  greatest common divisor (Message 1 to 5 of 5)  
From: jr
Subject: greatest common divisor
Date: 13 Jan 2022 11:35:00
Message: <web.61e053bc97dcb06aea8869266cde94f1@news.povray.org>
hi,

posting my (naive) implementation of the "Euclidean"[*] method to calculate the
gcd, in case it'll be of use to others.  googling for "gcd" (and spelled out) on
the news.povray site, surprising to me, got zero results.

[*] <https://en.wikipedia.org/wiki/Greatest_common_divisor#Euclidean_algorithm>


regards, jr.


Post a reply to this message


Attachments:
Download 'gcd.pov.txt' (1 KB)

From: Dave Blandston
Subject: Re: greatest common divisor
Date: 13 Jan 2022 17:15:00
Message: <web.61e0a409f2cd35a62636f1af607c1b34@news.povray.org>
Hey, that's a really interesting algorithm! I'm inspired to learn how that
works. Thanks!

Kind regards,
Dave Blandston


Post a reply to this message

From: jr
Subject: Re: greatest common divisor
Date: 14 Jan 2022 12:35:00
Message: <web.61e1b3ccf2cd35a6ea8869266cde94f1@news.povray.org>
hi,

"Dave Blandston" <IsN### [at] protonmailch> wrote:
> Hey, that's a really interesting algorithm! I'm inspired to learn how that
> works. Thanks!

heh, better you than me!  :-)  I can follow how it works, and given sufficient
time I might even have thought of subtracting all multiples of B from A, but
then to swap B + A, never, I simply lack understanding of even the basic
"properties" of numbers.  hope your brain can take the "edutainment" ;-).


regards, jr.


Post a reply to this message

From: kurtz le pirate
Subject: Re: greatest common divisor
Date: 22 Jan 2022 11:51:20
Message: <61ec3608$1@news.povray.org>
On 13/01/2022 17:30, jr wrote:
> hi,
> 
> posting my (naive) implementation of the "Euclidean"[*] method to calculate the
> gcd, in case it'll be of use to others.  googling for "gcd" (and spelled out) on
> the news.povray site, surprising to me, got zero results

To make it easier to use, you can also make :
(do not pay attention to the order of parameters)

#macro m_gcd(a_,b_)
  #local ta_ = max(a_,b_);
  #local tb_ = min(a_,b_);
  #while (tb_)
  ...



;)

-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: jr
Subject: Re: greatest common divisor
Date: 23 Jan 2022 03:50:00
Message: <web.61ed15fdf2cd35a6ea8869266cde94f1@news.povray.org>
hi,

kurtz le pirate <kur### [at] gmailcom> wrote:
> To make it easier to use, you can also make :
> (do not pay attention to the order of parameters)
>
> #macro m_gcd(a_,b_)
>   #local ta_ = max(a_,b_);
>   #local tb_ = min(a_,b_);
>   #while (tb_)
>   ...

neat.  although the condition is not the same, accepting A = B makes no
(practical) difference, afaict.  thanks.


regards, jr.


Post a reply to this message

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