% bottles3.pl

% Solution based on list processing
%

bottles(X) :-
	create_bottles(X,Stock),
	take_bottles(Stock).
	
create_bottles(0,[]).
create_bottles(Max,[Max|Bottles]) :-
	NewMax is Max - 1,
	create_bottles(NewMax,Bottles).

take_bottles([]) :-
	format("Now, they are all gone.").
take_bottles([1]) :-
	format("1 bottle of beer on the wall. "),
	take_one,
	take_bottles([]).
take_bottles([Bottle|Bottles]) :-
	format("~d bottles of beer on the wall. ", Bottle),
	take_one,
	take_bottles(Bottles).

take_one :-
	format("Take one down, and pass it around.\n").
