package com.fishercoder.solutions;

/**
 * There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is the minimum amount of pigs you need to figure out which bucket contains the poison within one hour.

 Answer this question, and write an algorithm for the follow-up general case.

 Follow-up:

 If there are n buckets and a pig drinking poison will die within m minutes, how many pigs (x) you need to figure out the "poison" bucket within p minutes? There is exact one bucket with poison.
 */
public class _458 {

    public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
        if (buckets-- == 1) {
            return 0;
        }
        int base = minutesToTest / minutesToDie + 1;
        int count = 0;
        while (buckets > 0) {
            buckets /= base;
            count++;
        }
        return count;
    }

}

@@ -33,16 +33,37 @@
 s;%0A%0A/**%0A
+ * 458. Poor Pigs%0A *%0A
  * There
@@ -122,16 +122,19 @@
  poison,
+%0A *
  the res
@@ -157,16 +157,19 @@
 h water.
+%0A *
  They al
@@ -184,16 +184,19 @@
 he same.
+%0A *
  If a pi
@@ -246,16 +246,19 @@
 minutes.
+%0A *
  What is
@@ -358,17 +358,18 @@
 e hour.%0A
-%0A
+ *
  Answer 
@@ -451,17 +451,16 @@
 low-up:%0A
-%0A
  If ther
@@ -527,16 +527,17 @@
 minutes,
+%0A
  how man
@@ -647,16 +647,18 @@
 poison.%0A
+ %0A
  */%0Apubl

refactor 458