I am not looking for the answer, only a direction to take this assignment. I need to find the max rating of a list of songs that will fit on a given cd size.
example:
song rating filesize
Song1 5 600
Song2 4 200
Song3 2 400
If I had 400 space on the CD, Song2 and Song3 would go on because they have a max rating of 4+2=6, vs only 5 for song1.
So far I have:
% Song data
song( song1, 1, 200000 ).
song( song2, 2, 300000 ).
song( song3, 5, 400000 ).
% Rules
% Trivial Case
burnCD( SizeOfCD, [], CDBurnList ).
% Recursive algorithm
burnCD( SizeOfCD, [Item|Rest], L ) :-
song( Title, Rating, Size ),
burnCD( SizeOfCD - Size, Rest, L ),
burnCD( SizeOfCD - Size, Rest, L ).
burnCD( SizeOfCD, [Item|Rest], L ) :-
song( SongTitle, SongRating, SongSize ),
getTotalRating( R, TotalRating ) >
getTotalRating( L, TotalRating ),
NewSizeOfCD is SizeOfCD - SongSize.
getTotalRating( [Item|Rest], Result ) :-
song( _, Rating, _),
Result is Result + Rating.
First question I have is this: When I run trace, it is only going through the first songs data. Why is this?
example:
song rating filesize
Song1 5 600
Song2 4 200
Song3 2 400
If I had 400 space on the CD, Song2 and Song3 would go on because they have a max rating of 4+2=6, vs only 5 for song1.
So far I have:
% Song data
song( song1, 1, 200000 ).
song( song2, 2, 300000 ).
song( song3, 5, 400000 ).
% Rules
% Trivial Case
burnCD( SizeOfCD, [], CDBurnList ).
% Recursive algorithm
burnCD( SizeOfCD, [Item|Rest], L ) :-
song( Title, Rating, Size ),
burnCD( SizeOfCD - Size, Rest, L ),
burnCD( SizeOfCD - Size, Rest, L ).
burnCD( SizeOfCD, [Item|Rest], L ) :-
song( SongTitle, SongRating, SongSize ),
getTotalRating( R, TotalRating ) >
getTotalRating( L, TotalRating ),
NewSizeOfCD is SizeOfCD - SongSize.
getTotalRating( [Item|Rest], Result ) :-
song( _, Rating, _),
Result is Result + Rating.
First question I have is this: When I run trace, it is only going through the first songs data. Why is this?