Aug 18, 2013
Aug 17, 2013
Project Euler Problem Nos 43
Original problem posted at:
http://projecteuler.net/problem=43
This is my solution to problem 43:
Output from the python script:
[('160', '603', '035', '357', '572', '728', '289'), ('460', '603', '035', '357', '572', '728', '289'), ('106', '063', '635', '357', '572', '728', '289'), ('406', '063', '635', '357', '572', '728', '289'), ('130', '309', '095', '952', '528', '286', '867'), ('430', '309', '095', '952', '528', '286', '867')]
Or after rearranging the digits according to the rules in problem 43:
4160357289
1460357289
4106357289
1406357289
4130952867
1430952867
These are the six numbers that satisfy all the properties and will add up to the answer.
http://projecteuler.net/problem=43
This is my solution to problem 43:
#!/usr/bin/python
### problem 43
import string
def get_divisible_set(n):
myset=[]
for i in range(2,999):
if (i%n==0):
myset.append(str(i).zfill(3))
###myset.append(str.format("%03d", i))
###n = '4'
###>>> print n.zfill(3)
###>>> '004'
return myset
def check_adjoining_item(a, b):
if ((a[1]==b[0])and(a[2]==b[1])):
return 1
else:
return 0
def get_adjoining_set(seta, setb):
myset=[]
#### assuming setb is the smaller set....
mylenb=len(setb)
mylena=len(seta)
for i in range(mylenb):
for j in range(mylena):
###print seta[j], setb[i]
mysettmp=set(seta[j])
mysettmp=mysettmp.union(set(setb[i]))
if (check_adjoining_item(seta[j], setb[i])==1) and (len(mysettmp)==4):
myset.append((seta[j],setb[i]))
return myset
myset17=get_divisible_set(17)
myset13=get_divisible_set(13)
myset11=get_divisible_set(11)
myset=get_adjoining_set(myset13, myset17)
nextset=[]
for i in range(len(myset)):
#print myset[i]
(a,b)=myset[i]
tmp=[]
mysettmp=set()
tmp.append(a)
tmpset=get_adjoining_set(myset11, tmp)
if len(tmpset)>0:
for j in range(len(tmpset)):
(c,d)=tmpset[j]
mysettmp=set(d)
mysettmp=mysettmp.union(set(c))
mysettmp=mysettmp.union(set(a))
mysettmp=mysettmp.union(set(b))
if len(mysettmp)==5:
nextset.append((c,a,b))
print "aaaa"
print nextset
myset7=get_divisible_set(7)
nextset1=[]
for i in range(len(nextset)):
(a,b,c)=nextset[i]
tmp=[]
mysettmp=set()
tmp.append(a)
tmpset=get_adjoining_set(myset7, tmp)
if len(tmpset)>0:
for j in range(len(tmpset)):
(d,e)=tmpset[j]
mysettmp=set(e)
mysettmp=mysettmp.union(set(d))
mysettmp=mysettmp.union(set(a))
mysettmp=mysettmp.union(set(b))
mysettmp=mysettmp.union(set(c))
if len(mysettmp)==6:
nextset1.append((d,e,b,c))
print "bbb"
print nextset1
myset5=get_divisible_set(5)
nextset2=[]
for i in range(len(nextset1)):
(a,b,c,d)=nextset1[i]
tmp=[]
mysettmp=set()
tmp.append(a)
tmpset=get_adjoining_set(myset5, tmp)
if len(tmpset)>0:
for j in range(len(tmpset)):
(e,f)=tmpset[j]
mysettmp=set(f)
mysettmp=mysettmp.union(set(e))
mysettmp=mysettmp.union(set(a))
mysettmp=mysettmp.union(set(b))
mysettmp=mysettmp.union(set(c))
mysettmp=mysettmp.union(set(d))
if len(mysettmp)==7:
nextset2.append((e,a,b,c,d))
print "bbb"
print nextset2
myset3=get_divisible_set(3)
nextset3=[]
for i in range(len(nextset2)):
(a,b,c,d,e)=nextset2[i]
tmp=[]
mysettmp=set()
tmp.append(a)
tmpset=get_adjoining_set(myset3, tmp)
if len(tmpset)>0:
for j in range(len(tmpset)):
(f,g)=tmpset[j]
mysettmp=set(g)
mysettmp=mysettmp.union(set(f))
mysettmp=mysettmp.union(set(a))
mysettmp=mysettmp.union(set(b))
mysettmp=mysettmp.union(set(c))
mysettmp=mysettmp.union(set(d))
mysettmp=mysettmp.union(set(e))
if len(mysettmp)==8:
nextset3.append((f,a,b,c,d,e))
myset2=get_divisible_set(2)
nextset4=[]
for i in range(len(nextset3)):
(a,b,c,d,e,f)=nextset3[i]
tmp=[]
mysettmp=set()
tmp.append(a)
tmpset=get_adjoining_set(myset2, tmp)
if len(tmpset)>0:
for j in range(len(tmpset)):
(g,h)=tmpset[j]
mysettmp=set(h)
mysettmp=mysettmp.union(set(g))
mysettmp=mysettmp.union(set(a))
mysettmp=mysettmp.union(set(b))
mysettmp=mysettmp.union(set(c))
mysettmp=mysettmp.union(set(d))
mysettmp=mysettmp.union(set(e))
mysettmp=mysettmp.union(set(f))
if len(mysettmp)==9:
nextset4.append((g,a,b,c,d,e,f))
print "final ans"
print nextset4
Output from the python script:
[('160', '603', '035', '357', '572', '728', '289'), ('460', '603', '035', '357', '572', '728', '289'), ('106', '063', '635', '357', '572', '728', '289'), ('406', '063', '635', '357', '572', '728', '289'), ('130', '309', '095', '952', '528', '286', '867'), ('430', '309', '095', '952', '528', '286', '867')]
Or after rearranging the digits according to the rules in problem 43:
4160357289
1460357289
4106357289
1406357289
4130952867
1430952867
These are the six numbers that satisfy all the properties and will add up to the answer.
Aug 15, 2013
Aug 13, 2013
Physics World Cup Problems & Solutions (II)
-
-
[PDF]pdf 1 - IYPT Archive
-
[PDF]ranking after pf4 - IYPT
-
[PDF]The Regulations of the International - IYPT
Jul 30, 2011 - The Regulations of the International. Young Physicists' Tournament. I. International Young Physicists' Tournament. The International Young ... -
[PDF]2 - IYPT Bratislava 2006
-
[PDF]Overview for Round: 1
-
[PDF]Download - IYPT
-
[PDF]Odborná komisia - IYPT
International Organizing Committee. Young Physicists' Tournament. EC meeting. Minutes. November 10th – 11th 2012, Taipei, Taiwan. Present: Alan Allinson ... -
[PDF]Overview for Round: 3
-
[PDF]IOC meeting Minutes - IYPT
International Organizing Committee. Young Physicists' Tournament. IOC meeting. Minutes. July 30th 2011, Safavi Hotel, Esfahan, Iran. Agenda. The agenda ... -
[PDF]Round: 3 - IYPT
-
[PDF]IYPT 2012
-
[PDF]Problems for IYPT 2011
Problems for IYPT 2011. 1. Adhesive tape. Determine the force necessary to remove a piece of adhesive tape from a horizontal surface. Investigate the influence ... -
[PDF]Scoring Guidelines - IYPT
Revised after IOC feedback and approved by EC on 2011-11-03. A report should include: • a presentation of the appropriate concepts, theories and principles of ... -
[PDF]Odborná komisia - IYPT
-
[PDF]Tournament Annual IOC meeting, Alpenhotel Goessing ... - IYPT
Jul 17, 2010 - International Organizing Committee. Young Physicists' Tournament. Annual IOC meeting, Alpenhotel Goessing, Austria. Minutes. July 16th ... -
[PDF]Problem submission form IYPT 2013
Apr 30, 2012 - International Organizing Committee. Young Physicists' Tournament. Problem submission form IYPT 2013. Country. Author's name e-mail. -
[PDF]η - IYPT Archive
-
[PDF]Round: 3, Room: Room A
-
[PDF]Overview for Round: 5
-
[PDF]Round: 1, Room: Room D
-
[PDF]Overview for Round: 2
-
[PDF]f - iypt solutions
-
[PDF]Round: 2 - IYPT
-
[PDF]Round: 2 - IYPT
-
[PDF]Dynamic Bubbles - IYPT
-
[PDF]l - IYPT Archive
-
[PDF]x - iypt solutions
-
[PDF]ranking after pf5 - IYPT
-
[PDF]A report should include:
-
[PDF]u re
-
[PDF]_ 5;»; . j; . . 1%
-
[PDF]ui - IYPT
-
[PDF]1 ; Signature:
-
[PDF]ui
-
[PDF]K A - IYPT
-
[PDF]Signatu re: '; a/
-
[PDF]cring - IYPT
-
[PDF]Fight (Round no): in
-
[PDF]iii - IYPT
-
[PDF]ML - IYPT
-
[PDF]_\ Fight (Round no):
-
[PDF]C a
-
[PDF]Scoring Guidelines
-
[PDF]ri uidelins
-
[PDF]f
-
[PDF]'- r . - IYPT
-
[PDF]iii, iii: i;
-
[PDF]ri - IYPT
Subscribe to:
Posts (Atom)