blob: fe8749ccdaa1416567c1fd399e578fa6263db631 (
plain) (
tree)
|
|
;;; Solve logic problems by pure backtracking
to track :lists :tests
foreach first :lists [make ? array count bf :lists]
catch "tracked [track1 first :lists bf :lists 1]
end
to track1 :master :others :index
if emptyp :others [tracktest stop]
track2 :master first :others bf :others
end
to track2 :names :these :those
if emptyp :these [track1 :master :those :index+1 stop]
foreach :these [setitem :index thing first :names ?
track2 bf :names remove ? :these :those]
end
to tracktest
foreach :tests [if not run ? [stop]]
foreach :master [pr se ? arraytolist thing ?]
throw "tracked
end
to is :this :that
if memberp :this :master [output memberp :that thing :this]
if memberp :that :master [output memberp :this thing :that]
localmake "who find [memberp :this thing ?] :master
output memberp :that thing :who
end
to differ :things
if emptyp bf :things [op "true]
op and (differ1 first :things bf :things) (differ bf :things)
end
to differ1 :this :those
foreach :those [if is :this ? [output "false]]
output "true
end
|