I just wrote a computer program to calculate the importance of food
versus water versus heat in survival in Prolog:
http://github.com/metaperl/metaphysics/blob/master/survival/survival.prolog
And it was sheer joy. Time to buy a book on Prolog, I think "Learn
Prolog Now" is what I will get unless there are other suggestions?
weeks_to_seconds(W,S) :- D is 7*W, days_to_seconds(D,S).
days_to_seconds(D,S) :- H is D*24, M is 60*H, S is 60*M.
% Can survive without adequate heat for 1 second
survive_without(heat,1).
% Can survive without water for 7 days (3-5 days cited)
% http://en.wikipedia.org/wiki/Survival_skills#Water
% comes out to 604,800 seconds
survive_without(water,X) :- days_to_seconds(7,X).
% If Mahatma Gandhi can live on water for 21 days at age 74, then
% any average person could expect to do the same
% http://www.scientificamerican.com/article.cfm?id=how-long-can-a-person-sur
% comes out to 1,814,400 seconds
survive_without(food,X) :- weeks_to_seconds(3,X).
more_important(N1,N2,I) :-
survive_without(N1,S1),
survive_without(N2,S2),
I is S2 / S1.
% Conclusions (based on survival levels, not necessarily optimal)
% ---------------------------------------------------------------
% water is 3 times more important than food
% heat is 600,000 times more important than water
% Given that the body is 70 percent water, and that every
% process in the body requires water, it is no surprise that water
% is many times more important than food.
> And it was sheer joy. Time to buy a book on Prolog, I think "Learn
> Prolog Now" is what I will get unless there are other suggestions?
There is an online version at http://www.learnprolognow.org/
It is "old" but very good as a starter. Make sure you have SWI with you:
it is a hands-on book. Skip the part on DCGs.
This book will keep your enthusiasm high, and it does not dig deep:
you should be able to cover it in a few evenings.
After a while, you might want to look at books by Bratko
or Sterling&Shapiro or O'Keefe.
Don't run before you have enjoyed walking.
And keep posting your programs !
Cheers
Bart Demoen
ps. very nice Subject line !
Walk through the P-99: Night-nine Prolog Problems,
https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/ , and you will
learn a lot. :)
> weeks_to_seconds(W,S) :- D is 7*W, days_to_seconds(D,S).
> days_to_seconds(D,S) :- H is D*24, M is 60*H, S is 60*M.
>
> % Can survive without adequate heat for 1 second
> survive_without(heat,1).
>
> % Can survive without water for 7 days (3-5 days cited)
> %http://en.wikipedia.org/wiki/Survival_skills#Water
> % comes out to 604,800 seconds
> survive_without(water,X) :- days_to_seconds(7,X).
>
> % If Mahatma Gandhi can live on water for 21 days at age 74, then
> % any average person could expect to do the same
> %http://www.scientificamerican.com/article.cfm?id=how-long-can-a-perso...
> % comes out to 1,814,400 seconds
> survive_without(food,X) :- weeks_to_seconds(3,X).
>
> more_important(N1,N2,I) :-
> survive_without(N1,S1),
> survive_without(N2,S2),
> I is S2 / S1.
>
> % Conclusions (based on survival levels, not necessarily optimal)
> % ---------------------------------------------------------------
> % water is 3 times more important than food
> % heat is 600,000 times more important than water
>
> % Given that the body is 70 percent water, and that every
> % process in the body requires water, it is no surprise that water
> % is many times more important than food.
The elements for survival program is to describe a sentence "Water is
more important than food, and heat is even more important than water."
Interesting!
A beginners comment:
I haven't read "Learn Prolog Now", but have started with Bratko, simply
because I acquired that book some years ago (must have gotten
sidetracked). Apart from the earlier (minor) complaint about "different"
predicate, the book seems well written, and interesting. I managed to
complete first three chapters without serious problems (with all
exercises solved without peeking). However, it probably depends on one's
background as a programmer. Mine is FP. As chapter #3 deals with lists
and recursion, I probably would not have done that well with the book
alone, because Bratko's explanation of recursive process is very terse.
- Hrvoje