Skip to content

Instantly share code, notes, and snippets.

View gavinsykes's full-sized avatar

Gavin Sykes gavinsykes

View GitHub Profile
import sys
sys.path.append('/home/gavin/project-euler')
import pyfuncs
challenge = 'There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.'
def euler_9(n):
a = b = c = 1;
for a in range(1,n-2):
<?php
require_once '../php_functions.php';
function euler_9($n) {
$a = $b = $c = 1;
for ($a = 1;$a <= $n-2;$a++) {
for ($b = 1; $b <= $n-$a-1;$b++) {
$c = $n - $a - $b;
if (is_pythagorean_triple($a,$b,$c)) {
return $a . ', ' . $b . ' and ' . $c . ' make ' . $a*$b*$c . '.';
import argparse
import sys
sys.path.append('/home/gavin/project-euler')
import pyfuncs
challenge = 'Find the largest product of the series of {} adjacent digits in the large number below:\n\n731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789112949495459501737958331952853208805511125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138105158593079608667017242712188399879790879227492190169972088809377665727333001053367881220235421809751254540594752243525849077116705560136048395864467063244157221553975369781797784617406495514929086256932197846862248283972241375657056057490261407972968652414535100474821663704844031998900088952434506585412275886668811642717147992444292823086346567481391912316282458617866458359124566529476545682848912883142607690042242190226710556263211111093705442175069416589604080719840385096245544436298123098
import argparse
import sys
sys.path.append('/home/gavin/project-euler')
import pyfuncs
challenge = 'What is the {}th prime number?'
import math
use std::io;
use std::time::SystemTime;
fn main() {
println!("Find the difference between the sum of the squares of the first n natural numbers and the square of the sum of those numbers.");
println!("Please enter the number you want to try below. It must be a positive integer. To match with the Project Euler Problem 4, set it to be 10.");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("error: unable to read user input");
import argparse
import sys
sys.path.append('/home/gavin/project-euler')
import pyfuncs
challenge = 'Find the difference between the sum of the squares of the first {} natural numbers and the square of the sum:'
parser = argparse.ArgumentParser(description = 'Find the difference between the sum of the squares of the first x natural numbers and the square of the sum.')
parser.add_argument('--num', default = 10, type = int, help = 'Insert the number here, it must be a positive integer. It defaults to 10 to correspond with the Project Euler Problem at https://projecteuler.net/problem=6')
use std::io;
use std::time::SystemTime;
fn main() {
println!("Find the largest palindrome from the product of 2 numbers of a given length.");
println!("Please enter the number you want to try below. It must be a positive integer. To match with the Project Euler Problem 4, set it to be 3.");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("error: unable to read user input");
import argparse
import sys
sys.path.append('/home/gavin/project-euler')
import pyfuncs
challenge = 'Find the largest palindrome made from the product of 2 numbers of {} digits:'
parser = argparse.ArgumentParser(description = 'Find the largest palindrome made from the product of 2 numbers of x digits.')
parser.add_argument('--num', default = 3, type = int, help = 'Insert the number of digits here, it must be a positive integer. It defaults to 3 to correspond with the Project Euler Problem at https://projecteuler.net/problem=4')
use std::io;
use std::time::SystemTime;
fn main() {
println!("Find the largest prime factor of a given number.");
println!("Please enter the number you want to try below. It must be a positive integer. To match with the Project Euler Problem 3, set it to be 600851475143.");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("error: unable to read user input");
def gen_max_prime(n):
if ( (n < 1) or (not isinstance(n, int)) ):
return undefined
while(is_even(n)):
result = 2
n >>= 1
for i in range(3,int(math.sqrt(n)) + 1,2):