Skip to content

Commit 9b74a61

Browse files
committed
P41 i.e. 2.11 done for Java
1 parent 70bead4 commit 9b74a61

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

  • java8
    • src
      • main/java/com/shekhargulati/ninetynine_problems/java8/_02_arithmetic
      • test/java/com/shekhargulati/ninetynine_problems/java8/_02_arithmetic

java8/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,21 @@ public void phiOf99Is60() throws Exception {
694694
assertThat(p, equalTo(60));
695695
}
696696
```
697+
698+
### [P41](https://github.com/shekhargulati/99-problems/blob/master/java8/src/main/java/com/shekhargulati/ninetynine_problems/java8/_02_arithmetic/P41.java) **(*) Compare the two methods of calculating Euler's totient function.**
699+
700+
Use the solutions of problems P39 and P40 to compare the algorithms. Take the number of logical inferences as a measure for efficiency. Try to calculate `phi(10090)` as an example.
701+
702+
```java
703+
@Test
704+
public void shouldCalculatePhiOf10090UsingP39() throws Exception {
705+
long p = P39.phi(10090);
706+
assertThat(p, equalTo(4032L));
707+
}
708+
709+
@Test
710+
public void shouldCalculatePhiOf10090UsingP40() throws Exception {
711+
long p = P40.phi(10090);
712+
assertThat(p, equalTo(4032L));
713+
}
714+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.shekhargulati.ninetynine_problems.java8._02_arithmetic;
2+
3+
/**
4+
* (*) Compare the two methods of calculating Euler's totient function.
5+
* Check P41Test
6+
*/
7+
public class P41 {
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.shekhargulati.ninetynine_problems.java8._02_arithmetic;
2+
3+
import org.junit.Test;
4+
5+
import static org.hamcrest.CoreMatchers.equalTo;
6+
import static org.junit.Assert.assertThat;
7+
8+
public class P41Test {
9+
10+
@Test
11+
public void shouldCalculatePhiOf10090UsingP39() throws Exception {
12+
long p = P39.phi(10090);
13+
assertThat(p, equalTo(4032L));
14+
}
15+
16+
@Test
17+
public void shouldCalculatePhiOf10090UsingP40() throws Exception {
18+
long p = P40.phi(10090);
19+
assertThat(p, equalTo(4032L));
20+
}
21+
}

0 commit comments

Comments
 (0)