#!/usr/bin/perlusewarnings;usestrict;useTypes::Standardqw( Int );useFunction::Parameters;funpotatoes(Int$p0,Int$w0,Int$p1){sprintf'%d',$w0*(100-$p0)/(100-$p1)}useTest::Moretests=>2;ispotatoes(99,100,98),50;ispotatoes(50,200,25),133;
How did I get the formula?
Let's say d is the dry matter weight. We know that
dm = w0 * (1 - p0)
dm = w1 * (1 - p1)
therefore,
w1 = w0 * (1 - p0) / (1 - p1)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perl solution with tests.
How did I get the formula?
Let's say
d
is the dry matter weight. We know thattherefore,