has_vowel(Atom) :-
	atom_chars(Atom,Chars),
	member(Char,Chars),
	member(Char,[a,e,i,o,u]).

printN(0).
printN(N) :- N > 0, M is N - 1, printN(M), writeln(N).

sumN(0,0).
sumN(N,Sum) :-
	N > 0, M is N - 1, sumN(M, Temp), Sum is Temp + N.

factorial(0,1). 

factorial(N,F) :-  
   N > 0, 
   N1 is N - 1, 
   factorial(N1,F1), 
   F is N * F1.

odd(1).
odd(N) :- odd(M), N is M + 2.

sumGreater(Target,N,Sum) :- between(1,inf,N), numlist(1,N,L), sumlist(L,Sum), Sum > Target.

starts_with(L, Prefix) :-
    append(Prefix,_,L).

take(L, N, Result) :-
    length(Result,N), append(Result, _, L).

take2(L, N, Result) :-
    append(Result, _, L), length(Result,N).

drop(L, N, Result) :-
    length(Dropped, N), append(Dropped, Result, L).

chunk(L,N,Chunk) :-
    length(Chunk,N),
    append(Chunk,_,L).

chunk(L,N,Chunk) :-
    length(Junk, N),
    append(Junk,Rest,L),
    chunk(Rest,N,Chunk).






	
first_last(L,First) :- append([First],_,L).
first_last(L,Last) :- append(_,[Last],L).












first_(L,First) :- append([First],_,L).
last_(L,Last) :- append(_,[Last],L).

first_last2(L,X) :- first_(L,X).
first_last2(L,X) :- last_(L,X).

head([X|_],X).

mem1(X,L) :- L = [X|_].
mem1(X,L) :- L = [_|T], mem1(X, T).

mem2(X,[X|_]).
mem2(X,[_|T]) :- mem2(X, T).

last1([X],X).
last1([_|T],X) :- last1(T,X).

len([], 0).
len([_|T],Len) :- len(T,TLen), Len is TLen + 1.

allsame([_]).
allsame([X,X|T]) :- allsame([X|T]).

listeq([],[]).
listeq([H|T],[H|T]) :- listeq(T,T).

listeq2([],[]).
listeq2([H|T],[H|T]).

myapp([], X, X).
myapp([X|L1], L2, [X|L3]) :-  myapp(L1, L2, L3).

% From Clause and Effect, p.43
drink(milk) :- true.       % Equivalent to drink(milk).
drink(beer) :- true, !.
drink(gin) :- true.


f(' f1 ').
f(' f2 ').
f(' f3 ').
g(' g1 ').
g(' g2 ').
g(' g3 ').

ce1(one,1) :- true.			% Equivalent to ce1(one,1).
ce1(two,2) :- true, !.
ce1(_, 'something') :- true.

grade(S,'A') :- S >= 90.
grade(S,'B') :- S >= 80, S < 90.
grade(S,'C') :- S >= 70, S < 80.
grade(S,'F') :- S < 70.


grade2(Score, 'A') :- Score >= 90.
grade2(Score, 'B') :- Score >= 80.
grade2(Score, 'C') :- Score >= 70.
grade2(_, 'F').

grade3(Score, 'A') :- Score >= 90, !.
grade3(Score, 'B') :- Score >= 80, !.
grade3(Score, 'C') :- Score >= 70, !.
grade3(_, 'F').

do_grades(Students) :-
    member(Who-Avg, Students),
    grade3(Avg,Grade),
    format('~w: ~w~n', [Who, Grade]), fail.


max0(X, Y, X) :- X >= Y.
max0(X, Y, Y) :- X < Y.

max(X,Y,X) :- X >= Y, !.
max(_,Y,Y).

/*
allpos([X]) :- X > 0.
allpos([X|T]) :- X > 0, allpos(T).
*/

allpos(L) :- member(X, L), X =< 0, !, fail.
allpos(_).

cant_prove(G) :- call(G), !, fail.
cant_prove(_).

% agf(F) :- food(F), color(F,green), !.

% makefoods and assert/retract predicates are in foods3.pl
