Skip to content

Solution to Problem 36 #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Project Euler/Problem 36/sol1.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions Project Euler/Problem 40/sol1.py
Original file line number Diff line number Diff line change
@@ -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]))
23 changes: 23 additions & 0 deletions Project Euler/Problem 52/sol1.py
Original file line number Diff line number Diff line change
@@ -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)