Zebra puzzle: Difference between revisions

Content deleted Content added
Line 5,733:
colors.select!{|x| x.join[/GreenWhite/]};
 
dis =-> proc{|s,*a{| s.brk.zip(map{|w| a+a[-2,2]*9.map{|p| p.index(w)}.
map{|w,p| p.index wcompact[0]}.each_slice(2).map{|a,b| (a-b).abs}}
 
men.each{|m| colors.each{|c|
next unless dis["RedEnglishBlueNorwegian",c,m]==[0,1]
drinks.each{|d| next unless dis["DaneTeaCoffeeGreen",m,d,d,c]==[0,0]
smokes.each{|s|
next unless dis["YellowDunhillBluemasterBeerGermanPrince",
c,s,s,d,m,s]==[0,0,0]
pets.each{|p|
next unless dis["SwedeDogBirdsPallmallCatsBlendHorseDunhill",
m,p,p,s]==[0,0,1,1]
x = [p,m,c,d,s].transpose
puts "The #{x.find{|y|y[0]=="Zebra"}[1]} owns the zebra.",