File tree Expand file tree Collapse file tree 7 files changed +63
-7
lines changed
Expand file tree Collapse file tree 7 files changed +63
-7
lines changed Original file line number Diff line number Diff line change 88 <artifactId >project-euler-java</artifactId >
99 <version >1.0-SNAPSHOT</version >
1010
11-
11+ <dependencies >
12+ <dependency >
13+ <groupId >junit</groupId >
14+ <artifactId >junit</artifactId >
15+ <version >4.12</version >
16+ </dependency >
17+ <dependency >
18+ <groupId >org.assertj</groupId >
19+ <artifactId >assertj-core</artifactId >
20+ <version >3.6.2</version >
21+ </dependency >
22+ </dependencies >
1223</project >
Original file line number Diff line number Diff line change 55 * Find the sum of all the multiples of 3 or 5 below 1000.
66 */
77public class Problem1 {
8- public static void main ( String [] args ) {
8+ public int solve ( ) {
99 int result = 0 ;
1010
1111 for (int i = 3 ; i < 1000 ; i ++) {
1212 if (i % 3 == 0 || i % 5 == 0 ) {
1313 result += i ;
1414 }
1515 }
16+ return result ;
17+ }
18+
19+ public static void main (String [] args ) {
20+ int result = new Problem1 ().solve ();
1621 System .out .println ("Result: " + result );
1722 }
1823}
Original file line number Diff line number Diff line change 77 * By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
88 */
99public class Problem2 {
10- public static void main ( String [] args ) {
10+ public int solve ( ) {
1111 int previous = 1 ;
1212 int current = 1 ;
1313 int result = 0 ;
@@ -20,6 +20,11 @@ public static void main(String[] args) {
2020 previous = current ;
2121 current = newCurrent ;
2222 }
23+ return result ;
24+ }
25+
26+ public static void main (String [] args ) {
27+ int result = new Problem2 ().solve ();
2328 System .out .println ("Result: " + result );
2429 }
2530}
Original file line number Diff line number Diff line change 55 * What is the largest prime factor of the number 600851475143 ?
66 */
77public class Problem3 {
8- public static void main ( String [] args ) {
8+ public int solve ( ) {
99 long num = 600851475143L ;
10- long largest = -1 ;
10+ int largest = -1 ;
1111 long copy = num ;
12- for (long i = 2 ; i < Math .sqrt (num ); i ++) {
12+ for (int i = 2 ; i < Math .sqrt (num ); i ++) {
1313 if (copy == 1L ) {
1414 break ;
1515 }
@@ -18,6 +18,11 @@ public static void main(String[] args) {
1818 largest = i ;
1919 }
2020 }
21- System .out .println ("Result: " + largest );
21+ return largest ;
22+ }
23+
24+ public static void main (String [] args ) {
25+ int result = new Problem3 ().solve ();
26+ System .out .println ("Result: " + result );
2227 }
2328}
Original file line number Diff line number Diff line change 1+ import org .assertj .core .api .Assertions ;
2+ import org .junit .Test ;
3+
4+ public class Problem1Test {
5+ @ Test
6+ public void checkValidValue () {
7+ int result = new Problem1 ().solve ();
8+ Assertions .assertThat (result ).isEqualTo (233168 );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ import org .assertj .core .api .Assertions ;
2+ import org .junit .Test ;
3+
4+ public class Problem2Test {
5+ @ Test
6+ public void checkValidValue () {
7+ int result = new Problem2 ().solve ();
8+ Assertions .assertThat (result ).isEqualTo (4613732 );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ import org .assertj .core .api .Assertions ;
2+ import org .junit .Test ;
3+
4+ public class Problem3Test {
5+ @ Test
6+ public void checkValidValue () {
7+ int result = new Problem3 ().solve ();
8+ Assertions .assertThat (result ).isEqualTo (6857 );
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments