36
4
Today you need to solve a very practical problem: How many loops do you need to have a certain number of sheets on your toilet paper roll? Let's look at some facts:
- The diameter of a bare toilet paper cylinder is 3.8cm
- The length of one sheet of toilet paper is 10cm.
- The thickness of one sheet of toilet paper is 1mm.
Before you wrap around the cylinder the first time, it has a circumference in cm of 3.8*pi. Every time you wrap a sheet around the cylinder its radius increases by .1, therefore its circumference increases by .2*PI. Use this information to find out how many loops it takes to fit n sheets of toilet paper. (Note: Use an approximation of Pi that is at least as accurate as 3.14159).
Test Cases:
n=1:
- 10/(3.8*pi) = .838 loops
n=2:
- (How many full loops can we make?) 1 full loop = 3.8*pi = 11.938.
- (How much do we have left after the 1st loop?) 20 - 11.938 = 8.062
- (How much of a 2nd loop does the remaining piece make?) 8.062/(4*pi) = .642 loops
- Answer: 1.642 loops
n=3:
- 1st full loop = 3.8*pi = 11.938, 2nd full loop = 4*pi = 12.566
- 30 - 11.938 - 12.566 = 5.496
- 5.496/(4.2*pi) = .417
- Answer: 2.417 loops
n=100 => 40.874
@FlagAsSpam Because in the first bullet point, I calculate the length of all the full loops. – geokavel – 2016-01-13T18:38:27.190
Also, your calculations are only correct if the bare roll is
3.7cm
in diameter. Only then the mean diameter of the first layer is3.8cm
. – Rainer P. – 2016-01-13T18:47:38.627@RainerP. o.k. I changed the language a bit. It should agree with what you're saying. – geokavel – 2016-01-13T19:01:24.593
35Phew! 1mm thick? Are you sure you're using toilet paper and not cardboard? – Digital Trauma – 2016-01-13T19:01:45.363
I'm getting
2.416499187…
forn = 3
. That doesn't round to2.417
. Is my calculation off somewhere? – PurkkaKoodari – 2016-01-13T19:14:17.863@Pietu1998 It's because when doing it by hand I rounded to 3 decimal places. – geokavel – 2016-01-13T19:16:47.590
So our programs do not have to round? – Conor O'Brien – 2016-01-13T19:35:45.223
@CᴏɴᴏʀO'Bʀɪᴇɴ Nope, less rounding is better. – geokavel – 2016-01-13T19:36:36.307
11@DigitalTrauma Clearly you don't know about triple-ply :p – geokavel – 2016-01-13T19:40:36.900
2Under the assumption that the toilet paper does not make steps but continuously increases the radius, you can get a closed form approximation to requested result. Is this good enough?
nloops = sqrt(n+11.34)*0.0564189 - 0.19
– flawr – 2016-01-13T20:01:33.203@flawr Sorry, no. – geokavel – 2016-01-13T20:04:14.793
Aside from the golfing aspect, I find this question incredibly amusing and even useful, lol. I wouldn't be surprised if this became a programming homework question and we see SO littered with this question!
– MonkeyZeus – 2016-01-13T21:13:20.3572Proposed test case:
100
->40.874
– Dennis – 2016-01-13T22:45:16.7831Triple-ply cardboard?! Now that's thick! – mbomb007 – 2016-01-13T22:59:05.767
1I'm not going to lie, I came here because I was expecting something else when I saw "toilet paper mysteries"... – Ashwin Gupta – 2016-01-15T03:20:01.330
@Ashwin Yeah, that was part off the idea :p – geokavel – 2016-01-15T03:21:44.933
1I can't get this shit to work. I think I need to try something different. :) – mathreadler – 2016-01-15T09:20:16.347
They see me rolling, they be knockin'. – mathreadler – 2016-01-15T09:28:32.230
It is literally a shit challenge. – sergiol – 2017-07-31T01:06:51.147