diff --git a/problem-55.py b/problem-55.py new file mode 100644 index 0000000..e820b6a --- /dev/null +++ b/problem-55.py @@ -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)) + + diff --git a/problem-56.py b/problem-56.py new file mode 100644 index 0000000..1df14da --- /dev/null +++ b/problem-56.py @@ -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) diff --git a/problem-57.py b/problem-57.py new file mode 100644 index 0000000..1ff3da3 --- /dev/null +++ b/problem-57.py @@ -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)) diff --git a/problem-65.py b/problem-65.py new file mode 100644 index 0000000..357a3af --- /dev/null +++ b/problem-65.py @@ -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])))) diff --git a/problem-69 b/problem-69 new file mode 100755 index 0000000..0a2a365 Binary files /dev/null and b/problem-69 differ diff --git a/problem-69.c b/problem-69.c new file mode 100644 index 0000000..9ec2a00 --- /dev/null +++ b/problem-69.c @@ -0,0 +1,60 @@ +#include + +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 greatest) { + greatest = i; + ratio = (double)i / coprimes; + } + } + + printf("number: %i\n", greatest); + printf("ratio : %f\n", ratio); + return 1; +} + + + diff --git a/problem-69.py b/problem-69.py new file mode 100644 index 0000000..c9bab06 --- /dev/null +++ b/problem-69.py @@ -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) + +