in reply to Simple arithmetic?

Using bog standard LCM:

my @T = ( [2147483648, 12, 4096], [3221225472, 5007, 4096], [4096, 4096, 4096], [8192, 8192, 4096], [15000, 8192, 4096], [17000, 8192, 4096], [17000, 10, 4096], ); sub gcd { !$_[1] ? $_[0] : gcd($_[1], $_[0] % $_[1]) } sub lcm { $_[0] * $_[1] / gcd($_[0], $_[1]) } for (@T) { my ($S, $R, $P) = @$_; my $N = $S - $S % lcm($R, $P); print "@$_: $N\n"; }

Replies are listed 'Best First'.
Re^2: Simple arithmetic?
by BrowserUk (Patriarch) on Mar 08, 2015 at 12:29 UTC
    Using bog standard LCM

    That's a very clean, and totally generic implementation. Thank you.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked