Add more solutions
This commit is contained in:
23
problem-55.py
Normal file
23
problem-55.py
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
def get_palindrome(num):
|
||||
return int(str(num)[::-1])
|
||||
|
||||
|
||||
def is_palindrome(num):
|
||||
return get_palindrome(num) == num
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
results = []
|
||||
for i in range(10, 10000):
|
||||
num = i + get_palindrome(i)
|
||||
counter = 0
|
||||
while counter < 50 and not is_palindrome(num):
|
||||
num += get_palindrome(num)
|
||||
counter += 1
|
||||
if not is_palindrome(num):
|
||||
results.append(i)
|
||||
print(len(results))
|
||||
|
||||
|
||||
12
problem-56.py
Normal file
12
problem-56.py
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
MAX_NUM = 100
|
||||
|
||||
if __name__ == '__main__':
|
||||
maximum = 0
|
||||
for a in range(MAX_NUM):
|
||||
for b in range(MAX_NUM):
|
||||
num = a ** b
|
||||
total = sum(int(x) for x in list(str(num)))
|
||||
if total > maximum:
|
||||
maximum = total
|
||||
print(maximum)
|
||||
12
problem-57.py
Normal file
12
problem-57.py
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
if __name__ == '__main__':
|
||||
results = []
|
||||
numerator = 3
|
||||
denominator = 2
|
||||
for _ in range(1000):
|
||||
if len(str(numerator)) > len(str(denominator)):
|
||||
results.append(str(numerator) + '/' + str(denominator))
|
||||
denominator += numerator
|
||||
numerator += 2 * (denominator - numerator)
|
||||
print(results)
|
||||
print(len(results))
|
||||
20
problem-65.py
Normal file
20
problem-65.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sequence = [2]
|
||||
|
||||
i = 1
|
||||
while len(sequence) < 100:
|
||||
sequence.extend([1, i * 2, 1])
|
||||
i+=1
|
||||
|
||||
numerator = 1
|
||||
denominator = sequence.pop()
|
||||
|
||||
while len(sequence) > 0:
|
||||
frac = (sequence.pop() * denominator + numerator, denominator)
|
||||
denominator = frac[0]
|
||||
numerator = frac[1]
|
||||
|
||||
print(frac)
|
||||
print(sum(int(i) for i in list(str(frac[0]))))
|
||||
BIN
problem-69
Executable file
BIN
problem-69
Executable file
Binary file not shown.
60
problem-69.c
Normal file
60
problem-69.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned int gcd(unsigned int u, unsigned int v)
|
||||
{
|
||||
int shift;
|
||||
if (u == 0) return v;
|
||||
if (v == 0) return u;
|
||||
shift = __builtin_ctz(u | v);
|
||||
u >>= __builtin_ctz(u);
|
||||
do {
|
||||
v >>= __builtin_ctz(v);
|
||||
if (u > v) {
|
||||
unsigned int t = v;
|
||||
v = u;
|
||||
u = t;
|
||||
}
|
||||
v = v - u;
|
||||
} while (v != 0);
|
||||
return u << shift;
|
||||
}
|
||||
|
||||
|
||||
unsigned int is_coprime(unsigned int u, unsigned int v)
|
||||
{
|
||||
if (gcd(u, v) == 1)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
unsigned int i, j;
|
||||
unsigned int coprimes;
|
||||
unsigned int MAX_NUM = 1000000;
|
||||
int greatest = 0;
|
||||
double ratio = 0;
|
||||
|
||||
for (i=1; i<MAX_NUM; i++) {
|
||||
if (i % 10000 == 0)
|
||||
printf("%i\n", i);
|
||||
|
||||
coprimes = 1;
|
||||
for (j = 2; j<i; j++) {
|
||||
if (is_coprime(i, j))
|
||||
coprimes += 1;
|
||||
}
|
||||
|
||||
if (((double)i / coprimes) > greatest) {
|
||||
greatest = i;
|
||||
ratio = (double)i / coprimes;
|
||||
}
|
||||
}
|
||||
|
||||
printf("number: %i\n", greatest);
|
||||
printf("ratio : %f\n", ratio);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
20
problem-69.py
Normal file
20
problem-69.py
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
from math import gcd
|
||||
|
||||
MAX_NUM = 1000000
|
||||
|
||||
def is_coprime(a, b):
|
||||
return gcd(a, b) == 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
greatest_ratio = (0, 0)
|
||||
for n in range(2, MAX_NUM+1):
|
||||
if n % 10000 == 0:
|
||||
print(n)
|
||||
relative_primes = len([x for x in range(2, n) if is_coprime(x, n)]) + 1
|
||||
if n/relative_primes > greatest_ratio[1]:
|
||||
greatest_ratio = (n, n/relative_primes)
|
||||
print(greatest_ratio)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user