Home Testing Forum

testD

The critical run. Another run (not shown) confirms the need for a 1963 $1 Federal Reserve Note to be in all solutions. This run actually references 12-note solutions. After each global store comma is a translation of each note's code.


Here is the code:



from time import time as systemTime
from sets import Set

empty=Set()


globalStores = [ Set(['l1', 'o1', 's3']), 1928 $1 USN
Set(['l1', 'ns1', 'o1', 's3']), 1928-B $2 USN
Set(['l5', 'ns1', 'o1', 's3']), 1928C-G $2 USN
Set(['fn1', 'l5', 'o1', 's8']), 1953-C $2 USN
Set(['fn1', 's8']), 1963 $2 USN

Set(['l1', 'ns2', 'o1', 's3']), 1928-B $5 USN
Set(['l5', 'ns2', 'o1', 's3']), 1928B-F $5 USN
Set(['fn3', 'l5', 'o1', 's8']), 1953-C $5 USN
Set(['fn3', 's8']), 1963 $5 USN
Set(['ch1', 'ns2']), 1929 $5 NBN T1
Set(['ch2', 'ns2']), 1929 $5 NBN T2
Set(['l3', 'ns2', 's2']), 1929 $5 FRBN
Set(['fn2', 'ns2']), 1934-D $5 SC
Set(['fn2', 'ns2', 's4']), 1934A $5 NASC
Set(['fn3']), 1953 $5 SC
Set(['f1', 'l2', 'ns2', 'o1', 's5']), 1928-A $5 Numeral FRN (forest green seal)
Set(['f2', 'l2', 'ns2', 'o1', 's5']), 1928B $5 Dark Green Seal (DGS) FRN
Set(['f2', 'l2', 'ns2', 'o1', 's6']), 1928B $5 Light Green Seal (LGS) "Lime" FRN
Set(['f2', 'l4', 'ns2', 'o1', 's6']), 1934 $5 LGS FRN
Set(['f2', 'l4', 'ns2', 'o1', 's7']), 1934 $5 DGS FRN (turquoise)
Set(['f2', 'l4', 'ns2', 'o1', 's2']), Hawaii $5 FRN
Set(['f3', 'l4', 'ns2', 'o1', 's7']), 1934B $5 FRN

Set(['ns3', 's1']), 1928 $10 GC
Set(['ch1', 'ns3']), 1929 $10 NBN T1
Set(['ch2', 'ns3']), 1929 $10 NBN T2
Set(['l3', 'ns3', 's2']), 1929 $10 FRBN
Set(['fn4', 'ns3']), 1934-D $10 SC
Set(['fn4', 'ns3', 's4']), 1934A $10 NASC
Set(['f1', 'l2', 'ns3', 'o1', 's5']), 1928-A $10 Numeral
Set(['f2', 'l2', 'ns3', 'o1', 's5']), 1928B $10 DGS
Set(['f2', 'l2', 'ns3', 'o1', 's6']), 1928B $10 Lime
Set(['f2', 'l4', 'ns3', 'o1', 's6']), 1934 $10 Lime
Set(['f2', 'l4', 'ns3', 'o1', 's7']), 1934 $10 Turquoise
Set(['f2', 'l4', 'ns3', 'o1', 's2']), $10 Hawaii
Set(['f3', 'l4', 'ns3', 'o1', 's7']), 1934B $10 FRN

Set(['b1', 's1']), 1928 $20 GC
Set(['b1', 'ch1']), 1929 $20 NBN T1
Set(['b1', 'ch2']), 1929 $20 NBN T2
Set(['b1', 'l3', 's2']), 1929 $20 FRBN
Set(['b1', 'f1', 'l2', 'o1', 's5']), 1928-A $20 Numeral
Set(['b1', 'f2', 'l2', 'o1', 's5']), 1928B $20 DGS
Set(['b1', 'f2', 'l2', 'o1', 's6']), 1928B $20 Lime
Set(['b1', 'f2', 'l4', 'o1', 's6']), 1934 $20 Lime
Set(['b1', 'f2', 'l4', 'o1', 's7']), 1934 $20 Turquoise
Set(['b1', 'f2', 'l4', 'o1', 's2']), $20 Hawaii
Set(['b1', 'f3', 'l4', 'o1', 's7']), 1934B-C $20 DGS
Set(['b2', 'f3', 'l4', 'o1', 's7']), 1934C-D $20 FRN

Set(['ns4', 's1']), 1928 $50 GC
Set(['ch1', 'ns4']), 1929 $50 NBN T1
Set(['ch2', 'ns4']), 1929 $50 NBN T2
Set(['l3', 'ns4', 's2']), 1929 $50 FRBN
Set(['f1', 'l2', 'ns4', 'o1', 's5']), 1928 $50 Numeral
Set(['f2', 'l2', 'ns4', 'o1', 's5']), 1928A $50 DGS
Set(['f2', 'l2', 'ns4', 'o1', 's6']), 1928A $50 Lime
Set(['f2', 'l4', 'ns4', 'o1', 's6']), 1934 $50 Lime
Set(['f2', 'l4', 'ns4', 'o1', 's7']), 1934 $50 DGS
Set(['f3', 'l4', 'ns4', 'o1', 's7']), 1934B $50 FRN

Set(['fn5', 's1']), 1928 $100 GC
Set(['ch1', 'fn5']), 1929 $100 NBN T1
Set(['ch2', 'fn5']), 1929 $100 NBN T2
Set(['fn5', 'l3', 's2']), 1929 $100 FRBN
Set(['f1', 'fn5', 'l2', 'o1', 's5']), 1928 $100 Numeral
Set(['f2', 'fn5', 'l2', 'o1', 's5']), 1928A $100 DGS
Set(['f2', 'fn5', 'l2', 'o1', 's6']), 1928A $100 Lime
Set(['f2', 'fn5', 'l4', 'o1', 's6']), 1934 $100 Lime
Set(['f2', 'fn5', 'l4', 'o1', 's7']), 1934 $100 DGS
Set(['f3', 'fn5', 'l4', 'o1', 's7']) ] 1934B $100 FRN

def union( sets ) :
return reduce( Set.__or__, sets, Set() )


allColors = union( globalStores )

print len(globalStores)
print len(allColors)

def check( ans, colors, stores) :
for solution in ans :
assert union(solution).issuperset(colors), (solution, remainingColors)
for store in solution :
assert store in globalStores
assert store in stores
return ans

def minStores( colors, stores, worstCase ) :
"""
Return a complete list of minimal sets of worstCase stores which contain at least the indicated colors.
colors = set of required colors
stores = list of stores. each store is a set of colors.
worstCase = integer
"""
for store in stores :
assert store in globalStores, store
nstores = len(stores)
if len(colors) == 0 :
assert worstCase == 0
return [[]] # empty solution is only solution

if worstCase == 0 or nstores==0 :
return [] # impossible

if worstCase == 1 :
return check( [ [store] for store in stores if store.issuperset(colors) ], colors, stores )

colorCount = dict( [(color,0) for color in colors] ) # number of stores with a given color
colorStore = dict() # example of a store with each color
maxUsefulColors = 0
for store in stores :
usefulColors = store.intersection(colors)
if len(usefulColors) > maxUsefulColors :
maxUsefulColors = len(usefulColors)
suggestedStore = store
for color in usefulColors :
colorCount[color] += 1
colorStore[color] = store

for color in colors :
if colorCount[color] == 0 :
return []

for color in colors :
if colorCount[color] == 1 :
myStore = colorStore[color]
myStoreNumber = stores.index(myStore)
remainingStores = stores[:myStoreNumber] + stores[myStoreNumber+1:]
avecS = minStores( colors-myStore, remainingStores, worstCase-1 )
map( list.append, avecS, [myStore]*len(avecS) )
return check( avecS, colors, stores )

remainingColors = colors-suggestedStore
dominatedStores = [ store for store in stores
if remainingColors.intersection(store)==empty ]
remainingStores = [ store for store in stores
if remainingColors.intersection(store)!=empty ]

ans = minStores( colors, remainingStores, worstCase )

avecS = minStores( remainingColors, remainingStores, worstCase-1 )
for myStore in dominatedStores :
neededColors = colors - myStore
ans += [ solution+[myStore]
for solution in avecS
if union(solution).issuperset(neededColors) ]
return check( ans, colors, stores )

startTime = systemTime()
ans = minStores( allColors, globalStores, 12 )
print systemTime() - startTime, "seconds"

n = len(ans)
print n, "solutions"

d = {}
for store in globalStores :
s = list(store)
s.sort()
d[tuple(s)] = 0.
for sol in ans :
for store in sol :
s = list(store)
s.sort()
d[tuple(s)] += 1./n
print d

colorDict = dict( [ (color,0.) for color in allColors ] )
for store, freq in d.iteritems() :
for color in store :
colorDict[color] += freq
print colorDict

Time required 909.702981949 seconds

113040 solutions found

Fraction of solutions containing each store:
{('l3', 'ns3', 's2'): 0.14140127388531556,
('f1', 'fn5', 'l2', 'o1', 's5'): 0.23906581740968061,
('f3', 'fn5', 'l4', 'o1', 's7'): 0.0,
('b1', 'f2', 'l4', 'o1', 's7'): 0.0,
('b1', 'f1', 'l2', 'o1', 's5'): 0.23906581740968061,
('fn3',): 0.24999999999990843,
('f3', 'l4', 'ns4', 'o1', 's7'): 0.0,
('f2', 'l2', 'ns2', 'o1', 's6'): 0.070700636942677392,
('f2', 'fn5', 'l4', 'o1', 's6'): 0.11953290870485991,
('f2', 'l2', 'ns4', 'o1', 's5'): 0.0,
('ch1', 'ns2'): 0.14140127388531556,
('f2', 'l4', 'ns2', 'o1', 's2'): 0.0,
('f2', 'l4', 'ns3', 'o1', 's6'): 0.070700636942677392,
('fn4', 'ns3'): 0.3333333333331982,
('b1', 's1'): 0.28025477706995633,
('f2', 'l4', 'ns4', 'o1', 's7'): 0.0,
('l1', 'ns1', 'o1', 's3'): 1.0000000000026534,
('f2', 'l2', 'ns4', 'o1', 's6'): 0.11953290870485991,
('f2', 'fn5', 'l2', 'o1', 's5'): 0.0,
('b1', 'f2', 'l2', 'o1', 's5'): 0.0,
('ch1', 'ns4'): 0.23906581740968061,
('l3', 'ns4', 's2'): 0.23906581740968061,
('f1', 'l2', 'ns2', 'o1', 's5'): 0.14140127388531556,
('b1', 'l3', 's2'): 0.23906581740968061,
('b2', 'f3', 'l4', 'o1', 's7'): 1.0000000000026534,
('b1', 'f2', 'l4', 'o1', 's2'): 0.0,
('ch2', 'ns2'): 0.14140127388531556,
('ch1', 'fn5'): 0.23906581740968061,
('f1', 'l2', 'ns3', 'o1', 's5'): 0.14140127388531556,
('fn3', 's8'): 0.24999999999990843,
('f2', 'fn5', 'l4', 'o1', 's7'): 0.0,
('f2', 'l4', 'ns4', 'o1', 's6'): 0.11953290870485991,
('ch2', 'ns4'): 0.23906581740968061,
('b1', 'ch2'): 0.23906581740968061,
('f3', 'l4', 'ns2', 'o1', 's7'): 0.0,
('f2', 'l4', 'ns2', 'o1', 's7'): 0.0,
('f2', 'l2', 'ns3', 'o1', 's5'): 0.0,
('fn1', 'l5', 'o1', 's8'): 0.75000000000121558,
('l5', 'ns1', 'o1', 's3'): 0.0,
('l1', 'ns2', 'o1', 's3'): 0.0,
('ch2', 'fn5'): 0.23906581740968061,
('f2', 'fn5', 'l2', 'o1', 's6'): 0.11953290870485991,
('fn4', 'ns3', 's4'): 0.66666666666740293,
('f3', 'l4', 'ns3', 'o1', 's7'): 0.0,
('ch2', 'ns3'): 0.14140127388531556,
('b1', 'f2', 'l4', 'o1', 's6'): 0.11953290870485991,
('ns3', 's1'): 0.15923566878976483,
('fn3', 'l5', 'o1', 's8'): 0.49999999999977768,
('fn2', 'ns2', 's4'): 0.66666666666740293,
('b1', 'ch1'): 0.23906581740968061,
('l5', 'ns2', 'o1', 's3'): 0.0,
('fn5', 's1'): 0.28025477706995633,
('f1', 'l2', 'ns4', 'o1', 's5'): 0.23906581740968061,
('fn5', 'l3', 's2'): 0.23906581740968061,
('ns4', 's1'): 0.28025477706995633,
('f2', 'l4', 'ns3', 'o1', 's7'): 0.0,
('b1', 'f3', 'l4', 'o1', 's7'): 0.0,
('f2', 'l2', 'ns2', 'o1', 's5'): 0.0,
('fn1', 's8'): 0.24999999999990843,
('fn2', 'ns2'): 0.3333333333331982,
('l3', 'ns2', 's2'): 0.14140127388531556,
('f2', 'l4', 'ns2', 'o1', 's6'): 0.070700636942677392,
('f2', 'l4', 'ns3', 'o1', 's2'): 0.0,
('l1', 'o1', 's3'): 0.0,
('f2', 'l2', 'ns3', 'o1', 's6'): 0.070700636942677392,
('ch1', 'ns3'): 0.14140127388531556,
('b1', 'f2', 'l2', 'o1', 's6'): 0.11953290870485991}

Average number of balloons purchased of each color in a random minimal solution:
{'f1': 0.99999999999967293
'f2': 0.99999999999986888
'f3': 1.0000000000026534
'b1': 1.4755838641183987
'b2': 1.0000000000026534
'fn5': 1.4755838641183987
's8': 1.7500000000008102
'fn3': 0.99999999999959455
'fn2': 1.0000000000006011
'fn1': 1.000000000001124
's3': 1.0000000000026534
's2': 0.99999999999967293
's1': 0.99999999999963385
's7': 1.0000000000026534
's6': 0.99999999999986888
's5': 0.99999999999967293
's4': 1.3333333333348059
'o1': 5.2500000000058433
'fn4': 1.0000000000006011
'ns1': 1.0000000000026534
'ns2': 1.7070063694272184
'ns3': 1.8662420382169833
'ns4': 1.4755838641183987
'ch1': 0.99999999999967293
'l4': 1.5000000000025882
'l5': 1.2500000000009932
'l2': 1.4999999999996076
'l3': 0.99999999999967293
'l1': 1.0000000000026534
'ch2': 0.99999999999967293}
USPI minimalist design collage
image
designset
Treasury Seals Type Set
Sign In or Register to comment.