From 1231e9562e508247bf23d3cb27c93b62159e7ca5 Mon Sep 17 00:00:00 2001 From: JellyWX Date: Wed, 21 Jun 2017 17:42:24 +0100 Subject: [PATCH] added solutions 4 and 5 --- problem3.py | 12 +++++++++--- problem4.py | 9 +++++++++ problem5.py | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 problem4.py create mode 100644 problem5.py diff --git a/problem3.py b/problem3.py index 09b37f3..bff2406 100644 --- a/problem3.py +++ b/problem3.py @@ -1,12 +1,18 @@ -prime = 13195 +prime = 600851475143 current_num = prime factors = [] +ran = False +hit = False -while current_num != 1: +while current_num != 1 and not ran: for i in range(2,current_num + 1): if current_num % i == 0: print('got a hit: ' + str(current_num) + str(factors)) factors.append(i) - current_num /= i + current_num //= i + hit = True + if not hit: + ran = False print(factors) +print('the largest prime factor is: ' + str(max(factors))) diff --git a/problem4.py b/problem4.py new file mode 100644 index 0000000..40fb5aa --- /dev/null +++ b/problem4.py @@ -0,0 +1,9 @@ +highest_value = 0 + +for i in range(100,1000): + for j in range(100,1000): + if str(i*j) == str(i*j)[::-1]: + if i*j > highest_value: + highest_value = i*j + +print(highest_value) diff --git a/problem5.py b/problem5.py new file mode 100644 index 0000000..39bf2b6 --- /dev/null +++ b/problem5.py @@ -0,0 +1,16 @@ +done = False +key = 1 + +def modulo(n): + for i in range(1,21): + if n % i != 0: + return False + return True + +while not done: + num = key*20 + done = modulo(num) + + key += 1 + +print(num)