Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Gzoref/fe68fbd6cbb55e2f81b62cdde81b649b to your computer and use it in GitHub Desktop.
Save Gzoref/fe68fbd6cbb55e2f81b62cdde81b649b to your computer and use it in GitHub Desktop.
Project Eular problems
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="AUTODETECT_INDENTS" value="false" />
<codeStyleSettings language="JAVA">
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="4" />
<option name="CLASS_BRACE_STYLE" value="5" />
<option name="METHOD_BRACE_STYLE" value="5" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION" value="true" />
<option name="SPACE_WITHIN_CAST_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_ELSE_KEYWORD" value="false" />
<option name="WRAP_COMMENTS" value="true" />
</codeStyleSettings>
</code_scheme>
</component>
<component name="ProjectDictionaryState">
<dictionary name="gzore" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/EvenFib/EvenFib.iml" filepath="$PROJECT_DIR$/EvenFib/EvenFib.iml" />
<module fileurl="file://$PROJECT_DIR$/Largest Prime Factor/Largest Prime Factor.iml" filepath="$PROJECT_DIR$/Largest Prime Factor/Largest Prime Factor.iml" />
<module fileurl="file://$PROJECT_DIR$/MulitpleOfThereAndFive/MulitpleOfThreeAndFive.iml" filepath="$PROJECT_DIR$/MulitpleOfThereAndFive/MulitpleOfThreeAndFive.iml" />
<module fileurl="file://$PROJECT_DIR$/Project Eular Problems.iml" filepath="$PROJECT_DIR$/Project Eular Problems.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="uidesigner-configuration">
<option name="DEFAULT_LAYOUT_MANAGER" value="FlowLayout" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
/*
* Name: Geoffrey Zoref
* Date: 12/24/2018
* Project: Project Eular Problems
*/
public class EvenFibonacci {
public static void main(String[] args) {
System.out.println(evenFib());
System.out.println(evenFib1());
}
public static int evenFib() {
int sum = 0;
int x = 1;
int y = 2;
while (x <= 4000000) {
if(x % 2 == 0)
sum += x;
int z = x + y;
x = y;
y = z;
}
return sum;
}
public static long evenFib1() {
long fib3 = 2;
long fib6 = 0;
long result = 2;
long summed = 0;
while (result < 4000000) {
summed += result;
result = 4 * fib3 + fib6;
fib6 = fib3;
fib3 = result;
}
return summed;
}
}
/**
* Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the
* first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence
* whose values do not exceed four million, find the sum of the even-valued terms.
*/
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
/*
* Name: Geoffrey Zoref
* Date: 12/24/2018
* Project: Project Eular Problems
*/
public class LargestPrimeFactor {
public static void main(String[] args) {
System.out.println(largestPFact());
}
private static long largestPFact() {
final long num = 600851475143L;
long newNum = num;
long largestFact = 0;
int counter = 2;
while (counter * counter <= newNum) {
if(newNum % counter == 0) {
newNum = newNum / counter;
}
else {
counter = (counter == 2) ? 3 : counter + 2;
}
}
return newNum;
}
}
/**
* The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
*/
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
/*
* Name: Geoffrey Zoref
* Date: 12/24/2018
* Project: Project Eular Problems
*/
public class ProblemOne {
public static int multiples() {
int total = 0;
for (int i = 1; i <= 999; i++) {
if(i % 3 == 0 || i % 5 == 0) {
total += i;
}
}
return total;
}
public static void main(String[] args) {
System.out.println(multiples());
}
}
/**
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these
* multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
*/
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment