aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)"
]
}
],