commit deletes
This commit is contained in:
parent
776bba907c
commit
372c577f83
233 changed files with 0 additions and 6724 deletions
|
|
@ -1,15 +0,0 @@
|
|||
floor[x_,y_]:=Flatten[Position[y,x]][[1]]
|
||||
Select[Permutations[{"Baker","Cooper","Fletcher","Miller","Smith"}],
|
||||
( floor["Baker",#] < 5 )
|
||||
&&( Abs[floor["Fletcher",#] - floor["Cooper",#]] > 1 )
|
||||
&&( Abs[floor["Fletcher",#] - floor["Smith",#]] > 1 )
|
||||
&&( 1 < floor["Cooper",#] < floor["Miller",#] )
|
||||
&&( 1 < floor["Fletcher",#] < 5 )
|
||||
&] [[1]] //Reverse //Column
|
||||
|
||||
->
|
||||
Miller
|
||||
Fletcher
|
||||
Baker
|
||||
Cooper
|
||||
Smith
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
def dinesman(floors, names, criteria)
|
||||
# the "bindVars" method returns a context where the "name" variables are bound to values
|
||||
eval "
|
||||
def bindVars(#{names.map {|n| n.downcase}.join ','})
|
||||
return binding
|
||||
end
|
||||
"
|
||||
expression = criteria.map {|c| "(#{c.downcase})"}.join " and "
|
||||
|
||||
floors.permutation.each do |perm|
|
||||
b = bindVars *perm
|
||||
return b if b.eval(expression)
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
floors = (1..5).to_a
|
||||
names = %w(Baker Cooper Fletcher Miller Smith)
|
||||
criteria = [
|
||||
"Baker != 5",
|
||||
"Cooper != 1",
|
||||
"Fletcher != 1",
|
||||
"Fletcher != 5",
|
||||
"Miller > Cooper",
|
||||
"(Smith - Fletcher).abs != 1",
|
||||
"(Fletcher - Cooper).abs != 1",
|
||||
]
|
||||
|
||||
b = dinesman(floors, names, criteria)
|
||||
|
||||
if b.nil?
|
||||
puts "no solution"
|
||||
else
|
||||
puts "Found a solution:"
|
||||
len = names.map {|n| n.length}.max
|
||||
residents = names.inject({}) {|r, n| r[b.eval(n.downcase)] = n; r}
|
||||
floors.each {|f| puts " Floor #{f}: #{residents[f]}"}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue