I have an order of facts, below is an example:
nutrition(cheeseburger, 300, 12, 33, 15).
nutrition(hamburger, 250, 9, 31, 12).
nutrition(chickenPieces, 270, 16, 19, 14).
In these examples the first atom is a food, the second is the number of calories, third is the fat, fourth is the number of carbohydrates, and fifth is the amount of protein.
What I'm trying to do is output these items based on the amount of fat in each. My initial idea is to use an iterator and go from 0 to 100 fat, but seeing as iteration isn't a possibility in Prolog, I can't figure out a good approach to take. If ordered correctly the output would be:
hamburger
250
9
31
12
cheeseburger
300
12
33
15
...
My other idea is to put all of the fat amounts into a list, but when I recurse the order starts over again. That idea is implemented below:
sort_menu(M, TC, F, C, P, Z) :- nutrition(M, TC, F, C, P),
sort_menu(M, TC, F, C, P, [F|Z]).
nutrition(cheeseburger, 300, 12, 33, 15).
nutrition(hamburger, 250, 9, 31, 12).
nutrition(chickenPieces, 270, 16, 19, 14).
In these examples the first atom is a food, the second is the number of calories, third is the fat, fourth is the number of carbohydrates, and fifth is the amount of protein.
What I'm trying to do is output these items based on the amount of fat in each. My initial idea is to use an iterator and go from 0 to 100 fat, but seeing as iteration isn't a possibility in Prolog, I can't figure out a good approach to take. If ordered correctly the output would be:
hamburger
250
9
31
12
cheeseburger
300
12
33
15
...
My other idea is to put all of the fat amounts into a list, but when I recurse the order starts over again. That idea is implemented below:
sort_menu(M, TC, F, C, P, Z) :- nutrition(M, TC, F, C, P),
sort_menu(M, TC, F, C, P, [F|Z]).