aboutsummaryrefslogtreecommitdiff
path: root/2022/day-02
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-12-02 00:32:46 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-12-02 00:32:46 -0500
commit8e9c76908a23197cf78dec3e39349e0c0e35b72a (patch)
treef13ca0d3c8ad111f23144771dfa40030b4b5b8c5 /2022/day-02
parent3ccb86e948ba6ac797476ed3c4caad79395f2a3f (diff)
downloadgleam_aoc-8e9c76908a23197cf78dec3e39349e0c0e35b72a.tar.gz
gleam_aoc-8e9c76908a23197cf78dec3e39349e0c0e35b72a.zip
day 2 working solution, may clean it up
Diffstat (limited to '2022/day-02')
-rw-r--r--2022/day-02/day-02.ipynb131
1 files changed, 131 insertions, 0 deletions
diff --git a/2022/day-02/day-02.ipynb b/2022/day-02/day-02.ipynb
new file mode 100644
index 0000000..1041425
--- /dev/null
+++ b/2022/day-02/day-02.ipynb
@@ -0,0 +1,131 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "(require racket\n",
+ " advent-of-code\n",
+ " threading)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "(define strategy-guide-raw (~> (fetch-aoc-input (find-session) 2022 2) (string-split \"\\n\")))\n",
+ "\n",
+ "(define translation-part-1\n",
+ " (hash \"A\" 'rock \"B\" 'paper \"C\" 'scissors \"X\" 'rock \"Y\" 'paper \"Z\" 'scissors))\n",
+ "\n",
+ "(define score-bonus (hash 'rock 1 'paper 2 'scissors 3 'win 6 'draw 3 'lose 0))\n",
+ "\n",
+ "(define (naive-play them me)\n",
+ " (match* ((hash-ref translation-part-1 them) (hash-ref translation-part-1 me))\n",
+ " [(x x) (+ 3 (hash-ref score-bonus x))]\n",
+ " [('rock (and x 'paper)) (+ 6 (hash-ref score-bonus x))]\n",
+ " [('paper (and x 'scissors)) (+ 6 (hash-ref score-bonus x))]\n",
+ " [('scissors (and x 'rock)) (+ 6 (hash-ref score-bonus x))]\n",
+ " [(_ x) (hash-ref score-bonus x)]))\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<code>13809</code>"
+ ],
+ "text/plain": [
+ "13809"
+ ]
+ },
+ "execution_count": 58,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "\n",
+ "(define trust-the-guide\n",
+ " (for/sum ([play (in-list strategy-guide-raw)])\n",
+ " (match-define (list them me) (string-split play))\n",
+ " (naive-play them me)))\n",
+ "\n",
+ "trust-the-guide\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<code>12316</code>"
+ ],
+ "text/plain": [
+ "12316"
+ ]
+ },
+ "execution_count": 59,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(define translation-part-2 (hash \"A\" 'rock \"B\" 'paper \"C\" 'scissors \"X\" 'lose \"Y\" 'draw \"Z\" 'win))\n",
+ "\n",
+ "(define (skilled-play them me)\n",
+ " (match* ((hash-ref translation-part-2 them) (hash-ref translation-part-2 me))\n",
+ " [('rock 'win) 8]\n",
+ " [('rock 'draw) 4]\n",
+ " [('rock 'lose) 3]\n",
+ " [('paper 'win) 9]\n",
+ " [('paper 'draw) 5]\n",
+ " [('paper 'lose) 1]\n",
+ " [('scissors 'win) 7]\n",
+ " [('scissors 'draw) 6]\n",
+ " [('scissors 'lose) 2]))\n",
+ "\n",
+ "(define new-understanding\n",
+ " (for/sum ([play (in-list strategy-guide-raw)])\n",
+ " (match-define (list them me) (string-split play))\n",
+ " (skilled-play them me)))\n",
+ "\n",
+ "new-understanding\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Racket (Trusted)",
+ "language": "racket",
+ "name": "racket-trusted"
+ },
+ "language_info": {
+ "codemirror_mode": "scheme",
+ "file_extension": ".rkt",
+ "mimetype": "text/x-racket",
+ "name": "racket",
+ "pygments_lexer": "racket",
+ "version": "8.7"
+ },
+ "orig_nbformat": 4,
+ "vscode": {
+ "interpreter": {
+ "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
+ }
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}