Created
September 24, 2019 13:37
-
-
Save jjbarr/93978d818a414083da39d73e429ccbe9 to your computer and use it in GitHub Desktop.
lisp genehealth solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require "uiop") | |
(read-line) ;;throwaway line | |
(defparameter *gene/health* | |
(map 'vector #'cons | |
(uiop:split-string (read-line) :separator " ") | |
(mapcar #'parse-integer (uiop:split-string (read-line) :separator " ")))) | |
(defun gene-match-head (gene/health genome) | |
(if (reduce (lambda (a b) (and a b)) | |
(map 'list #'eql (car gene/health) genome)) | |
(cdr gene/health) | |
nil)) | |
(defun get-genome-health (genome range) | |
;;no slices. bah. | |
(let ((genes (loop for i from (car range) to (cdr range) | |
collect (aref *gene/health* i)))) | |
(loop for g on genome | |
sum (reduce #'+ | |
(remove-if-not #'identity | |
(mapcar (lambda (gene) | |
(gene-match-head gene g)) | |
genes)))))) | |
(read-line) | |
(let ((minmax (do* ((l (read-line t nil) | |
(read-line t nil)) | |
(max nil) | |
(min nil)) | |
((not l) (list min max)) | |
(destructuring-bind (start-str end-str genome) | |
(uiop:split-string l :separator " ") | |
(let ((health (get-genome-health (coerce genome 'list) | |
(cons | |
(parse-integer start-str) | |
(parse-integer end-str))))) | |
(if max (setf max (max health max)) | |
(setf max health)) | |
(if min (setf min (min health min)) | |
(setf min health))))))) | |
(format t "~A ~A~%" (car minmax) (cadr minmax))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment