AoC Benchmarks

aoc2021-day06b Common Lisp/SBCL program

source code


;; SPDX-License-Identifier: LGPL-3.0-or-later
;; Copyright (C) 2021 Massimo Zaniboni <mzan@dokmelody.org>

;; WARNING: I'm learning CL

(ql:quickload :trivia)     ;; common macro and functions and optimal pattern matching
(ql:quickload :alexandria) ;; common CL extensions
(ql:quickload :trivial-types)  ;; common types
(ql:quickload :defstar)    ;; add type annotations
(ql:quickload :str)        ;; Common string manipulation functions
(ql:quickload :parse-float)
(ql:quickload :iterate)
(ql:quickload :let-plus)          ;; extend "let"
(ql:quickload :array-operations)  ;; rich management of arrays

(defpackage :main
  (:import-from :alexandria)
  (:import-from :trivial-types :proper-list :tuple)
  (:use :cl :defstar :trivia :parse-float :iterate :let-plus)
  (:export main))

(in-package :main)

(declaim (optimize (speed 3) (debug 0) (safety 0)))

(defun make-empty-group-arr ()
  (make-array 9 :element-type 'integer :initial-element 0))

(defun group-arr-init! (arr initial-group)
  (iter (for n in-sequence initial-group)
        (after-each (incf (aref arr n)))))

(defun day6a ()
  (let* ((in *standard-input*)
           (initial-group (map 'list #'parse-integer (str:split-omit-nulls "," (read-line in))))
           (days (parse-integer (read-line in)))
           (arr1 (make-empty-group-arr))
           (arr2 (make-empty-group-arr)))

    (group-arr-init! arr1 initial-group)

    (iter (for day from 1 to days)
          (after-each
            (let* ((g0 (aref arr1 0))
                   (g7 (aref arr1 7))
                   (g8 (aref arr1 8)))

               (iter (for i from 1 to 6)
                     (for j = (- i 1))
                     (after-each
                      (setf (aref arr2 j) (aref arr1 i))))

               (setf (aref arr2 8) g0)
               (setf (aref arr2 7) g8)
               (setf (aref arr2 6) (+ g0 g7))
               (rotatef arr1 arr2)))

          (finally
             (return
               (values
                  (iter (for n in-sequence arr1) (sum n))
                  arr1))))))

(defun main () (format t "~a~%" (day6a)))
    

notes, command-line, and program output

NOTES:
Linux


Sun, 23 Jan 2022 14:22:24 GMT

MAKE:
sbcl --disable-debugger --load "aoc2021_day06b.lisp-1.lisp" --eval "(sb-ext:save-lisp-and-die \"app_lisp\" :executable t  :toplevel #'main:main)"
This is SBCL 2.1.11, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
To load "trivia":
  Load 1 ASDF system:
    trivia
; Loading "trivia"

To load "alexandria":
  Load 1 ASDF system:
    alexandria
; Loading "alexandria"

To load "trivial-types":
  Load 1 ASDF system:
    trivial-types
; Loading "trivial-types"

To load "defstar":
  Load 1 ASDF system:
    defstar
; Loading "defstar"

To load "str":
  Load 1 ASDF system:
    str
; Loading "str"
...
To load "parse-float":
  Load 1 ASDF system:
    parse-float
; Loading "parse-float"

To load "iterate":
  Load 1 ASDF system:
    iterate
; Loading "iterate"

To load "let-plus":
  Load 1 ASDF system:
    let-plus
; Loading "let-plus"

To load "array-operations":
  Load 1 ASDF system:
    array-operations
; Loading "array-operations"

[undoing binding stack and other enclosing state... done]
[performing final GC... done]
[defragmenting immobile space... (fin,inst,fdefn,code,sym)=1172+996+19861+20291+25972... done]
[saving current Lisp image into app_lisp:
writing 0 bytes from the read-only space at 0x50000000
writing 736 bytes from the static space at 0x50100000
writing 48136192 bytes from the dynamic space at 0x1000000000
writing 2080768 bytes from the immobile space at 0x50200000
writing 13066240 bytes from the immobile space at 0x52a00000
done]

3.71s to complete and log all make actions

COMMAND LINE:
./app_lisp 0 < aoc2021_day06b-input3.txt

TIMED OUT after 1400s


PROGRAM OUTPUT: