% Musterloesungen Sitzung 20.04. % Schreiben Sie ein Prädikat icecream/1, das die folgenden Bilder von Eistüten erzeugt. % Das Argument gibt die Höhe des Eisbergs an: % % % ?- icecream(1). % () % /\/\ % \ / % \/ % % ?- icecream(2). % % () % (()) % /\/\/\ % \ / % \ / % \/ % % ?- icecream(3). % % () % (()) % (( )) % /\/\/\/\ % \ / % \ / % \ / % \/ % % ?- icecream(4). % % () % (()) % (( )) % (( )) % /\/\/\/\/\ % \ / % \ / % \ / % \ / % \/ % icecream(N):- icepeak(N), icetop(N), icemid(N), icebottom(N). icepeak(N) :- tab(N), write('()'), nl. icetop(N) :- V is N-1, icetop(V, 0). icetop(0, _). icetop(V, M) :- tab(V), write('(('), tab(M), write('))'), nl, NewV is V-1, NewM is M+2, icetop(NewV, NewM). icemid(0) :- write('/'), write('\\'), nl. icemid(N) :- write('/'), write('\\'), A is N-1, icemid(A). icebottom(N) :- icebottom(0,N). icebottom(N,0) :- tab(N), write('\\/'). icebottom(N,M) :- tab(N), write('\\'), DoubleM is M*2, tab(DoubleM), write('/'), nl, NewN is N+1, NewM is M-1, icebottom(NewN, NewM). % Bonus: cake % % ?- cake(2). % /\ /\ /\ /\ /\ % \/ \/ \/ \/ \/ % || || || || || % || || || || || % oooooooooooooooooooo % o/\oo/\oo/\oo/\oo/\o % o\/oo\/oo\/oo\/oo\/o % oooooooooooooooooooo % % % % % ?- cake(3). % /\ /\ /\ /\ /\ % \/ \/ \/ \/ \/ % || || || || || % || || || || || % || || || || || % || || || || || % oooooooooooooooooooooooooooooo % oo/\oooo/\oooo/\oooo/\oooo/\oo % o/xx\oo/xx\oo/xx\oo/xx\oo/xx\o % o\xx/oo\xx/oo\xx/oo\xx/oo\xx/o % oo\/oooo\/oooo\/oooo\/oooo\/oo % oooooooooooooooooooooooooooooo % % % ?- cake(4). % /\ /\ /\ /\ /\ % \/ \/ \/ \/ \/ % || || || || || % || || || || || % || || || || || % || || || || || % || || || || || % || || || || || % oooooooooooooooooooooooooooooooooooooooo % ooo/\oooooo/\oooooo/\oooooo/\oooooo/\ooo % oo/xx\oooo/xx\oooo/xx\oooo/xx\oooo/xx\oo % o/xxxx\oo/xxxx\oo/xxxx\oo/xxxx\oo/xxxx\o % o\xxxx/oo\xxxx/oo\xxxx/oo\xxxx/oo\xxxx/o % oo\xx/oooo\xx/oooo\xx/oooo\xx/oooo\xx/oo % ooo\/oooooo\/oooooo\/oooooo\/oooooo\/ooo % oooooooooooooooooooooooooooooooooooooooo rep(_,0). rep(Str,N) :- write(Str), N1 is N-1, rep(Str,N1). candles(N) :- N1 is N-1, candle1(5,N1,'/\\'),nl, candle1(5,N1,'\\/'),nl, N2 is N1*2, cbottom(N2,N1),!. candle1(0,_,_). candle1(N,Indent,Str) :- rep(' ',Indent), write(Str), rep(' ',Indent), N1 is N-1, candle1(N1,Indent,Str),!. cbottom(0,_). cbottom(N,Indent) :- candle1(5,Indent,'||'),nl, N1 is N-1, cbottom(N1,Indent),!. cakebody(N) :- Width is N*10, N1 is N-1, rep('o',Width),nl, diamondt('/','\\',N1,1), diamondb('\\','/',N1,1), rep('o',Width),nl,!. diamondt(Front,End,1,Indent) :- diamondline(Front,End,0,Indent,5),!. diamondt(Front,End,N,Indent) :- N1 is N-1, I1 is Indent+1, C is N1*2, diamondt(Front,End,N1,I1), diamondline(Front,End,C,Indent,5),!. diamondline(_,_,_,_,0) :- nl,!. diamondline(Front,End,Space,Indent,N) :- rep('o',Indent), write(Front), rep('x',Space), write(End), rep('o',Indent), N1 is N-1, diamondline(Front,End,Space,Indent,N1),!. diamondb(Front,End,1,Indent) :- diamondline(Front,End,0,Indent,5),!. diamondb(Front,End,N,Indent) :- N1 is N-1, I1 is Indent+1, C is N1*2, diamondline(Front,End,C,Indent,5), diamondb(Front,End,N1,I1),!. cake(N) :- candles(N), cakebody(N),!.