Anonymous user
Cheryl's birthday: Difference between revisions
m
→{{header|Lua}}
m (→{{header|Lua}}) |
|||
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
io.write(" ")
apply(
print("\n")
end
print("Cheryl offers these ten choices:")
listValidChoices()
print("
apply(
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()
print("2) After Albert's revelation, Bernard now knows, so day must be unique, leaving:")
apply(
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()
print("3) After Bernard's revelation, Albert now knows, so month must be unique, leaving only:")
apply(
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)
{{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
5/15, 5/16, 5/19, 6/17, 6/18, 7/14, 7/16, 8/14, 8/15, 8/17,
|