src/problems/fibd.lisp @ e3aefcbf364c

Cache Uniprot results on the filesystem

This will make only the first `(run-tests)` on a given computer take forever,
instead of the first `(run-tests)` of a given Lisp session.  It will also
hopefully make the Uniprot folks not hate me.
author Steve Losh <steve@stevelosh.com>
date Fri, 24 Jan 2020 23:05:16 -0500
parents 2735aa6aab79
children (none)
(defpackage :rosalind/fibd (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/fibd)

(define-problem fibd (data stream)
    "6 3"
    "4"
  (iterate
    (with months = (read data))
    (with lifespan = (read data))
    (for month :from 2 :to months)
    (labels ((ref (array index)
               (if (plusp index)
                 (aref array index)
                 0))
             (breeding (month)
               (- (ref population (- month 1))
                  (deaths month)))
             (births (month)
               (breeding (- month 1)))
             (deaths (month)
               (ref births (- month lifespan)))
             (population (month)
               (+ (breeding month)
                  (births month))))
      ;; We initialize the buffers with NIL in index 0 for the 1-based months,
      ;; and 1 in index 0 for the initial pair of rabbits.
      (u:buffering (u:returning-final (population month))
                   :into population
                   :initial-contents '(nil 1))
      (u:buffering (births month)
                   :into births
                   :initial-contents '(nil 1)))))


#; Scratch --------------------------------------------------------------------
(problem-fibd "45 6")
;; (solve fibd)