week 2 challenge
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
/Week4.class
|
||||
/Week4Bonus.class
|
||||
@@ -0,0 +1,53 @@
|
||||
package fall23.Week4;
|
||||
|
||||
/**
|
||||
* In this week's club bonus challenges, you will be tasked with solving problems relating to the Fibonacci Sequence.
|
||||
*
|
||||
* For those unfamiliar, the Fibonacci Seuqence is generated by adding the prior two terms. Starting with 1 & 2, The
|
||||
* first 10 terms are 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.
|
||||
*/
|
||||
public class Week4 {
|
||||
|
||||
/**
|
||||
* Only consider terms of the Fibonacci Sequence below 4 million. Find the sum of only the even terms.
|
||||
* eg. The first 5 terms counted would be 2, 8, 34, 144, 610, . . ., and the sum of those terms is 366.
|
||||
*
|
||||
* Credit: Project Euler Problem 2.
|
||||
* HINT: If your algorithm works for terms below 200, it'll work for the terms below any value.
|
||||
*/
|
||||
public static int problem1() {
|
||||
return -1; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an algorithm that will calculate the nth EVEN term of the Fibonacci Sequence.
|
||||
*
|
||||
* HINT: This only requires a minor modification to your solution for Problem1.
|
||||
*/
|
||||
public static int problem2(int n) {
|
||||
return -1; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an algorithm that finds the first EVEN term of the Fibonacci Sequence that has n digits.
|
||||
* eg. if n = 3, value = 144.
|
||||
*
|
||||
* Then, find the average of all of the EVEN terms up to this value.
|
||||
*/
|
||||
public static double problem3(int n) {
|
||||
return -1.0; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Test driver should not be edited!
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int sum1 = problem1();
|
||||
int sum2 = problem2(10);
|
||||
double avg3 = problem3(5);
|
||||
|
||||
System.out.println(sum1 == 4613732 ? "Problem 1 is correct!" : "Problem 1 (" + sum1 + ") is not correct...");
|
||||
System.out.println(sum2 == 196418 ? "Problem 2 is correct!" : "Problem 2 (" + sum2 + ") is not correct...");
|
||||
System.out.println(avg3 == 2046.0 ? "Problem 3 is correct!" : "Problem 3 (" + avg3 + ") is not correct...");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package fall23.Week4;
|
||||
|
||||
/**
|
||||
* In this week's club bonus challenge, you will be tasked with solving grid traversal problem.
|
||||
*/
|
||||
public class Week4Bonus {
|
||||
|
||||
/**
|
||||
* In a 2x2 grid, there are exactly 6 routes from the top-left corner to the bottom-right corner.
|
||||
* Find an algorithm to find the number of routes in a 20x20 grid.
|
||||
*
|
||||
* Credit: Project Euler Problem 15.
|
||||
*
|
||||
* HINT: Recursion, recursion, recursion, recursion, recursion, recursion, recursion, recursion, recursion, recursion...
|
||||
*/
|
||||
public static long problem1() {
|
||||
return -1; // TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Test driver should not be edited!
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
long ans1 = problem1();
|
||||
|
||||
System.out.println(ans1 == 137846528820L ? "Problem 1 is correct!" : "Problem 1 (" + ans1 + ") is not correct...");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user