aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunky Jimpjorps <thechairman@thechairman.info>2022-12-01 00:13:21 -0500
committerHunky Jimpjorps <thechairman@thechairman.info>2022-12-01 00:13:21 -0500
commit64f2ab8dfdf5b1bb6f16265f0d5a56aed74e077c (patch)
tree8d74cbeb56c1f8f33523b8ea2271c61b965527c0
parent479b6f63d924cacfd615952400b239f976f43047 (diff)
downloadgleam_aoc-64f2ab8dfdf5b1bb6f16265f0d5a56aed74e077c.tar.gz
gleam_aoc-64f2ab8dfdf5b1bb6f16265f0d5a56aed74e077c.zip
day 1 complete
-rw-r--r--2020/day-08/day-08.ipynb32
-rw-r--r--2022/day-01/day-01.ipynb150
-rw-r--r--2022/day-01/day-01.rkt6
3 files changed, 162 insertions, 26 deletions
diff --git a/2020/day-08/day-08.ipynb b/2020/day-08/day-08.ipynb
index b95af07..718373b 100644
--- a/2020/day-08/day-08.ipynb
+++ b/2020/day-08/day-08.ipynb
@@ -18,11 +18,7 @@
{
"cell_type": "code",
"execution_count": 1,
- "metadata": {
- "vscode": {
- "languageId": "racket"
- }
- },
+ "metadata": {},
"outputs": [],
"source": [
"#lang iracket/lang #:require racket\n",
@@ -52,11 +48,7 @@
{
"cell_type": "code",
"execution_count": 2,
- "metadata": {
- "vscode": {
- "languageId": "racket"
- }
- },
+ "metadata": {},
"outputs": [
{
"data": {
@@ -101,11 +93,7 @@
{
"cell_type": "code",
"execution_count": 3,
- "metadata": {
- "vscode": {
- "languageId": "racket"
- }
- },
+ "metadata": {},
"outputs": [
{
"data": {
@@ -147,11 +135,7 @@
{
"cell_type": "code",
"execution_count": 4,
- "metadata": {
- "vscode": {
- "languageId": "racket"
- }
- },
+ "metadata": {},
"outputs": [
{
"data": {
@@ -190,11 +174,7 @@
{
"cell_type": "code",
"execution_count": 5,
- "metadata": {
- "vscode": {
- "languageId": "racket"
- }
- },
+ "metadata": {},
"outputs": [
{
"data": {
@@ -229,7 +209,7 @@
"codemirror_mode": "scheme",
"file_extension": ".rkt",
"mimetype": "text/x-racket",
- "name": "Racket",
+ "name": "racket",
"pygments_lexer": "racket",
"version": "8.7"
},
diff --git a/2022/day-01/day-01.ipynb b/2022/day-01/day-01.ipynb
new file mode 100644
index 0000000..b585757
--- /dev/null
+++ b/2022/day-01/day-01.ipynb
@@ -0,0 +1,150 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Advent of Code 2020\n",
+ "#### Day 1: Calorie Counting\n",
+ "\n",
+ "Elves carry various amounts of food with various caloric contents.\n",
+ "\n",
+ "**Part 1.** How many calories is the elf with the most calories of food carrying?\n",
+ "**Part 2.** How many calories are the three elves with the most calories of food carrying?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "vscode": {
+ "languageId": "racket"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "(require racket\n",
+ " advent-of-code\n",
+ " threading)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##### Part 1\n",
+ "\n",
+ "The data file is a list of integers, one on each line, with an empty line separating the inventory of each elf.\n",
+ "\n",
+ "1. Fetch the input file,\n",
+ "2. split it on double newlines,\n",
+ "3. split each list member on single newlines,\n",
+ "4. convert each sublist member to a number,\n",
+ "5. sum up each list, and\n",
+ "6. find the maximum one. \n",
+ "\n",
+ "This is straightforward to do with threading/piping:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "vscode": {
+ "languageId": "racket"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<code>70374</code>"
+ ],
+ "text/plain": [
+ "70374"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(define calorie-data (fetch-aoc-input (find-session) 2022 1))\n",
+ "\n",
+ "(~> calorie-data\n",
+ " (string-split \"\\n\\n\")\n",
+ " (map (λ~> string-split (map string->number _) (apply + _)) _)\n",
+ " (apply max _))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "##### Part 2\n",
+ "\n",
+ "Similarly, to find the top three calorie holders,\n",
+ "\n",
+ "1. fetch the input file,\n",
+ "2. split it on double newlines,\n",
+ "3. split each list member on single newlines,\n",
+ "4. convert each sublist member to a number,\n",
+ "5. sum up each list, \n",
+ "6. sort the list from high to low,\n",
+ "7. take the first three members,\n",
+ "8. and sum them."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {
+ "vscode": {
+ "languageId": "racket"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<code>204610</code>"
+ ],
+ "text/plain": [
+ "204610"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "(~> calorie-data\n",
+ " (string-split \"\\n\\n\")\n",
+ " (map (λ~> string-split (map string->number _) (apply + _)) _)\n",
+ " (sort _ >)\n",
+ " (take 3)\n",
+ " (apply + _))\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Racket (WSL)",
+ "language": "racket",
+ "name": "racket"
+ },
+ "language_info": {
+ "codemirror_mode": "scheme",
+ "file_extension": ".rkt",
+ "mimetype": "text/x-racket",
+ "name": "Racket",
+ "pygments_lexer": "racket",
+ "version": "8.7"
+ },
+ "orig_nbformat": 4
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/2022/day-01/day-01.rkt b/2022/day-01/day-01.rkt
new file mode 100644
index 0000000..b29335d
--- /dev/null
+++ b/2022/day-01/day-01.rkt
@@ -0,0 +1,6 @@
+#lang racket
+
+(require advent-of-code
+ threading
+ seq)
+