mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Merge pull request #282 from daniel-s-ingram/master
Solution to Problem 36
This commit is contained in:
commit
78beda5034
30
Project Euler/Problem 36/sol1.py
Normal file
30
Project Euler/Problem 36/sol1.py
Normal file
|
@ -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
Project Euler/Problem 40/sol1.py
Normal file
26
Project Euler/Problem 40/sol1.py
Normal file
|
@ -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
Project Euler/Problem 52/sol1.py
Normal file
23
Project Euler/Problem 52/sol1.py
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user