Cheryl's birthday: Difference between revisions

m
Line 1,697:
local function isvalid(k,v) return v.valid end
local function invalidate(k,v) v.valid = false end
local function remaining() return filter(choices, isvalid) end
 
local function remaininglistValidChoices()
io.write(" ")
apply(filterremaining(choices, isvalid), function(k,v) io.write(v.mon.."/"..v.day..", ") end)
print("\n")
end
 
print("Cheryl offers these ten choices:")
listValidChoices()
remaining()
 
print("1a1) Albert knows monththat butBernard notalso daycannot yet know, so month cannot be a month with a unique, obviously/redundantlyday, leaving still:")
apply(filterremaining(choices, isvalid), function(k,v)
if count(filter(choices, function(k2,v2) return v2.valid and v.mon==v2.mon end)) == 1 then
apply(filter(choices, function(k2,v2) return v2.valid and v.mon==v2.mon end), invalidate)
end
end)
remaining()
 
print("1b) Albert also knows that Bernard cannot yet know, so cannot be a month with a unique day, leaving:")
apply(filter(choices, isvalid), function(k,v)
if count(filter(choices, function(k2,v2) return v.day==v2.day end)) == 1 then
apply(filter(choices, function(k2,v2) return v2.valid and v.mon==v2.mon end), invalidate)
end
end)
listValidChoices()
remaining()
 
print("2) After Albert's revelation, Bernard now knows, so day must be unique, leaving:")
apply(filterremaining(choices, isvalid), function(k,v)
if count(filter(choices, function(k2,v2) return v2.valid and v.day==v2.day end)) > 1 then
apply(filter(choices, function(k2,v2) return v2.valid and v.day==v2.day end), invalidate)
end
end)
listValidChoices()
remaining()
 
print("3) After Bernard's revelation, Albert now knows, so month must be unique, leaving only:")
apply(filterremaining(choices, isvalid), function(k,v)
if count(filter(choices, function(k2,v2) return v2.valid and v.mon==v2.mon end)) > 1 then
apply(filter(choices, function(k2,v2) return v2.valid and v.mon==v2.mon end), invalidate)
end
end)
remaininglistValidChoices()</lang>
{{out}}
<pre>Cheryl offers these ten choices:
5/15, 5/16, 5/19, 6/17, 6/18, 7/14, 7/16, 8/14, 8/15, 8/17,
 
1a) Albert knows month but not day, so month cannot be unique, (obviously/redundantly), leaving still:
5/15, 5/16, 5/19, 6/17, 6/18, 7/14, 7/16, 8/14, 8/15, 8/17,
 
Anonymous user