(defpackage #:calorie-count
(:use :cl))
(in-package #:calorie-count)
(defvar calorie-list (list '()))
(with-open-file (s "/tmp/list")
(loop for line = (read-line s nil)
while line do (
if (string= line "")
(setf calorie-list (cons '() calorie-list))
(let ((x (car calorie-list)) (y (cdr calorie-list)))
(setf x (cons (parse-integer line) x))
(setf calorie-list (cons x y))))))
(defun max-index (max-val vals start-index)
(let ((val (car vals)) (vals (cdr vals)))
(cond ((not val) nil)
((eql val max-val) start-index)
(t (max-index max-val vals (1+ start-index))))))
(print calorie-list)
(let ((elf-list (sort (mapcar #'(lambda (l) (reduce #'+ l)) (reverse calorie-list)) #'>)))
(let ((max-elfs (subseq elf-list 0 3)))
(progn (print (apply #'+ max-elfs)))))