aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/07/solver.el
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/07/solver.el')
-rw-r--r--AoC2022/07/solver.el69
1 files changed, 69 insertions, 0 deletions
diff --git a/AoC2022/07/solver.el b/AoC2022/07/solver.el
new file mode 100644
index 0000000..ab97c08
--- /dev/null
+++ b/AoC2022/07/solver.el
@@ -0,0 +1,69 @@
+;;; solver.el --- Day 07 -*- 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 08, 2022
+;; Modified: December 08, 2022
+;; Version: 0.0.1
+;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
+;; Homepage: https://github.com/titan/solver
+;; Package-Requires: ((emacs "24.3"))
+;;
+;; This file is not part of GNU Emacs.
+;;
+;;; Commentary:
+;;
+;; Day 07
+;;
+;;; Code:
+
+
+(require 'cl-lib)
+
+(with-temp-buffer
+ (insert "$ cd /
+$ ls
+dir a
+14848514 b.txt
+8504156 c.dat
+dir d
+$ cd a
+$ ls
+dir e
+29116 f
+2557 g
+62596 h.lst
+$ cd e
+$ ls
+584 i
+$ cd ..
+$ cd ..
+$ cd d
+$ ls
+4060174 j
+8033020 d.log
+5626152 d.ext
+7214296 k")
+ (let ((data (split-string (buffer-string) "\n")))
+ (cl-labels ((scan ()
+ (cl-loop for item = (pop data)
+ while (and item (not (string= "$ cd .." item)))
+ when (parse item)
+ collect it))
+ (parse (entry)
+ (pcase (split-string entry)
+ (`("$" "cd" ,dir) (cons dir (scan)))
+ (`("$" "ls") nil)
+ (`("dir" ,dir) nil)
+ (`(,size ,name) (cons name (string-to-number size))))))
+
+ (scan)
+ )))
+
+
+
+(append '(5 6 8) (cons 5 8))
+(provide 'solver)
+;;; solver.el ends here