DEV Community

Discussion on: Daily Challenge #64- Drying Potatoes

Collapse
 
choroba profile image
E. Choroba

Perl solution with tests.

#!/usr/bin/perl
use warnings;
use strict;

use Types::Standard qw( Int );
use Function::Parameters;

fun potatoes (Int $p0, Int $w0, Int $p1) {
    sprintf '%d', $w0 * (100 - $p0) / (100 - $p1)
}

use Test::More tests => 2;
is potatoes(99, 100, 98), 50;
is potatoes(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)