Baratski has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
Is there a better way, other than my following example, to find if a number is a multiple of a number?
My klunky way would be to keep subtracting x from y and look for a zero value. This seems like a long haul if I have to keep subtracting say, 4 from 123456789, or something like that.
$x = 4; $y = 123456789; while($y > 0) { $y -= $x; if($y == 0) { #..... } }
Is there a better way?
Thank you.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Find if a number is a multiple of a number.
by gellyfish (Monsignor) on Mar 02, 2005 at 12:36 UTC | |
Re: Find if a number is a multiple of a number.
by borisz (Canon) on Mar 02, 2005 at 12:41 UTC | |
by Baratski (Acolyte) on Mar 02, 2005 at 12:50 UTC | |
by blazar (Canon) on Mar 03, 2005 at 07:41 UTC | |
by borisz (Canon) on Mar 03, 2005 at 10:26 UTC | |
by blazar (Canon) on Mar 03, 2005 at 13:59 UTC | |
Re: Find if a number is a multiple of a number.
by Anonymous Monk on Mar 02, 2005 at 12:36 UTC | |
Re: Find if a number is a multiple of a number.
by g0n (Priest) on Mar 02, 2005 at 12:36 UTC | |
Re: Find if a number is a multiple of a number.
by ambrus (Abbot) on Mar 02, 2005 at 13:06 UTC |
Back to
Seekers of Perl Wisdom