-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler032.py
More file actions
25 lines (20 loc) · 737 Bytes
/
Copy patheuler032.py
File metadata and controls
25 lines (20 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/python
def permutations( lst ) :
'''Returns sequential permutations of a list'''
if len( lst ) > 1 :
for i in xrange( len( lst ) ) :
for rest in permutations( lst[:i] + lst[i+1:] ) :
yield lst[i:i+1] + rest
else:
yield lst
solutions = set()
#for p in permutations( range( 1, 10 ) ) :
#product = p[5] * 1000 + p[6] * 100 + p[7] * 10 + p[8]
#if (p[0] * 10 + p[1]) * (p[2] * 100 + p[3] * 10 + p[4]) == product \
#or p[0] * ( p[1] * 1000 + p[2] * 100 + p[3] * 10 + p[4] ) == product :
#solutions.add( product )
for p in permutations( '123456789' ) :
product = int( p[5:] )
if int(p[0]) * int(p[1:5]) == product or int(p[0:2]) * int(p[2:5]) == product :
solutions.add( product )
print sum( solutions )