Posts Tagged ‘programming’

Study in Genesis using Prolog

Wednesday, September 16th, 2009

Do you know that the flood came in the year 1656, the year when the last of the patriachs, Methuselah, died?

The following piece of code tells me that:

born(adam,0).
/*born(X,Year):-
begot_age(adam,Year,X).*/
born(X,Year):-
begot_age(Y,Y1,X),
born(Y,Y2),
Year is Y1+Y2.
die(X,Year):-
born(X,Y1),
die_age(X,Y2),
Year is Y1+Y2.
alive(X,Year):-
born(X,Y1),
die(X,Y2),
Year < Y2,
Year > Y1.
contemporary(X,Y):-
born(X,Y1),
born(Y,Y2),
die(X,Y3),
die(Y,Y4),
Y3 > Y2,
Y4 > Y1.

begot_age(adam,130,seth).
begot_age(seth,105,enosh).
begot_age(enosh,90,kenan).
begot_age(kenan,70,mahalalel).
begot_age(mahalalel,65,jared).
begot_age(jared,162,enoch).
begot_age(enoch,65,methuselah).
begot_age(methuselah,187,lamech).
begot_age(lamech,182,noah).
begot_age(noah,500,shem).
begot_age(noah,500,ham).
begot_age(noah,500,japtheh).

die_age(adam,930).
die_age(seth,912).
die_age(enosh,905).
die_age(kenan,910).
die_age(mahalalel,895).
die_age(jared,962).
die_age(enoch,365).
die_age(methuselah,969).
die_age(lamech,777).
die_age(noah,950).
flood(noah,600).
flood_year(Y):-
flood(noah,X),
born(noah,Y1),
Y is X+Y1.