;;; solver.el --- Solution for AoC 2022 day 1 -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2022 Óscar Nájera
;;
;; Author: Óscar Nájera <hi@oscarnajera.com>
;; Maintainer: Óscar Nájera <hi@oscarnajera.com>
;; Created: December 02, 2022
;; Modified: December 02, 2022
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Solution for AoC 2022 day 1
;;
;;; Code:
(require 'seq)
(require 'subr-x)
(defun solver-elves-rations ()
(with-temp-buffer
(insert-file-contents "input")
(thread-last
(split-string (buffer-string) "\n\n")
(mapcar
(lambda (elf)
(seq-reduce (lambda (acc x)
(+ acc (string-to-number x)))
(split-string elf) 0))))))
(ert-deftest solutions ()
(let ((rations (solver-elves-rations)))
;; calculate the maximum from each elves rations
(should (= 75622 (apply #'max rations)))
;; calculate the maximum from each elves rations
(should (= 213159 (apply #'+ (seq-take (sort rations #'>) 3))))))