The game of life is normally played on a grid. See http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life . You can imagine (as I was inspired by a nice old prof), a B23/S24 version of it played on the line. For the line version, the 4 significant neighbours of a cell are the next and second next cells at its right and left.
Write a set of Lisp functions to implement this variation of the game.
The main function must be (LifeLine conf gen), where conf is the initial configuration of the game – represented as a list containing the ‘relative’ coordinates of live cells, and gen is the number of generations the game is
to be played for. The output should be the sequence of configurations corresponding to each generation. For example (LifeLine ‘(1 2) 5) should produce the output:
(1 2)
(0 3)
(1 2)
(0 3)
(1 2)
(0 3)
While (LifeLine ‘(13 14 15 16 17) 8) should produce the output: (13 14 15 16 17)
(12 13 15 17 18) (11 13 14 15 16 17 19) (12 15 18) (13 14 16 17) (12 14 16 18) (13 14 15 16 17) (12 13 15 17 18) (11 13 14 15 16 17 19)
You may only use the following LISP functions and predicates
(car x) (cdr x) (cons x y)
(atom x) (null x) (eq x y) (equal x y) (numberp x) (listp x)
(eval y) (funcall x ...) (apply x y)
special forms (including logic connectives)
(defun ...) (defmacro ...) (let ((x y) (u v)...) z) (lambda (x y) ...)
(quote x) and its short form 'x (function y) as well as #' `( ...) (list a1 a2 ...)
(if x y z) (cond ... ) (and x y ...) (or x y ...) (not x) (mapcar f l)
and numeric operators and comparisons such as
(+ x y) (- x y) (* x y) (/ x y) (< x y) (mod x y) (floor x) (ceiling x) (> x y)
(= x y) (<= x y) (>= x y)
You may also use a combination of car and cdr, such as
(cadr ...), (cdaar ...)
as well as
(first x) (second x) (third x) ...
(rest x)
etc.
For printing purposes you may use the functions:
print
format
If you would like to use any other functions of forms, please talk to me.
- Roman numerals were the numerical system of the Roman Empire. They use the letters I,V,X,L,C,D,M to represent positive integers. The Wikipedia entry on roman numerals http://en.wikipedia.org/wiki/Roman_numerals describes rules for converting back and forth between Roman numerals and Arabic
Write a list set of Lisp functions to convert between the two numeric representations:
- roman-to-arabic – to convert a Roman numeral – given as the list of its letters- to the corresponding Arabic numeral
- arabic-to-roman – to convert an Arabic numeral – given as a regular number – to the corresponding Roman numeral – represented as a list of its
For example:
(roman-to-arabic ‘(M M X I I)) → 2012 (arabic-to-roman 1977) → (M C M L X X V I I)
NOTE: Your implementation must be consistent with the rules described in the Wikipedia’s roman numerals entry.