summaryrefslogtreecommitdiffstats
path: root/2021/07/calc.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-11-06 09:58:38 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-11-06 09:58:38 -0800
commit4fd1aae518076adc8b97735225c678d6a362328d (patch)
tree97d61b659fc3cac628d0cdee71128a0baee2cb73 /2021/07/calc.tl
downloadadvent-4fd1aae518076adc8b97735225c678d6a362328d.tar.gz
advent-4fd1aae518076adc8b97735225c678d6a362328d.tar.bz2
advent-4fd1aae518076adc8b97735225c678d6a362328d.zip
Kazinator's Advent of Code stuff.
Diffstat (limited to '2021/07/calc.tl')
-rw-r--r--2021/07/calc.tl22
1 files changed, 22 insertions, 0 deletions
diff --git a/2021/07/calc.tl b/2021/07/calc.tl
new file mode 100644
index 0000000..b6dac9c
--- /dev/null
+++ b/2021/07/calc.tl
@@ -0,0 +1,22 @@
+(defun read-crab (name)
+ (flow
+ (file-get-string name)
+ (tok #/\d+/)
+ (mapcar toint)))
+
+(defun calc (input)
+ (let* ((mn (find-min input))
+ (mx (find-max input))
+ (rg (range mn mx))
+ (cost (op sum input (op abs (- @1 @@1)))))
+ [cost (find-min rg : cost)]))
+
+(defun calc2 (input)
+ (let* ((mn (find-min input))
+ (mx (find-max input))
+ (rg (range mn mx))
+ (cost (op sum input (opip (- @@1) abs (* @1 (succ @1)) (trunc @1 2))
+ #;(lambda (x)
+ (let ((n (abs (- x @1))))
+ (trunc (* n (succ n)) 2))))))
+ [cost (find-min rg : cost)]))