Skip to content

Commit 78beda5

Browse files
authored
Merge pull request TheAlgorithms#282 from daniel-s-ingram/master
Solution to Problem 36
2 parents cf14473 + b172ec3 commit 78beda5

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

Project Euler/Problem 36/sol1.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import print_function
2+
'''
3+
Double-base palindromes
4+
Problem 36
5+
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
6+
7+
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
8+
9+
(Please note that the palindromic number, in either base, may not include leading zeros.)
10+
'''
11+
try:
12+
xrange #Python 2
13+
except NameError:
14+
xrange = range #Python 3
15+
16+
def is_palindrome(n):
17+
n = str(n)
18+
19+
if n == n[::-1]:
20+
return True
21+
else:
22+
return False
23+
24+
total = 0
25+
26+
for i in xrange(1, 1000000):
27+
if is_palindrome(i) and is_palindrome(bin(i).split('b')[1]):
28+
total += i
29+
30+
print(total)

Project Euler/Problem 40/sol1.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#-.- coding: latin-1 -.-
2+
from __future__ import print_function
3+
'''
4+
Champernowne's constant
5+
Problem 40
6+
An irrational decimal fraction is created by concatenating the positive integers:
7+
8+
0.123456789101112131415161718192021...
9+
10+
It can be seen that the 12th digit of the fractional part is 1.
11+
12+
If dn represents the nth digit of the fractional part, find the value of the following expression.
13+
14+
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
15+
'''
16+
17+
constant = []
18+
i = 1
19+
20+
while len(constant) < 1e6:
21+
constant.append(str(i))
22+
i += 1
23+
24+
constant = ''.join(constant)
25+
26+
print(int(constant[0])*int(constant[9])*int(constant[99])*int(constant[999])*int(constant[9999])*int(constant[99999])*int(constant[999999]))

Project Euler/Problem 52/sol1.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import print_function
2+
'''
3+
Permuted multiples
4+
Problem 52
5+
6+
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
7+
8+
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
9+
'''
10+
i = 1
11+
12+
while True:
13+
if sorted(list(str(i))) == \
14+
sorted(list(str(2*i))) == \
15+
sorted(list(str(3*i))) == \
16+
sorted(list(str(4*i))) == \
17+
sorted(list(str(5*i))) == \
18+
sorted(list(str(6*i))):
19+
break
20+
21+
i += 1
22+
23+
print(i)

0 commit comments

Comments
 (0)