From 9ed60ba882c7b6a07b7b951447558710fcbdcc4b Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Mon, 2 Apr 2018 12:20:53 -0400 Subject: [PATCH 1/3] Solution to Problem 36 --- Project Euler/Problem 36/sol1.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Project Euler/Problem 36/sol1.py diff --git a/Project Euler/Problem 36/sol1.py b/Project Euler/Problem 36/sol1.py new file mode 100644 index 000000000..d78e7e59f --- /dev/null +++ b/Project Euler/Problem 36/sol1.py @@ -0,0 +1,30 @@ +from __future__ import print_function +''' +Double-base palindromes +Problem 36 +The decimal number, 585 = 10010010012 (binary), is palindromic in both bases. + +Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. + +(Please note that the palindromic number, in either base, may not include leading zeros.) +''' +try: + xrange #Python 2 +except NameError: + xrange = range #Python 3 + +def is_palindrome(n): + n = str(n) + + if n == n[::-1]: + return True + else: + return False + +total = 0 + +for i in xrange(1, 1000000): + if is_palindrome(i) and is_palindrome(bin(i).split('b')[1]): + total += i + +print(total) \ No newline at end of file From 6a8f1cf2325253f7643bd23d1e91cb410b3cbb00 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Mon, 2 Apr 2018 23:46:28 -0400 Subject: [PATCH 2/3] Solution to Problem 40 --- Project Euler/Problem 40/sol1.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Project Euler/Problem 40/sol1.py diff --git a/Project Euler/Problem 40/sol1.py b/Project Euler/Problem 40/sol1.py new file mode 100644 index 000000000..ab4017512 --- /dev/null +++ b/Project Euler/Problem 40/sol1.py @@ -0,0 +1,26 @@ +#-.- coding: latin-1 -.- +from __future__ import print_function +''' +Champernowne's constant +Problem 40 +An irrational decimal fraction is created by concatenating the positive integers: + +0.123456789101112131415161718192021... + +It can be seen that the 12th digit of the fractional part is 1. + +If dn represents the nth digit of the fractional part, find the value of the following expression. + +d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000 +''' + +constant = [] +i = 1 + +while len(constant) < 1e6: + constant.append(str(i)) + i += 1 + +constant = ''.join(constant) + +print(int(constant[0])*int(constant[9])*int(constant[99])*int(constant[999])*int(constant[9999])*int(constant[99999])*int(constant[999999])) \ No newline at end of file From b172ec38418044cefaaa6aafcf56eee172308de2 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Tue, 3 Apr 2018 00:04:38 -0400 Subject: [PATCH 3/3] Solution to Problem 52 --- Project Euler/Problem 52/sol1.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Project Euler/Problem 52/sol1.py diff --git a/Project Euler/Problem 52/sol1.py b/Project Euler/Problem 52/sol1.py new file mode 100644 index 000000000..376b4cfa1 --- /dev/null +++ b/Project Euler/Problem 52/sol1.py @@ -0,0 +1,23 @@ +from __future__ import print_function +''' +Permuted multiples +Problem 52 + +It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. + +Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits. +''' +i = 1 + +while True: + if sorted(list(str(i))) == \ + sorted(list(str(2*i))) == \ + sorted(list(str(3*i))) == \ + sorted(list(str(4*i))) == \ + sorted(list(str(5*i))) == \ + sorted(list(str(6*i))): + break + + i += 1 + +print(i) \ No newline at end of file