Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% https://xkcd.com/287/ subset_sum(Total, _, []) :- Total = 0. subset_sum(Total, [PricesHead|_], [PricesHead]) :- Total = PricesHead. subset_sum(Total, [PricesHead|PricesTail], [PricesHead|BuyTail]) :- RemainingTotal is Total - PricesHead, RemainingTotal > 0, subset_sum(RemainingTotal, [PricesHead|PricesTail], BuyTail). subset_sum(Total, [_|PricesTail], Buy) :- subset_sum(Total, PricesTail, Buy). % The order was for "$15.05 worth of appetizers", % which would not include the $6.55 barbecue sandwitch. % (Apparently this hobby also involves giving ambiguous orders; % two different sets of appetizers are available at that price) % % findall(OrderedItems, order_appetizers(OrderedItems), ValidOrders) order_appetizers(OrderedItems) :- subset_sum(1505, [215, 275, 335, 355, 420, 580], OrderedItems). % If the sandwitch is included as a possible itme being ordered, % an additional order is possible. % % findall(OrderedItems, order_full_menu(OrderedItems), ValidOrders) order_full_menu(OrderedItems) :- subset_sum(1505, [215, 275, 335, 355, 420, 580, 655], OrderedItems). /** <examples> ?- findall(OrderedItems, order_appetizers(OrderedItems), ValidOrders). ?- findall(OrderedItems, order_full_menu(OrderedItems), ValidOrders). */