John bought potatoes: their weight is 100 kilograms. Potatoes contain water and dry matter.
The water content is 99 percent of the total weight. H...
For further actions, you may consider blocking this person and/or reporting abuse
Oh come on, that's not coding :v
All this talk of potatoes makes me want to Go get some french fries.
I added some error checking for a few cases that made sense to me, such as:
I also changed the inputs and outputs to specifically be unsigned integers, since it seems like negative numbers were not meant to be used here and this avoids having to do error checking for things like:
Want to see my solutions to the other challenges? Go check them out on my Github! github.com/Dak425/dev-to-challenges
potato.go
potato_test.go
Perl solution with tests.
How did I get the formula?
Let's say
d
is the dry matter weight. We know thattherefore,
Good ol' python one-liner* 😊
def potatoes(p0, w0, p1): return w0*(100-p0)/(100-p1)
*math sold separately
I didn't know that we can define a function and return it in the same line ...
That's crazy
Haskell:
let potatoes = (p0, w0, p1) => parseInt(w0 * (100 - p0) / (100 - p1))
console.log(potatoes(99, 100, 98));
console.log(potatoes(50, 200, 25));
in C#
mind : blown 🤯