Python3: Drying Potatoes

Introduction

This Kata was a real headache. It took me almost 2 hours even when it was relatively easy (from developer view). The main issue was come up with the equation to solve the issue. Lastly, when I worked with mathematics it was on high school, more than 10 years ago.

But luckily, with a lot of tries and refreshing memories, I was able to come up with a solution.

Instructions

All we eat is water and dry matter.

John bought potatoes: their weight is 100 kilograms. Potatoes contain water and dry matter.

The water content is 99 percent of the total weight. He thinks they are too wet and puts them in an oven – at low temperature – for them to lose some water.

At the output the water content is only 98%.

What is the total weight in kilograms (water content plus dry matter) coming out of the oven?

He finds 50 kilograms and he thinks he made a mistake: “So much weight lost for such a small change in water content!”

Can you help him?

Write function potatoes with

  • int parameter p0 – initial percent of water
  • int parameter w0 – initial weight
  • int parameter p1 – final percent of water

potatoesshould return the final weight coming out of the oven w1 truncated as an int.

Example:

potatoes(99, 100, 98) --> 50

My Solution

def potatoes(p0, w0, p1):
        return int(((100-p0)*w0)/(100-p1))

print(potatoes(99,100,98))
print(potatoes(82,127,80))