in reply to finding multiples of two values

I think JavaFan had it right but I didn't notice, since his reply didn't have code, till I wrote some. So…

while ( <DATA> ) { chomp; my ( $first, $second ) = split; print "$first:$second --> ", multiple($first,$second) ? "yes" : "no", "\n"; } sub multiple { my ( $one, $two ) = @_; ! ( $one > $two ? $one % $two : $two % $one ); } __DATA__ 1 2 2 3 3 9 9 3 11 7 2 108 4 4

Replies are listed 'Best First'.
Re^2: finding multiples of two values
by urnumdei (Initiate) on Sep 02, 2009 at 10:14 UTC
    Thanks guys. I finally got a chance to work on this.

    I just did the modulus route and it works. I had a somewhat of a basic clue of what to do, just needed an extra push.

    I agree though, I don't think a subroutine is necessary for this program. I need to look more into this modulus operator, it seems nifty. My first try resulted in a incorrect answer. It said that it was a multiple, even though the quotient was .5 (2 / 4), and when it said it wasn't a multiple when the quotient was 4 (48 / 12) I fixed it by flipping the operands. Just was an unexpected result. Something to research for sure.

    Anyways, thanks again guys.