aboutsummaryrefslogtreecommitdiff
path: root/2022/day-05/day-05.ipynb
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-12-05 09:29:28 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-12-05 09:29:28 -0500
commit5abb472942f93ca1edebd0bc59df0a26c8dde38a (patch)
tree3e87e2910ba77737884c66d0621bd7c40c727785 /2022/day-05/day-05.ipynb
parentf5e51cc47cf1f98b75510afdeed37252e1e7c76b (diff)
downloadgleam_aoc-5abb472942f93ca1edebd0bc59df0a26c8dde38a.tar.gz
gleam_aoc-5abb472942f93ca1edebd0bc59df0a26c8dde38a.zip
day 5 cleanup
Diffstat (limited to '2022/day-05/day-05.ipynb')
-rw-r--r--2022/day-05/day-05.ipynb9
1 files changed, 5 insertions, 4 deletions
diff --git a/2022/day-05/day-05.ipynb b/2022/day-05/day-05.ipynb
index fa9374a..4feea30 100644
--- a/2022/day-05/day-05.ipynb
+++ b/2022/day-05/day-05.ipynb
@@ -57,7 +57,7 @@
"(define crates-list\n",
" (~>> assignments\n",
" (take _ 8)\n",
- " (map (λ~>> ->list))\n",
+ " (map ->list)\n",
" (apply map list _)\n",
" rest\n",
" (chunks-of _ 4)\n",
@@ -130,12 +130,13 @@
}
],
"source": [
- "(define (find-crate-message cs [reverse-function reverse])\n",
+ "(define (find-crate-message cs [reverse? #true])\n",
+ " (define direction (if reverse? reverse identity))\n",
" (for/fold ([current-crates cs]\n",
" #:result (~>> (hash-values current-crates) (map first) (apply string)))\n",
" ([i (in-list instructions)])\n",
" (match-define (instruction n from to) i)\n",
- " (define taken (~> (hash-ref current-crates from) (take _ n) reverse-function))\n",
+ " (define taken (~> (hash-ref current-crates from) (take _ n) direction))\n",
" (~> current-crates\n",
" (hash-update _ from (λ (v) (drop v n)))\n",
" (hash-update _ to (λ (v) (append taken v))))))\n",
@@ -176,7 +177,7 @@
}
],
"source": [
- "(find-crate-message crates identity)"
+ "(find-crate-message crates #false)"
]
}
],