From 41ffa60a36284e087545bdcf413f7bb4b7c23369 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Mon, 5 Dec 2022 12:46:56 +0100 Subject: [AoC2022] Elisp 05-01 --- AoC2022/05/input | 512 +++++++++++++++++++++++++++++++++++++++++++++++++++ AoC2022/05/makefile | 15 ++ AoC2022/05/solver.el | 50 +++++ 3 files changed, 577 insertions(+) create mode 100644 AoC2022/05/input create mode 100644 AoC2022/05/makefile create mode 100644 AoC2022/05/solver.el (limited to 'AoC2022') diff --git a/AoC2022/05/input b/AoC2022/05/input new file mode 100644 index 0000000..c1f5fb0 --- /dev/null +++ b/AoC2022/05/input @@ -0,0 +1,512 @@ +[T] [D] [L] +[R] [S] [G] [P] [H] +[G] [H] [W] [R] [L] [P] +[W] [G] [F] [H] [S] [M] [L] +[Q] [V] [B] [J] [H] [N] [R] [N] +[M] [R] [R] [P] [M] [T] [H] [Q] [C] +[F] [F] [Z] [H] [S] [Z] [T] [D] [S] +[P] [H] [P] [Q] [P] [M] [P] [F] [D] + 1 2 3 4 5 6 7 8 9 + +move 3 from 8 to 9 +move 2 from 2 to 8 +move 5 from 4 to 2 +move 7 from 1 to 4 +move 3 from 8 to 2 +move 3 from 2 to 7 +move 1 from 7 to 4 +move 3 from 2 to 9 +move 4 from 7 to 9 +move 1 from 5 to 2 +move 2 from 3 to 4 +move 5 from 9 to 5 +move 6 from 9 to 3 +move 5 from 9 to 5 +move 1 from 9 to 7 +move 2 from 3 to 1 +move 7 from 3 to 9 +move 2 from 7 to 2 +move 5 from 2 to 4 +move 1 from 2 to 9 +move 2 from 1 to 9 +move 7 from 6 to 1 +move 2 from 7 to 3 +move 2 from 3 to 9 +move 1 from 7 to 4 +move 1 from 9 to 2 +move 3 from 1 to 8 +move 2 from 3 to 4 +move 5 from 9 to 2 +move 1 from 3 to 9 +move 8 from 5 to 7 +move 1 from 6 to 1 +move 15 from 4 to 1 +move 4 from 2 to 5 +move 5 from 9 to 7 +move 1 from 9 to 5 +move 5 from 1 to 2 +move 3 from 8 to 9 +move 1 from 7 to 6 +move 11 from 1 to 2 +move 7 from 5 to 3 +move 4 from 2 to 6 +move 7 from 3 to 4 +move 3 from 5 to 9 +move 2 from 2 to 5 +move 5 from 1 to 8 +move 2 from 6 to 8 +move 3 from 8 to 9 +move 9 from 4 to 9 +move 9 from 7 to 4 +move 2 from 8 to 1 +move 1 from 8 to 7 +move 6 from 2 to 7 +move 5 from 2 to 4 +move 5 from 7 to 2 +move 2 from 1 to 7 +move 2 from 6 to 4 +move 7 from 7 to 1 +move 3 from 2 to 6 +move 1 from 8 to 7 +move 2 from 9 to 3 +move 2 from 3 to 1 +move 1 from 2 to 5 +move 4 from 6 to 5 +move 2 from 2 to 3 +move 3 from 5 to 7 +move 1 from 5 to 3 +move 9 from 1 to 7 +move 2 from 9 to 5 +move 13 from 4 to 1 +move 5 from 7 to 2 +move 3 from 3 to 1 +move 2 from 2 to 9 +move 1 from 2 to 7 +move 5 from 5 to 6 +move 2 from 2 to 4 +move 5 from 1 to 3 +move 9 from 7 to 8 +move 2 from 9 to 5 +move 3 from 5 to 4 +move 5 from 9 to 2 +move 10 from 4 to 8 +move 1 from 4 to 1 +move 2 from 8 to 4 +move 4 from 8 to 2 +move 3 from 6 to 8 +move 7 from 8 to 7 +move 10 from 9 to 3 +move 7 from 3 to 2 +move 11 from 2 to 3 +move 13 from 3 to 9 +move 1 from 6 to 3 +move 1 from 1 to 2 +move 1 from 2 to 8 +move 3 from 3 to 4 +move 1 from 2 to 9 +move 1 from 4 to 1 +move 10 from 8 to 3 +move 11 from 9 to 7 +move 1 from 6 to 2 +move 14 from 7 to 1 +move 2 from 2 to 9 +move 4 from 7 to 6 +move 1 from 2 to 4 +move 3 from 4 to 2 +move 4 from 2 to 9 +move 10 from 3 to 4 +move 3 from 6 to 1 +move 5 from 9 to 5 +move 5 from 5 to 8 +move 1 from 9 to 7 +move 2 from 9 to 6 +move 1 from 9 to 8 +move 2 from 4 to 8 +move 1 from 4 to 5 +move 2 from 3 to 1 +move 2 from 3 to 7 +move 27 from 1 to 2 +move 2 from 7 to 1 +move 9 from 4 to 6 +move 9 from 6 to 5 +move 5 from 8 to 6 +move 26 from 2 to 3 +move 1 from 2 to 5 +move 1 from 2 to 7 +move 1 from 8 to 4 +move 1 from 7 to 8 +move 24 from 3 to 5 +move 1 from 8 to 5 +move 1 from 4 to 3 +move 1 from 7 to 1 +move 1 from 8 to 9 +move 7 from 1 to 7 +move 8 from 6 to 4 +move 4 from 7 to 6 +move 1 from 3 to 9 +move 2 from 9 to 1 +move 3 from 7 to 9 +move 8 from 4 to 6 +move 3 from 9 to 1 +move 1 from 3 to 6 +move 1 from 8 to 2 +move 10 from 5 to 4 +move 1 from 3 to 8 +move 13 from 5 to 3 +move 1 from 2 to 9 +move 1 from 8 to 9 +move 1 from 3 to 8 +move 1 from 9 to 2 +move 3 from 6 to 9 +move 7 from 4 to 9 +move 4 from 3 to 9 +move 2 from 6 to 8 +move 2 from 4 to 5 +move 10 from 9 to 3 +move 1 from 1 to 9 +move 1 from 4 to 8 +move 1 from 1 to 4 +move 1 from 4 to 5 +move 4 from 6 to 3 +move 1 from 9 to 5 +move 1 from 6 to 9 +move 2 from 6 to 5 +move 1 from 9 to 2 +move 1 from 6 to 7 +move 18 from 5 to 2 +move 22 from 3 to 7 +move 19 from 7 to 1 +move 3 from 8 to 5 +move 4 from 9 to 3 +move 2 from 7 to 2 +move 1 from 8 to 1 +move 19 from 1 to 3 +move 2 from 7 to 5 +move 13 from 3 to 9 +move 4 from 1 to 2 +move 3 from 5 to 1 +move 11 from 9 to 1 +move 11 from 2 to 8 +move 3 from 9 to 3 +move 3 from 5 to 2 +move 2 from 1 to 4 +move 5 from 2 to 7 +move 12 from 1 to 5 +move 2 from 4 to 5 +move 9 from 5 to 8 +move 1 from 5 to 3 +move 4 from 2 to 3 +move 2 from 7 to 5 +move 6 from 2 to 8 +move 17 from 8 to 9 +move 2 from 9 to 6 +move 2 from 7 to 1 +move 15 from 9 to 6 +move 2 from 2 to 4 +move 9 from 8 to 5 +move 2 from 1 to 3 +move 12 from 6 to 2 +move 2 from 3 to 9 +move 5 from 6 to 3 +move 4 from 5 to 3 +move 11 from 3 to 4 +move 2 from 9 to 4 +move 6 from 5 to 2 +move 13 from 4 to 3 +move 1 from 4 to 5 +move 1 from 4 to 8 +move 18 from 2 to 6 +move 2 from 5 to 3 +move 1 from 8 to 3 +move 1 from 2 to 5 +move 1 from 7 to 8 +move 28 from 3 to 6 +move 2 from 3 to 4 +move 3 from 5 to 9 +move 2 from 5 to 9 +move 3 from 9 to 3 +move 5 from 3 to 4 +move 1 from 9 to 3 +move 1 from 9 to 1 +move 1 from 3 to 4 +move 45 from 6 to 2 +move 1 from 8 to 3 +move 2 from 4 to 6 +move 5 from 4 to 2 +move 1 from 3 to 7 +move 3 from 2 to 9 +move 1 from 4 to 8 +move 3 from 6 to 1 +move 42 from 2 to 8 +move 2 from 9 to 2 +move 4 from 2 to 6 +move 2 from 2 to 7 +move 1 from 9 to 6 +move 2 from 8 to 9 +move 4 from 1 to 8 +move 1 from 6 to 4 +move 1 from 4 to 8 +move 1 from 2 to 5 +move 3 from 7 to 4 +move 39 from 8 to 3 +move 7 from 8 to 5 +move 8 from 5 to 7 +move 35 from 3 to 1 +move 4 from 3 to 7 +move 10 from 7 to 2 +move 2 from 9 to 6 +move 3 from 4 to 2 +move 1 from 7 to 5 +move 1 from 7 to 8 +move 1 from 5 to 4 +move 12 from 1 to 6 +move 1 from 8 to 1 +move 1 from 4 to 5 +move 14 from 6 to 8 +move 9 from 8 to 6 +move 5 from 6 to 1 +move 11 from 2 to 9 +move 1 from 9 to 8 +move 6 from 8 to 3 +move 6 from 9 to 2 +move 8 from 1 to 9 +move 3 from 3 to 6 +move 7 from 1 to 4 +move 1 from 5 to 9 +move 8 from 9 to 8 +move 7 from 6 to 8 +move 1 from 9 to 3 +move 3 from 6 to 4 +move 3 from 9 to 1 +move 4 from 3 to 2 +move 1 from 6 to 7 +move 1 from 4 to 2 +move 13 from 1 to 7 +move 6 from 4 to 8 +move 1 from 7 to 3 +move 1 from 4 to 6 +move 1 from 9 to 5 +move 1 from 3 to 5 +move 19 from 8 to 9 +move 1 from 6 to 5 +move 6 from 9 to 2 +move 2 from 5 to 8 +move 1 from 5 to 2 +move 4 from 1 to 4 +move 8 from 9 to 4 +move 3 from 9 to 8 +move 2 from 9 to 1 +move 6 from 7 to 5 +move 12 from 4 to 2 +move 6 from 8 to 3 +move 1 from 4 to 1 +move 1 from 3 to 1 +move 13 from 2 to 3 +move 4 from 5 to 3 +move 1 from 4 to 9 +move 1 from 8 to 9 +move 12 from 3 to 2 +move 1 from 9 to 1 +move 2 from 5 to 9 +move 3 from 9 to 5 +move 1 from 7 to 5 +move 3 from 7 to 3 +move 1 from 5 to 4 +move 1 from 5 to 8 +move 9 from 2 to 3 +move 2 from 2 to 3 +move 3 from 1 to 9 +move 1 from 8 to 9 +move 3 from 9 to 1 +move 9 from 2 to 6 +move 1 from 9 to 5 +move 6 from 2 to 3 +move 2 from 6 to 9 +move 3 from 6 to 3 +move 1 from 4 to 3 +move 2 from 9 to 6 +move 2 from 7 to 2 +move 2 from 2 to 8 +move 24 from 3 to 7 +move 2 from 5 to 6 +move 2 from 8 to 2 +move 7 from 2 to 8 +move 8 from 3 to 6 +move 2 from 1 to 3 +move 1 from 1 to 2 +move 1 from 5 to 2 +move 15 from 7 to 4 +move 9 from 7 to 9 +move 7 from 9 to 1 +move 5 from 8 to 1 +move 4 from 1 to 4 +move 19 from 4 to 3 +move 22 from 3 to 5 +move 1 from 7 to 5 +move 9 from 5 to 4 +move 6 from 1 to 3 +move 6 from 3 to 1 +move 4 from 5 to 4 +move 1 from 2 to 1 +move 1 from 2 to 6 +move 4 from 6 to 1 +move 1 from 3 to 6 +move 3 from 6 to 3 +move 2 from 9 to 8 +move 2 from 5 to 3 +move 2 from 5 to 1 +move 10 from 6 to 4 +move 4 from 4 to 9 +move 7 from 4 to 3 +move 2 from 8 to 7 +move 4 from 9 to 3 +move 5 from 5 to 7 +move 1 from 5 to 1 +move 1 from 6 to 3 +move 1 from 8 to 4 +move 1 from 8 to 3 +move 13 from 4 to 5 +move 1 from 1 to 8 +move 6 from 5 to 3 +move 1 from 7 to 6 +move 5 from 7 to 6 +move 9 from 1 to 8 +move 1 from 8 to 4 +move 1 from 7 to 1 +move 1 from 4 to 1 +move 5 from 3 to 7 +move 3 from 7 to 9 +move 1 from 5 to 4 +move 6 from 8 to 6 +move 1 from 9 to 3 +move 2 from 9 to 5 +move 7 from 5 to 9 +move 1 from 7 to 5 +move 2 from 5 to 3 +move 10 from 6 to 8 +move 2 from 6 to 1 +move 1 from 4 to 9 +move 1 from 7 to 5 +move 8 from 8 to 2 +move 1 from 1 to 7 +move 1 from 9 to 7 +move 1 from 5 to 1 +move 3 from 9 to 8 +move 7 from 8 to 7 +move 6 from 7 to 1 +move 1 from 8 to 7 +move 4 from 7 to 1 +move 16 from 3 to 7 +move 4 from 3 to 1 +move 5 from 7 to 8 +move 16 from 1 to 4 +move 9 from 1 to 7 +move 1 from 3 to 4 +move 15 from 4 to 8 +move 1 from 3 to 1 +move 2 from 1 to 6 +move 2 from 4 to 9 +move 17 from 8 to 2 +move 6 from 9 to 5 +move 8 from 7 to 8 +move 2 from 6 to 9 +move 4 from 5 to 7 +move 2 from 8 to 5 +move 1 from 5 to 9 +move 11 from 2 to 6 +move 4 from 6 to 1 +move 5 from 2 to 8 +move 2 from 9 to 2 +move 1 from 9 to 3 +move 3 from 1 to 8 +move 1 from 3 to 6 +move 7 from 6 to 9 +move 2 from 5 to 4 +move 6 from 7 to 4 +move 4 from 8 to 1 +move 1 from 5 to 2 +move 1 from 6 to 1 +move 7 from 9 to 8 +move 2 from 7 to 9 +move 9 from 2 to 9 +move 5 from 9 to 3 +move 3 from 2 to 8 +move 4 from 8 to 7 +move 9 from 7 to 2 +move 3 from 1 to 3 +move 14 from 8 to 1 +move 2 from 8 to 3 +move 1 from 9 to 4 +move 3 from 7 to 9 +move 8 from 3 to 9 +move 2 from 2 to 7 +move 12 from 1 to 8 +move 4 from 1 to 6 +move 2 from 6 to 7 +move 1 from 6 to 7 +move 9 from 4 to 7 +move 9 from 7 to 4 +move 1 from 1 to 6 +move 2 from 3 to 6 +move 2 from 6 to 8 +move 12 from 9 to 8 +move 2 from 6 to 9 +move 2 from 9 to 7 +move 1 from 8 to 5 +move 5 from 7 to 5 +move 1 from 9 to 1 +move 3 from 4 to 1 +move 5 from 4 to 8 +move 4 from 1 to 7 +move 1 from 4 to 2 +move 19 from 8 to 4 +move 2 from 7 to 5 +move 14 from 8 to 5 +move 2 from 7 to 8 +move 3 from 9 to 8 +move 19 from 4 to 2 +move 9 from 2 to 4 +move 2 from 7 to 8 +move 15 from 5 to 9 +move 15 from 9 to 8 +move 1 from 5 to 9 +move 11 from 8 to 7 +move 4 from 5 to 8 +move 1 from 5 to 9 +move 2 from 9 to 5 +move 2 from 2 to 6 +move 14 from 2 to 9 +move 12 from 8 to 9 +move 3 from 8 to 4 +move 7 from 9 to 2 +move 4 from 7 to 9 +move 1 from 6 to 9 +move 1 from 7 to 5 +move 1 from 6 to 2 +move 3 from 5 to 4 +move 19 from 9 to 4 +move 1 from 5 to 1 +move 1 from 9 to 8 +move 1 from 1 to 7 +move 1 from 8 to 9 +move 4 from 7 to 2 +move 3 from 7 to 6 +move 18 from 4 to 2 +move 17 from 2 to 3 +move 2 from 6 to 8 +move 17 from 3 to 6 +move 13 from 2 to 1 +move 2 from 8 to 3 +move 2 from 2 to 9 +move 6 from 1 to 9 +move 1 from 3 to 4 +move 1 from 3 to 9 +move 8 from 6 to 4 +move 20 from 4 to 8 +move 3 from 4 to 8 +move 15 from 8 to 2 +move 11 from 2 to 6 +move 2 from 1 to 7 +move 7 from 9 to 8 +move 6 from 9 to 3 +move 1 from 6 to 5 diff --git a/AoC2022/05/makefile b/AoC2022/05/makefile new file mode 100644 index 0000000..6516fa4 --- /dev/null +++ b/AoC2022/05/makefile @@ -0,0 +1,15 @@ +## +# run solutions +# +# @file +# @version 0.1 + + + +# end + +run: + sbcl --load ~/.sbclrc --script solver.lisp + emacs -batch -l ert -l solver.el -f ert-run-tests-batch-and-exit + rustc solver.rs && ./solver + elixir solver.ex diff --git a/AoC2022/05/solver.el b/AoC2022/05/solver.el new file mode 100644 index 0000000..59faf65 --- /dev/null +++ b/AoC2022/05/solver.el @@ -0,0 +1,50 @@ +;;; solver.el --- Day 05 -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2022 Óscar Nájera +;; +;; Author: Óscar Nájera +;; Maintainer: Óscar Nájera +;; Created: December 05, 2022 +;; Modified: December 05, 2022 +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; Day 05 +;; +;;; Code: +(require 'subr-x) +(defun solver-build-stacks () + (let* ((stacks-len (length + (split-string + (buffer-substring-no-properties (line-beginning-position) (line-end-position))))) + (stacks (make-vector stacks-len nil)) + next) + (message "%S" (list stacks-len (split-string + (buffer-substring-no-properties (point) (line-end-position))))) + + (while (setq next (search-backward "]" nil t)) + (push (intern (string (char-before))) + (aref stacks (/ (- next (line-beginning-position) 1) 4)))) + stacks)) + +(defun solver-apply-moves (stacks) + (while (re-search-forward (rx bol "move " (group (+ digit)) " from " (group (+ digit)) " to " (group (+ digit))) nil t) + (let ((from (1- (string-to-number (match-string 2)))) + (to (1- (string-to-number (match-string 3))))) + (dotimes (_ (string-to-number (match-string 1))) + (push (pop (aref stacks from)) (aref stacks to))))) + stacks) + +'(T P G V Q P F D H) +(with-temp-buffer + (insert-file-contents "input") + (re-search-forward "^ 1") + (thread-last + (solver-build-stacks) + (solver-apply-moves) + (seq-map #'car))) + +(provide 'solver) +;;; solver.el ends here -- cgit v1.2.3