Last active
August 29, 2015 14:06
-
-
Save Shadey/81a838f1747b62046c54 to your computer and use it in GitHub Desktop.
Java 8 Project Euler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
public class ProjectOne{ | |
public static void main(String[] args){ | |
System.out.println(IntStream.range(1, 1000).filter(n -> n % 3 == 0 || n % 5 == 0).sum()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class ProblemTwo { | |
public static int fib(int n) { | |
if (n < 2) return n; | |
return fib(n - 1) + fib(n - 2); | |
} | |
public static void main(String[] args) { | |
List<Integer> nums = new ArrayList<Integer>(); | |
for(int i =0;fib(i) <= 4000000;i++) nums.add(fib(i)); | |
System.out.println(nums.stream() | |
.filter(n -> n % 2 == 0) | |
.mapToInt(n -> n) | |
.sum()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment