Skip to content

Commit f92a373

Browse files
refactor 458
1 parent e59063b commit f92a373

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/main/java/com/fishercoder/solutions/_458.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ how many pigs (x) you need to figure out the "poison" bucket within p minutes? T
1717
*/
1818
public class _458 {
1919

20-
public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
21-
if (buckets-- == 1) {
22-
return 0;
20+
public static class Solution1 {
21+
public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
22+
if (buckets-- == 1) {
23+
return 0;
24+
}
25+
int base = minutesToTest / minutesToDie + 1;
26+
int count = 0;
27+
while (buckets > 0) {
28+
buckets /= base;
29+
count++;
30+
}
31+
return count;
2332
}
24-
int base = minutesToTest / minutesToDie + 1;
25-
int count = 0;
26-
while (buckets > 0) {
27-
buckets /= base;
28-
count++;
29-
}
30-
return count;
3133
}
3234

3335
}

src/test/java/com/fishercoder/_458Test.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import static junit.framework.Assert.assertEquals;
99

1010
public class _458Test {
11-
private static _458 test;
11+
private static _458.Solution1 solution1;
1212
private static int expected;
1313
private static int actual;
1414
private static int buckets;
@@ -17,7 +17,7 @@ public class _458Test {
1717

1818
@BeforeClass
1919
public static void setup() {
20-
test = new _458();
20+
solution1 = new _458.Solution1();
2121
}
2222

2323
@Before
@@ -32,7 +32,7 @@ public void test1() {
3232
minutesToDie = 15;
3333
minutesToTest = 60;
3434
expected = 5;
35-
actual = test.poorPigs(buckets, minutesToDie, minutesToTest);
35+
actual = solution1.poorPigs(buckets, minutesToDie, minutesToTest);
3636
assertEquals(expected, actual);
3737
}
3838

@@ -42,7 +42,7 @@ public void test2() {
4242
minutesToDie = 1;
4343
minutesToTest = 1;
4444
expected = 0;
45-
actual = test.poorPigs(buckets, minutesToDie, minutesToTest);
45+
actual = solution1.poorPigs(buckets, minutesToDie, minutesToTest);
4646
assertEquals(expected, actual);
4747
}
4848

@@ -52,7 +52,7 @@ public void test3() {
5252
minutesToDie = 12;
5353
minutesToTest = 60;
5454
expected = 4;
55-
actual = test.poorPigs(buckets, minutesToDie, minutesToTest);
55+
actual = solution1.poorPigs(buckets, minutesToDie, minutesToTest);
5656
assertEquals(expected, actual);
5757
}
5858
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy