4 ms·
Of course, Prolog makes it easy too. ?- member(Fruit,[0,1,2,3,4,5,6,7]), member(Fries,[0,1,2,3,4,5,6,7]), member(Salad,[0,1,2,3,4,5]),
by lake99 13y ago
Of course, Prolog makes it easy too.
?- member(Fruit,[0,1,2,3,4,5,6,7]),
member(Fries,[0,1,2,3,4,5,6,7]),
member(Salad,[0,1,2,3,4,5]),
member(Wings,[0,1,2,3,4]),
member(Sticks,[0,1,2,3]),
member(Sampler,[0,1,2]),
1505 is Fruit*215 + Fries*275 + Salad*335 + Wings*355 + Sticks*420 + Sampler*580.
Fruit = Sampler, Sampler = 1,
Fries = Salad, Salad = Sticks, Sticks = 0,
Wings = 2 ; % << END OF ANSWER #1
Fruit = 7,
Fries = Salad, Salad = Wings, Wings = Sticks, Sticks = Sampler, Sampler = 0 ; % << END OF ANSWER #2
false.
- maaaats 13y agoAs a person not heavily invested in Prolog, can you explain how that works? Is it just branching by choices from the different groups and it backtracks/fails back up to the last choice if constraints are not met?
- kaoD 13y agoPretty much that, yeah. http://en.wikipedia.org/wiki/Unification_%28computer_science%29#Unification_in_logic_programming http://en.wikipedia.org/wiki/Unification_%28computer_science...