Skip to content

Instantly share code, notes, and snippets.

@Shadey
Last active August 29, 2015 14:06
Show Gist options
  • Save Shadey/81a838f1747b62046c54 to your computer and use it in GitHub Desktop.
Save Shadey/81a838f1747b62046c54 to your computer and use it in GitHub Desktop.
Java 8 Project Euler
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());
}
}
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