blob: 8dba125d0dbbdf3aaffbed9b216d2a464cf57f81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
;;; 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))))))
|