From 7dd8e1a22499367cd97442f9b1b03432304cc83a Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 2 Dec 2022 10:35:31 -0500 Subject: [PATCH 1/8] 2022 02 --- 2022/02/input | 2500 ++++++++++++++++++++++++++++++++++++++++++++++ 2022/02/part1.js | 58 ++ 2022/02/test.js | 28 + 3 files changed, 2586 insertions(+) create mode 100644 2022/02/input create mode 100644 2022/02/part1.js create mode 100644 2022/02/test.js diff --git a/2022/02/input b/2022/02/input new file mode 100644 index 0000000..67ea6b7 --- /dev/null +++ b/2022/02/input @@ -0,0 +1,2500 @@ +B Z +C Z +B X +A Y +B X +B X +A X +B Z +C Z +B Y +A Z +C X +B X +C X +B Z +B Z +C Y +B Z +B Z +C Z +B Z +B Y +B X +B Y +C Z +C Y +C Z +A X +C Z +B X +C Z +B Y +B X +A Y +A X +A Y +B Y +B X +B X +A Z +B Z +B Y +C Z +B X +C Y +B Z +B Y +C Y +A X +A Y +C Y +C Z +B Z +B X +C Z +A X +B X +A Y +B Z +C Y +A Y +C Z +C Z +A X +B X +C Z +A Z +A Z +B X +B X +B X +A Y +B X +B X +C Y +B X +C Z +C Y +B Z +A X +B X +B X +A X +C Y +C Y +A X +A X +B Z +B X +C Z +B X +B Z +A Z +B Z +A X +A X +B Z +A X +B X +B X +B X +A Y +A Y +A Y +B X +C Y +B Z +A Y +B X +A Z +C X +A Z +B Y +B Z +C Z +B Z +A Y +B X +B Z +B Z +B Z +C Y +B X +A Y +B Z +B Y +B Z +B X +A X +A X +B Y +B X +C Y +A Y +A Z +B Z +B Z +B Y +B X +B Z +B X +B Z +B Z +B X +B Z +B Z +B Z +B X +A Y +B X +B Z +A X +B Z +B Z +B X +C Y +A Z +B Z +C Z +B X +A Z +B X +A Z +C Y +C Y +A Y +A Y +B Z +A Y +A Y +C Z +A X +B X +B X +C Y +A Z +B Y +C Y +B Z +B Y +B Z +A X +B Z +C Z +B X +B Y +A X +C Z +B Y +B Z +B Z +A Z +B X +A Y +C Y +C Y +B Z +B Z +B X +B Z +B Z +B Y +B Z +B Z +B Z +B X +B X +B Z +B Y +B Z +C Y +A Z +A Y +B X +A X +B Z +B Z +A Z +B Z +B Z +B X +A Y +C Z +C Y +B Z +B Z +C Z +A X +B Z +B Z +B X +A Y +A Z +B Z +C Y +C Z +A Y +B Z +B X +C Z +A X +C Z +B Z +C Z +B X +C Y +B X +B Z +B X +A Y +A Z +B Z +B X +B Z +C Z +C Z +C Y +B X +B Y +B Z +C Z +C Z +B Z +B X +B Z +C Y +A Y +C Y +B X +C Y +B Y +C X +B X +A Y +C Z +B X +B Z +B Y +B X +B X +A Z +B Z +C Z +B X +B X +A X +B X +B X +C X +C Y +A X +B X +B Z +B X +A Y +B X +B Y +B X +B X +B Y +B X +A Z +B X +B Z +B X +C Z +A Z +C X +B Z +A Y +B X +B X +A Z +A Y +B Z +B Z +A Y +C Z +B X +B X +C Z +B Z +B Z +B Z +A Y +A Y +A X +B X +C X +B X +B Z +B X +A X +B X +B Z +B X +A Y +B X +C Y +B X +B Z +B Z +C Z +C Z +C Y +B Z +B X +B Z +A Y +C Y +B X +C Y +C Z +A X +B Z +A X +B X +C Y +A X +A Y +B X +A Y +A Z +C X +B X +B Y +B Z +B X +A Y +B Z +B X +A X +B X +B X +B Y +B Z +B Z +B X +B X +A X +B Z +B Z +B Z +A Y +C Z +A X +A Y +B Z +B X +C Y +A X +B X +B Z +B Y +A Y +B Z +B Z +B X +A Y +A Y +A Y +C Y +B X +B X +B Z +B Z +A Z +A Y +B Z +B X +B X +B X +A X +B X +C Y +B Z +A Y +B X +A Y +A X +C Y +B Z +C Z +B Z +B X +B Z +A Y +B Z +C Z +B Z +B Z +A X +B Z +B Z +B X +B Z +B Z +B Z +C X +B X +B X +A Y +A Y +B X +B X +C Z +B X +B X +C Y +C Y +C Z +B X +B Z +B Z +B Z +A Y +A Y +A X +C Z +A Z +A X +B Z +C Z +A X +B X +B Y +C Z +B Y +B Z +C Y +C Y +C Y +B Z +B Z +B X +B Z +B Y +B X +B Z +A X +B X +A Y +A X +B Z +A Y +C Z +C X +B X +B X +C Y +B Z +A Y +B Z +B X +C X +B Z +A X +A Y +A Y +C Y +C Z +C Z +B X +A X +B X +B X +B Z +C Y +B X +C Z +C Y +B X +B Z +B X +B X +C Z +A Y +B Z +B X +A X +B Z +B Z +B X +B X +C Z +C Z +B Y +C Z +B Z +C Y +B X +B X +C Y +B X +B X +A Z +B X +B X +A Y +B X +B X +B X +B Z +B Z +C Z +A Y +B X +B Z +B X +B Z +B Z +B X +B Y +C Z +A Z +A Y +C Y +B X +A X +B Y +A X +B Y +A Y +C X +B X +A Y +B Z +B Z +B X +B Z +B Z +B X +B X +A Y +B Z +A Y +B Y +B Y +B Y +B X +B Z +B Z +A Y +A X +C Y +B X +B X +A Y +B X +A Y +B Z +B Z +B Y +B Z +C Z +C Z +C Y +B Z +C Y +A X +B X +C Y +C Z +B X +C Y +A Y +B Z +B Z +A X +C Y +B X +A Y +C Z +B Z +B X +A Y +C Z +A X +A Y +C X +C Y +A Y +B Z +B X +A Z +B Z +B Z +B X +C Z +B X +B Z +B X +B X +B Z +B X +A X +A Y +B Y +A Y +A Y +B Z +C Z +B X +B Z +A Y +A Y +A Z +B X +A Y +A Y +B X +A X +B Y +B Z +B Y +A Z +C Y +B Z +A X +A Z +C Z +B X +B Z +B X +C Y +A X +B Z +A Y +B X +B Z +B X +C Y +B Z +B X +A Y +B X +C Y +C X +A X +B Z +B X +A X +A Z +B X +B Y +A Z +B Z +C Y +A Y +C X +B Z +A Y +C Y +C Z +B Y +C Y +A Z +B Z +B Z +A Y +B X +C X +A Y +A Y +A Z +B X +B X +B Y +A X +B X +B Z +B Z +B X +B Y +C Z +C Y +A Y +A Y +C X +C Z +C Y +C Y +A Y +A Y +B Z +C Y +C Y +A Y +A Y +C Z +B Z +A X +B Y +B Z +B Z +B Z +B Z +B X +A Y +A Y +B Z +A Y +C X +A X +C Z +B Z +B Z +A X +C Y +B Z +B X +B X +B X +B Z +C Y +B Z +B X +B X +B Z +C Y +B X +A Z +B X +B Z +A X +C X +A X +B Z +B Z +B Z +B Z +A Y +B Z +B Y +B Z +B Z +B X +B Z +B Z +A Y +A X +B X +A Z +B Z +A Z +B X +B X +B Z +A Y +B Y +A X +B X +B X +A Y +B X +B X +B Z +B Y +B Z +C Z +B X +C Y +B Z +B Z +C Y +B Z +B Z +B Z +B Z +B Z +C Y +A Y +A X +B Z +C Y +B Y +C Z +B Z +B Z +C Z +B Z +B Z +B X +A Y +B Z +B Z +C Y +A Y +B Z +A Y +B Z +C Z +C Y +A Y +A Z +B X +A X +B Z +B Y +A X +A X +A Y +B X +C Y +B X +B Z +A Y +B X +B X +A Y +A Z +C Z +C Y +A Y +B X +B Z +B X +C Z +A Y +B X +A Y +B Z +B X +C Y +A Y +B Z +C Y +B Y +B X +C Y +A Y +B Z +C Y +B X +A X +B Z +B Z +C Y +A Y +B Z +C Y +B X +A X +A Z +C X +B Z +B Z +C Y +B Y +C Z +C Y +A X +A Y +A X +A Y +C Z +C Y +C Z +C Z +C Y +A X +C Z +B X +C X +B X +A Z +B X +C Z +A Y +A X +A Z +C Z +B X +C Y +A Y +C Y +C Z +C Y +C Y +C X +B Z +B X +B Y +A X +B Z +B Y +C Y +C Y +C Z +A Z +A X +A Y +C Z +B Z +B X +B Z +B Z +B X +B Z +C Y +A X +B X +A Z +B X +C Y +B Z +B X +B Z +C Z +C Z +A X +B Z +B X +A Y +B Z +A Y +B Y +C Z +C Y +A X +A Y +C Y +C Z +B X +C Y +B Z +B Z +B Z +C Z +B X +C Y +B Z +C Z +B X +A Y +A X +B Z +B Z +C Y +B X +B Z +C Y +A Y +C Y +A Y +B X +C Z +A X +A Y +C Y +C Z +B Z +B Z +B Z +A Y +A Y +C Z +A Z +B X +A X +B Z +C Z +B X +C Y +B Z +B X +B Z +B Z +B X +C Z +B X +B Z +B X +A X +B X +A X +B Z +B Z +A Y +B X +B Z +B Z +C Z +C Y +B X +B X +B Y +C Z +C Y +A X +B Z +C Y +A Y +B X +B X +A X +A Y +C X +B Z +B Z +A Y +A X +C Y +B Z +B Z +C X +C Y +A Y +B Z +C Y +B Z +B X +B Z +C Y +B X +B Z +B X +B X +B X +B Z +B Z +C Y +B X +B Z +A Z +A Y +A Z +A Y +B X +C Z +A Y +B X +B X +C Z +B Z +A X +B X +C Y +A Y +A X +B Z +A X +A Y +B Z +B X +B Z +C Y +A X +A X +B X +B Y +C X +A X +B X +B X +A Y +C Y +B Z +B Z +C Z +B X +B Z +B X +B Y +B Z +B Z +B X +B Z +A X +B X +A Y +A Z +B Z +B X +A Y +A X +B Z +B X +C Z +A Y +A Y +C Z +B X +A X +C Y +B X +B Z +B X +B Z +B X +C Y +B Z +C Y +C Z +A Z +C Z +A X +C Z +B Y +B X +B Z +C Z +A Y +A Z +A X +B Z +A X +B Z +B X +A Z +C Z +C Y +B Z +C X +A X +A X +B X +A Y +A X +B Z +B Z +B Z +B Z +A X +A X +A Y +B Z +B Y +B Z +A Y +B Y +A X +A Z +B Z +A Y +B X +A X +A X +B Z +A Z +B Y +B Z +C Z +C Y +B X +B Y +A X +A Z +B Z +A Z +B Z +A X +B Z +A Z +B Y +A Z +C Y +B Z +C Z +B Z +B X +B Z +C X +A X +B X +C Z +B X +B Y +A X +B X +B X +A Z +B X +B Z +C Z +B X +B X +B X +A Y +A Z +C Y +A Y +B X +A Z +A Z +B Y +B Y +C Z +C Z +B Z +C Z +B Z +A Y +A X +C Y +B X +B Z +B Z +B Z +B X +B Z +B Z +A X +A Y +B X +B X +B X +C X +C Y +C X +B X +B Z +B Y +C X +A Y +A Y +B Z +C Y +C Z +C Z +C Z +A Y +B Y +B Z +B X +B Z +B Y +A X +C Y +C Z +A Y +B Z +A X +A X +A X +B Z +B X +C Y +B Y +C Z +B Z +B Z +C Y +B Z +C Z +B X +B Y +A Y +C Z +A Y +B Z +B Z +B X +B X +B Z +B Z +B X +B X +C Z +B Y +B Z +B X +C Y +C Z +A Y +C Z +B Z +C Y +B X +C Z +A X +B Z +B X +C X +C Z +B Z +C Z +A X +B Z +C X +B Z +C Z +A Y +B Z +B Z +C Z +B Y +B Z +B X +B X +A X +A Y +A Y +C Y +C Y +C Y +B Z +B Z +A Y +B X +A Z +C Y +C Z +B X +A Y +A Y +C Z +C Z +C Y +A Z +B Z +B Z +B Z +A Y +A Y +C Z +B Z +B X +C Z +B Z +C Y +A Z +B X +B Z +A Z +B X +A X +B X +A X +B X +B Z +B Z +B Z +C Y +C Z +A Y +B X +A X +C Z +C Y +C Z +B Z +B X +A Y +A X +C Z +B X +C Z +C Y +A X +B X +C Z +B X +B Z +C Y +B X +A X +A Y +A X +B Z +B Z +C Z +B X +A Y +B X +B X +A Z +B Y +B Z +B X +B Z +B X +B Y +B X +B X +A Y +A Y +A X +C Y +A Y +B X +C Y +B Z +B Z +A Y +B X +C Y +C Z +C Y +B Z +C Z +C Y +A Y +A Y +B Z +B X +A X +A Y +B X +B Z +B X +C Z +C Z +A Y +B X +B Z +B Y +C X +C Y +B Z +A X +B Z +A Y +A X +A Y +B X +B Z +B Z +B X +B Z +C Z +B Z +A Y +B Z +C Z +B X +B X +B X +B X +B X +B X +B Y +B Z +B X +B Z +A Z +B Z +C Y +A X +B Z +B Z +C Z +B X +A Z +C Y +B Z +B X +A X +A Y +C Y +B Y +A X +B Y +B X +B Z +C Y +B Z +C Y +A Z +B Z +C Y +C Z +A Y +C X +C Y +B Z +B X +B Z +B X +B X +A Y +B Y +B X +B X +C Y +B X +C X +B Y +A Y +C Y +B X +B X +A X +B X +A X +A X +B X +B X +A Z +C Z +C Y +B X +B X +C Z +B X +C Y +C Z +A Y +B Z +C Y +B X +B Y +B X +B X +C X +A X +B X +B Z +B Z +C Y +C Y +B Y +A Y +B Z +B X +B X +A Z +B Z +B X +B X +A Y +B X +B X +B X +A X +B X +B X +B X +B Z +B X +A Z +B Y +B X +B Z +B Z +B Z +A X +B Z +B Z +B X +B Z +C Z +C Y +A Z +C X +C Y +A Y +B X +B Z +C Z +B X +C Z +B Z +A Z +A Y +B Y +B Z +B X +A X +B Z +C Z +C Y +B Z +A X +A Y +A Z +B Z +C Y +A Y +B X +C Z +A Y +B X +B Z +B X +C Y +B X +B X +B X +A Z +B Z +C Z +B Z +C Y +B Z +C Z +B Z +B X +C Y +C Z +A X +C Z +C Y +C Y +B X +A Y +A Z +B X +B Z +B Z +B Z +A X +A Z +B Z +A Z +A Y +C Z +B Y +B Z +B X +B X +C Z +B Z +B Z +B Z +B Z +B X +B X +A X +A X +A Z +B Z +B X +B Z +B Z +C X +A Y +B Y +B X +B X +B Z +B X +B X +B X +C Y +B Z +B X +C Y +B Z +A Y +B Y +B Z +A Y +A X +B X +B X +B Z +A X +B Z +A Y +B Z +B X +A X +A X +A X +A Y +B Z +A Y +A X +B X +B Z +A Y +B Z +B X +B X +A Z +B Z +B Z +B Z +B Z +A X +B Z +B Z +B X +B Z +C Y +B Z +B X +B Z +B X +C Y +B X +B Y +B Z +B X +A X +C Y +B Z +B Z +B X +A Y +B X +B Z +C X +C Y +A Y +B X +B X +A Y +B Z +C Y +B Z +A Y +C Y +B Z +A X +A X +A Y +C Y +C Z +B Z +C Z +B X +A X +B X +A Y +A Y +C Z +C Y +A Z +B Z +A Y +B X +B X +B Z +C Z +B X +B X +B Y +C Y +C Z +A Y +A Z +A X +A Y +A Y +A Z +B Z +B Z +C Z +B Z +B X +C Y +A Y +B X +C Z +A X +B Z +B Y +A Y +B X +B X +A X +C Z +C Z +C Y +C Y +A X +B X +B X +B Y +A Z +C Z +A Y +C Z +C Y +B X +C Y +B Z +A Z +B Y +B X +C Y +B Y +B Z +A Z +A X +B X +C Z +C Z +B Z +B Z +C Z +B X +B X +C Y +A Y +C Y +C Z +B Z +B X +A Y +B Y +B Z +C X +B X +B Z +B Z +B X +B Z +B Z +C Y +A Y +B Z +B X +A Y +A Y +B Z +B Y +C Y +B Z +B Y +B Z +A Y +B X +C Z +A X +B X +C Y +B Z +B Y +B Y +B Z +A X +A X +B Z +B X +A X +B Z +B Z +A Y +B X +A X +B X +B X +A Y +C Z +C Y +B Z +B X +B X +B X +A X +B X +B Z +B Z +B Z +B X +B Z +B Z +A Z +C Y +B X +B X +B X +A X +C Z +A Y +A Y +B Z +B X +C Z +B Y +C Z +B X +A Y +C X +B Z +B X +B X +C Y +B X +B X +B Z +A X +B X +A Z +B X +B X +B Z +B X +B X +B Z +A Y +B X +B Z +B X +B X +C Y +B X +B Z +B Z +B X +B Z +C Z +B Y +A Y +B Z +B X +B X +A X +B Z +B X +B X +B Z +C Z +B Z +B X +C Y +B Z +B Y +B Z +B Z +A Z +B X +B X +B X +B X +C Y +A Y +B X +B Z +B X +B X +C Z +C X +B Z +B Z +B X +B Z +A Y +A Z +C Z +A X +A X +A Y +A Y +A Y +C Z +B Z +A Y +C Z +B X +A Z +C Y +A X +A X +A Y +B Z +A X +B X +B X +C Z +B Z +C Z +B Z +A X +C Y +C Z +A X +A Z +B X +C Y +A X +B X +B Z +B X +A Y +A Z +C Z +B Z +A X +B X +C Y +B X +B X +C Y +B X +A Z +A X +C X +B Z +B Y +C Z +C Z +A Y +A Y +A Y +B X +A Z +B X +A X +C Y +B X +A X +B X +B X +B Z +B Z +B Y +A Y +C Z +C Z +B X +B Z +C Z +B X +C Z +B Z +A Y +A X +B X +C Z +C Y +A Y +B Z +C Y +B X +C X +A X +B Z +C Z +B Z +B X +A Y +B Z +A Y +A Y +A Y +C Y +C Y +C Z +A Y +C Y +C Y +B Z +B X +C Y +C Y +B X +B Z +B X +C Z +C Y +C Y +B X +B X +A Y +B Z +B Z +B X +B X +C Z +A X +B Y +B X +A Z +B Z +B X +B Z +C Y +B Z +C Y +B Z +A Z +C Y +A Z +C Z +B X +B X +C Y +B X +C Y +A Z +B X +B Z +B Z +B X +B Z +B Y +A Y +B Z +B X +B Z +A Y +A Y +C Z +A Y +C X +B Z +A Y +A Y +B X +B Z +A Y +C Z +B Z +B Z +C Y +A X +B Z +C Z +B X +B X +B Z +A Y +B Y +C Z +A Y +B X +C Z +B X +B Z +B Z +B Z +B X +B Z +B X +A Z +B X +B X +B X +B Z +A Z +A Y +B Z +B X +B X +C X +A Y +A X +C Y +A Z +A X +C Y +A Y +C Y +A Z +B X +B Z +B Z +C Y +A Y +B X +B X +A Y +C Z +B Z +B Z +A X +A Y +B Z +A Z +A Y +C Z +B X +B Z +B Z +C Y +A Y +C Z +B Z +A Y +C Y +C Y +B Z +B Z +B Z +A Y +B Y +A Y +B Z +C Z +A Y +B X +C Y +A Z +A X +B X +A Z +B Z +A Z +C Z +B Z +A Y +A X +A X +C Y +A Y +B Z +A Y +B Z +B X +A Y +A X +A Y +A X +C Z +A Y +B X +C Z +B X +B Z +B Z +C Y +B Z +B X +A X +B Y +A Y +B X +C Z +A Y +B Z +B X +A Y +C Z +C Y +B Z +B Z +B Z +A X +B X +A Y +B Z +C Y +A X +A Z +B Y +B X +C Y +B Z +C Y +A Z +B X +A Y +A Y +C Y +A Z +B X +A Z +B X +B X +A X +B X +B Z +B X +B Y +B Z +B Y +B X +A Y +A X +C Z +B Y +C Y +B X +C Y +B X +B Z +B X +B X +B Z +B Z +B Z +C Z +B Z +B Z +A X +A Y +B X +B X +B X +C Z +B X +B Z +C Y +A X +A Z +B X +C Z +A X +A X +B Z +A Y +B Z +A X +C X +C Z +B X +B X +C Y +A X +B X +A X +C Y +C Y +A X +A X +B X +B Y +B Z +A X +B X +B X +B X +B Y +A Z +B Z +C Z +B X +B X +B Z +A Y +C Y +B X +B X +A X +C Y +C X +C Z +B X +B Y +A Z +C Z +A X +C Y +B Z +B X +A X +B X +B X +B Z +C Y +A Y +A X +C Z +B Z +A Y +B X +B X +B X +A Y +B X +C Y +B Y +A X +A X +B Y +B X +B X +B Z +B Z +A X +C Z +C Z +A X +C Y +B X +C Z +B X +B Z +B X +B Z +A Y +C Y +B X +B X +B X +B X +B Y +C Y +B Y +B Y +A Y +B Z +C Y +A X +C Z +B X +B Z +C Y +A Y +B X +C Z +B Z +A Z +A Z +A Z +A Y +C Z +A Z +B X +C Z +B Z +B X +C X +A Z +B Y +A Y +B Y +C Y +B X +A X +A X +A Y +A Y +A X +B Y +B Z +B X +A X +C Y +B X +B Y +A Y +C Y +A Y +B Z +B X +B Z +B Z +B X +B X +B Z +B Z +C Z +C Y +A Z +B X +B X +A Y +C Y +B X +B Z +B X +C Z +A Z +B X +C Z +B X +B X +B X +B Z +C Z +C Z +B X +C Y +B Z +C Z +B Z +C Z +B Y +B X +C Z +A X +B X +B X +C Y +B Z diff --git a/2022/02/part1.js b/2022/02/part1.js new file mode 100644 index 0000000..b95d356 --- /dev/null +++ b/2022/02/part1.js @@ -0,0 +1,58 @@ +import * as R from "remeda"; +import { test, expect } from "vitest"; +import fs from "fs-extra"; +import path from 'path'; + +import { spy } from '../01/main.js'; + +export const sampleInput = `A Y +B X +C Z`; + +export const puzzleInput = + fs.readFileSync( path.join( path.dirname(import.meta.url), "input").replace('file:',''), "utf8"); + +const playMap = { + X: 'A', // rock + Y: 'B', // paper + Z: 'C', // scissors +} + +export const parseInput = R.createPipe( + text => text.split("\n"), + R.map( entry => entry.split(' ') ), + R.map( ([a,b]) => [a,playMap[b]] ), +) + + +const playScore = { + A: 1, + B: 2, + C: 3, +}; + +const draw = 3; +const lost = 0; +const win = 6; + +const outcome = ( opponent, me ) => { + if( opponent === me ) return draw; + if( opponent === 'A' ) { + return me === 'C' ? lost : win; + } + if( opponent === 'B' ) { + return me === 'A' ? lost : win; + } + return me === 'B' ? lost : win; +} + +export const mapScores = ([opponent,me]) => [ outcome(opponent,me), playScore[me] ]; + +export const solutionPart1 = R.createPipe( + parseInput, + R.filter( ([a]) => a ), // remove last line + R.map( mapScores ), + R.map( R.sumBy(R.identity) ), + R.sumBy(R.identity) +); + diff --git a/2022/02/test.js b/2022/02/test.js new file mode 100644 index 0000000..e59f035 --- /dev/null +++ b/2022/02/test.js @@ -0,0 +1,28 @@ +import { test, expect } from "vitest"; + +import { expectSolution } from '../01/main.js'; +import { parseInput, sampleInput, puzzleInput, mapScores, solutionPart1 } from './part1.js'; + +test( "input parsing", () => { + expect(parseInput(sampleInput)).toEqual([['A','B'],['B','A'],['C','C']]); +}); + +test( "mapScore", () => { + expect( mapScores(['A','B']) ).toEqual([6,2]); + expect( mapScores(['B','A']) ).toEqual([0,1]); + expect( mapScores(['C','C']) ).toEqual([3,3]); +}); + +test( "part 1, sample", () => { + expect( + solutionPart1(sampleInput) + ).toEqual(15) + +}); + +test("part 1", () => { + expectSolution(solutionPart1(puzzleInput)).toEqual(12458); +}); + +test.todo("part 2", () => { +}); From f815cf7b0fbaac45487b9507e02f7d2c3ffcd241 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 2 Dec 2022 10:59:27 -0500 Subject: [PATCH 2/8] part 2 --- 2022/02/part1.js | 69 ++++++++++++++++++++++++++---------------------- 2022/02/part2.js | 25 ++++++++++++++++++ 2022/02/test.js | 59 +++++++++++++++++++++++++---------------- 3 files changed, 98 insertions(+), 55 deletions(-) create mode 100644 2022/02/part2.js diff --git a/2022/02/part1.js b/2022/02/part1.js index b95d356..7172837 100644 --- a/2022/02/part1.js +++ b/2022/02/part1.js @@ -1,58 +1,63 @@ import * as R from "remeda"; import { test, expect } from "vitest"; import fs from "fs-extra"; -import path from 'path'; +import path from "path"; -import { spy } from '../01/main.js'; +import { spy } from "../01/main.js"; export const sampleInput = `A Y B X C Z`; -export const puzzleInput = - fs.readFileSync( path.join( path.dirname(import.meta.url), "input").replace('file:',''), "utf8"); +export const puzzleInput = fs.readFileSync( + path.join(path.dirname(import.meta.url), "input").replace("file:", ""), + "utf8" +); const playMap = { - X: 'A', // rock - Y: 'B', // paper - Z: 'C', // scissors -} + X: "A", // rock + Y: "B", // paper + Z: "C", // scissors +}; export const parseInput = R.createPipe( - text => text.split("\n"), - R.map( entry => entry.split(' ') ), - R.map( ([a,b]) => [a,playMap[b]] ), -) + (text) => text.split("\n"), + R.filter(R.identity), // remove last line + R.map((entry) => entry.split(" ")) +); +export const movePositions = ["A", "B", "C"]; const playScore = { - A: 1, - B: 2, - C: 3, + A: 1, + B: 2, + C: 3, }; const draw = 3; const lost = 0; const win = 6; -const outcome = ( opponent, me ) => { - if( opponent === me ) return draw; - if( opponent === 'A' ) { - return me === 'C' ? lost : win; - } - if( opponent === 'B' ) { - return me === 'A' ? lost : win; - } - return me === 'B' ? lost : win; -} +const outcome = (opponent, me) => { + if (opponent === me) return draw; + if (opponent === "A") { + return me === "C" ? lost : win; + } + if (opponent === "B") { + return me === "A" ? lost : win; + } + return me === "B" ? lost : win; +}; -export const mapScores = ([opponent,me]) => [ outcome(opponent,me), playScore[me] ]; +export const mapScores = ([opponent, me]) => [ + outcome(opponent, me), + playScore[me], +]; export const solutionPart1 = R.createPipe( - parseInput, - R.filter( ([a]) => a ), // remove last line - R.map( mapScores ), - R.map( R.sumBy(R.identity) ), - R.sumBy(R.identity) + parseInput, + R.map(([a, b]) => [a, playMap[b]]), + R.map(mapScores), + R.map(R.sumBy(R.identity)), + R.sumBy(R.identity) ); - diff --git a/2022/02/part2.js b/2022/02/part2.js new file mode 100644 index 0000000..c70ebe1 --- /dev/null +++ b/2022/02/part2.js @@ -0,0 +1,25 @@ +import * as R from "remeda"; + +import { movePositions, mapScores, playMap, parseInput } from "./part1.js"; + +function calculateMove(opponent, verdict) { + const incr = { + Y: 0, + X: 2, + Z: 1, + }; + + const index = + (movePositions.findIndex((x) => x === opponent) + incr[verdict]) % + movePositions.length; + + return movePositions[index]; +} + +export const solutionPart2 = R.createPipe( + parseInput, + R.map(([a, b]) => [a, calculateMove(a, b)]), + R.map(mapScores), + R.map(R.sumBy(R.identity)), + R.sumBy(R.identity) +); diff --git a/2022/02/test.js b/2022/02/test.js index e59f035..778928a 100644 --- a/2022/02/test.js +++ b/2022/02/test.js @@ -1,28 +1,41 @@ -import { test, expect } from "vitest"; +import { test, expect, describe } from "vitest"; -import { expectSolution } from '../01/main.js'; -import { parseInput, sampleInput, puzzleInput, mapScores, solutionPart1 } from './part1.js'; +import { expectSolution } from "../01/main.js"; +import { + parseInput, + sampleInput, + puzzleInput, + mapScores, + solutionPart1, +} from "./part1.js"; +import { solutionPart2 } from "./part2.js"; -test( "input parsing", () => { - expect(parseInput(sampleInput)).toEqual([['A','B'],['B','A'],['C','C']]); +describe("part 1", () => { + test("input parsing", () => { + expect(parseInput(sampleInput)).toEqual([ + ["A", "Y"], + ["B", "X"], + ["C", "Z"], + ]); + }); + + test("mapScore", () => { + expect(mapScores(["A", "B"])).toEqual([6, 2]); + expect(mapScores(["B", "A"])).toEqual([0, 1]); + expect(mapScores(["C", "C"])).toEqual([3, 3]); + }); + + test("part 1, sample", () => { + expect(solutionPart1(sampleInput)).toEqual(15); + }); + + test("solution", () => { + expectSolution(solutionPart1(puzzleInput)).toEqual(12458); + }); }); -test( "mapScore", () => { - expect( mapScores(['A','B']) ).toEqual([6,2]); - expect( mapScores(['B','A']) ).toEqual([0,1]); - expect( mapScores(['C','C']) ).toEqual([3,3]); -}); - -test( "part 1, sample", () => { - expect( - solutionPart1(sampleInput) - ).toEqual(15) - -}); - -test("part 1", () => { - expectSolution(solutionPart1(puzzleInput)).toEqual(12458); -}); - -test.todo("part 2", () => { +describe("part 2", () => { + test("part 2", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual(12683); + }); }); From e21830bd4ed8f845b98044467fae6d22243bb477 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 2 Dec 2022 11:05:04 -0500 Subject: [PATCH 3/8] add template for a new day --- 2022/template/part1.js | 1 + 2022/template/part2.js | 2 ++ 2022/template/test.js | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 2022/template/part1.js create mode 100644 2022/template/part2.js create mode 100644 2022/template/test.js diff --git a/2022/template/part1.js b/2022/template/part1.js new file mode 100644 index 0000000..b509eb0 --- /dev/null +++ b/2022/template/part1.js @@ -0,0 +1 @@ +import * as R from "remeda"; diff --git a/2022/template/part2.js b/2022/template/part2.js new file mode 100644 index 0000000..31477e8 --- /dev/null +++ b/2022/template/part2.js @@ -0,0 +1,2 @@ +import * as R from "remeda"; + diff --git a/2022/template/test.js b/2022/template/test.js new file mode 100644 index 0000000..9859a0e --- /dev/null +++ b/2022/template/test.js @@ -0,0 +1,20 @@ +import { test, expect, describe } from "vitest"; + +import { expectSolution } from "../01/main.js"; +import { + solutionPart1, + puzzleInput, +} from "./part1.js"; +import { solutionPart2 } from "./part2.js"; + +describe("part 1", () => { + test.todo("solution", () => { + expectSolution(solutionPart1(puzzleInput)).toEqual('TODO'); + }); +}); + +describe("part 2", () => { + test.todo("solution", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual('TODO'); + }); +}); From c9ff0203bf280a31349d4479663314efcc1c9bfd Mon Sep 17 00:00:00 2001 From: Yanick Date: Sat, 3 Dec 2022 14:52:19 -0500 Subject: [PATCH 4/8] part 1 --- 2022/03/input | 300 +++++++++++++++++++++++++++++++++++++++++++++++ 2022/03/part1.js | 23 ++++ 2022/03/part2.js | 2 + 2022/03/sample | 6 + 2022/03/test.js | 29 +++++ 5 files changed, 360 insertions(+) create mode 100644 2022/03/input create mode 100644 2022/03/part1.js create mode 100644 2022/03/part2.js create mode 100644 2022/03/sample create mode 100644 2022/03/test.js diff --git a/2022/03/input b/2022/03/input new file mode 100644 index 0000000..712656e --- /dev/null +++ b/2022/03/input @@ -0,0 +1,300 @@ +fzmmmfwDWFzlQQqjCQjDGnqq +tJHJvLJVVttNsvTtTvgHHSVwCsQRQQZCZZMqQMQBnqBMQs +LgThNJhNSgTJVgvgtghPhbpfWzfbwfPmpprb +lDLnSnLZRjmWrlhrFF +PffQJNqJbPZbpmjrrCVNFmCh +qzbcbqfMfZMTfQTqqzzTPPLMHgBBBtHRStvgHRDBnSRL +WPZfJlZZCMwwZPWCwWzVHQhsshVSsfNQHdvQNN +FLGDGGnGdVjQQQDQ +ccFFbggLnRcLFRtFBmnJzdZZzZBMpwJlZMppMp +RZsnCZssCnDccJCnfcQfHTdzMzhdLdMTqdRqpRLwqq +tNrGNrrvGhTThQqw +rrFStPgrFWWgvmP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bczvpZCwvwZccndpvzpzCP +jzngbHrlHQllcbcTCtHGWtftGCHqWC +JJgmsJRwFqChLGtqGs +SmJmSmDdSPRwSMppJdPPwVvvzNQvjrNMNjMZZrQgZNgQ +PvPlPcZPZFllzNzCDdhhdHjrpHNjHBHB +VmgWtJWrqbQmqGDBdGQjjhBGdG +tmbgggbgnMWnStttgnfnTzrCfPvFnccnPclT +RQQbdSRdpprQSNVqqqfrffjvnjnJnhnVvHhBhVjJtjJz +WGgGgLmLgGZMPDBhDJDHjMBFnD +WPPwPGwlLgZwmWlslCLRNbrsTrfRrNNQqsspBT +dNNpHpchLppdccTNtZZTRRPSSnwPPSbSnhhrhnSJ +qfqsFsqffgQMznJrPznbMrrB +vglfqQCgDgFjglCDCjLZpTHNPHttdcZVVN +FWtDHDStZwrFCDwrgWPFDsWQJZzlMdpZzlNpNjdjjQzNzj +BqnVGVcbTmGfHLGVzvpQpvJvQlflMdJp +ThRRchnHqLTGbFCCCrrSSFhFCs +wJrwdZPnJwqPbJPCnjFZdvHtMvsLsTsDtHsHDDqvpH +RWzNRWjRfgjNMMLvcMcLNt +WGGRQzzRmRmVQSgwrwJjjCbJhnbShJ +cjngcvcwbMwWnbMWjbgvnsjPftsqfthqsBtsJJJJBt +HrGFmDDzpmLTHpDsPfsBNBPfzZNPqN +DDVmDplDrpGSVSTTHGlpLnPwCRnWcvWCdPbbMvcVdW +BVRlBfPBffWswVWQsfwBNNPMFMmmGFZGnWZGtztrzMZMnz +HqSJchHTHbTgHhGhvmRzFmnFtzRF +RJqHTpgDLJDSqLJJPNVjsfPwBVsVLlfN +NDrBlSmrFBlbbJllmtHHwhNNhZztqHVRzQ +CMTCGLcvvtfCdCcCvCnMTMcTzjHwVZVRLjRRjQjRHRwzwjVH +dfGdgGMGPggnvfvgbtDtlSJPDSFJPslJ diff --git a/2022/03/part1.js b/2022/03/part1.js new file mode 100644 index 0000000..a7d31f2 --- /dev/null +++ b/2022/03/part1.js @@ -0,0 +1,23 @@ +import * as R from "remeda"; +import fs from 'fs-extra'; +import path from 'path'; + +const readFile = (year,day,file) => fs.readFileSync( + path.join( year, day, file ), + "utf8" +); + +export const sample = readFile('2022','03','sample'); +export const puzzleInput = readFile('2022','03','input'); + +export const solutionPart1 = R.createPipe( + text => text.split("\n"), + R.filter( R.identity ), + R.map( line => line.split('') ), + R.map( line => [ line, line.splice( line.length / 2 ) ] ), + R.map( line => R.intersection(...line) ), + R.map( line => line[0].charCodeAt(0) ), + R.map( code => code > 96 ? code - 96 : code - 38 ), + R.sumBy( R.identity ) +); + diff --git a/2022/03/part2.js b/2022/03/part2.js new file mode 100644 index 0000000..31477e8 --- /dev/null +++ b/2022/03/part2.js @@ -0,0 +1,2 @@ +import * as R from "remeda"; + diff --git a/2022/03/sample b/2022/03/sample new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/03/sample @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/2022/03/test.js b/2022/03/test.js new file mode 100644 index 0000000..95bdb5f --- /dev/null +++ b/2022/03/test.js @@ -0,0 +1,29 @@ +import { test, expect, describe } from "vitest"; + +import { + solutionPart1, + sample, + puzzleInput, +} from "./part1.js"; +import { solutionPart2 } from "./part2.js"; + +function expectSolution(result) { + console.info(result); + return expect(result); +} + +describe("part 1", () => { + test( 'sample', () => { + console.log(JSON.stringify(solutionPart1(sample))); + expectSolution(solutionPart1(sample)).toEqual(157) + }); + test("solution", () => { + expectSolution(solutionPart1(puzzleInput)).toEqual('TODO'); + }); +}); + +describe("part 2", () => { + test.todo("solution", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual('TODO'); + }); +}); From 5339d77492366834e38df1c8dac9167f69d05752 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 3 Dec 2022 15:26:15 -0500 Subject: [PATCH 5/8] part 2 --- 2022/03/part1.js | 31 ++++++++++++++----------------- 2022/03/part2.js | 10 ++++++++++ 2022/03/test.js | 20 ++++++++------------ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/2022/03/part1.js b/2022/03/part1.js index a7d31f2..023ee91 100644 --- a/2022/03/part1.js +++ b/2022/03/part1.js @@ -1,23 +1,20 @@ import * as R from "remeda"; -import fs from 'fs-extra'; -import path from 'path'; +import fs from "fs-extra"; +import path from "path"; -const readFile = (year,day,file) => fs.readFileSync( - path.join( year, day, file ), - "utf8" -); +const readFile = (year, day, file) => + fs.readFileSync(path.join(year, day, file), "utf8"); -export const sample = readFile('2022','03','sample'); -export const puzzleInput = readFile('2022','03','input'); +export const sample = readFile("2022", "03", "sample"); +export const puzzleInput = readFile("2022", "03", "input"); export const solutionPart1 = R.createPipe( - text => text.split("\n"), - R.filter( R.identity ), - R.map( line => line.split('') ), - R.map( line => [ line, line.splice( line.length / 2 ) ] ), - R.map( line => R.intersection(...line) ), - R.map( line => line[0].charCodeAt(0) ), - R.map( code => code > 96 ? code - 96 : code - 38 ), - R.sumBy( R.identity ) + (text) => text.split("\n"), + R.filter(R.identity), + R.map((line) => line.split("")), + R.map((line) => [line, line.splice(line.length / 2)]), + R.map((line) => R.intersection(...line)), + R.map((line) => line[0].charCodeAt(0)), + R.map((code) => (code > 96 ? code - 96 : code - 38)), + R.sumBy(R.identity) ); - diff --git a/2022/03/part2.js b/2022/03/part2.js index 31477e8..b40e97e 100644 --- a/2022/03/part2.js +++ b/2022/03/part2.js @@ -1,2 +1,12 @@ import * as R from "remeda"; +export const solutionPart2 = R.createPipe( + (text) => text.split("\n"), + R.filter(R.identity), + R.map((line) => line.split("")), + R.chunk(3), + R.map((group) => group.reduce((a, b) => R.intersection(a, b))), + R.map((line) => line[0].charCodeAt(0)), + R.map((code) => (code > 96 ? code - 96 : code - 38)), + R.sumBy(R.identity) +); diff --git a/2022/03/test.js b/2022/03/test.js index 95bdb5f..4f1e0f8 100644 --- a/2022/03/test.js +++ b/2022/03/test.js @@ -1,10 +1,7 @@ import { test, expect, describe } from "vitest"; -import { - solutionPart1, - sample, - puzzleInput, -} from "./part1.js"; +import { solutionPart1, sample, puzzleInput } from "./part1.js"; + import { solutionPart2 } from "./part2.js"; function expectSolution(result) { @@ -13,17 +10,16 @@ function expectSolution(result) { } describe("part 1", () => { - test( 'sample', () => { - console.log(JSON.stringify(solutionPart1(sample))); - expectSolution(solutionPart1(sample)).toEqual(157) - }); + test("sample", () => { + expect(solutionPart1(sample)).toEqual(157); + }); test("solution", () => { - expectSolution(solutionPart1(puzzleInput)).toEqual('TODO'); + expectSolution(solutionPart1(puzzleInput)).toEqual(8515); }); }); describe("part 2", () => { - test.todo("solution", () => { - expectSolution(solutionPart2(puzzleInput)).toEqual('TODO'); + test("solution", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual(2434); }); }); From e78cfbad0738dd0190054268ab0f1eb979b14cd5 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 3 Dec 2022 16:32:41 -0500 Subject: [PATCH 6/8] tidy up --- 2022/{ => 01}/input | 0 2022/01/main.js | 11 +++++++++++ 2022/01/test.js | 12 +++--------- 2022/02/part1.js | 3 --- 4 files changed, 14 insertions(+), 12 deletions(-) rename 2022/{ => 01}/input (100%) create mode 100644 2022/01/main.js diff --git a/2022/input b/2022/01/input similarity index 100% rename from 2022/input rename to 2022/01/input diff --git a/2022/01/main.js b/2022/01/main.js new file mode 100644 index 0000000..453167a --- /dev/null +++ b/2022/01/main.js @@ -0,0 +1,11 @@ +import { expect } from "vitest"; + +export const spy = (x) => { + console.debug(x); + return x; +}; + +export function expectSolution(result) { + console.info(result); + return expect(result); +} diff --git a/2022/01/test.js b/2022/01/test.js index a573612..7da2d97 100644 --- a/2022/01/test.js +++ b/2022/01/test.js @@ -1,16 +1,14 @@ import * as R from "remeda"; import { test, expect } from "vitest"; import fs from "fs-extra"; +import path from 'path'; +import { expectSolution } from './main.js'; const split = (splitter) => (text) => text.split(splitter); const sum = R.sumBy(R.identity); -const spy = (x) => { - console.debug(x); - return x; -}; const input = R.pipe( - fs.readFileSync("input", "utf8"), + fs.readFileSync( path.join( path.dirname(import.meta.url), "input").replace('file:',''), "utf8"), split("\n\n"), R.map((x) => split("\n")(x) @@ -20,10 +18,6 @@ const input = R.pipe( R.map(sum) ); -function expectSolution(result) { - console.info(result); - return expect(result); -} test("part 1", () => { const maxCalories = R.pipe(input, (calories) => Math.max(...calories)); diff --git a/2022/02/part1.js b/2022/02/part1.js index 7172837..2d3eb9c 100644 --- a/2022/02/part1.js +++ b/2022/02/part1.js @@ -1,10 +1,7 @@ import * as R from "remeda"; -import { test, expect } from "vitest"; import fs from "fs-extra"; import path from "path"; -import { spy } from "../01/main.js"; - export const sampleInput = `A Y B X C Z`; From 574eee8e859d1e8da187e51c16ffc4232b78ec84 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 4 Dec 2022 12:37:18 -0500 Subject: [PATCH 7/8] part 1 --- 2022/04/input | 1000 +++++++++++++++++++++++++++++++++++++++++++++ 2022/04/part1.js | 20 + 2022/04/part2.js | 2 + 2022/04/puzzle.md | 57 +++ 2022/04/sample | 6 + 2022/04/test.js | 24 ++ 6 files changed, 1109 insertions(+) create mode 100644 2022/04/input create mode 100644 2022/04/part1.js create mode 100644 2022/04/part2.js create mode 100644 2022/04/puzzle.md create mode 100644 2022/04/sample create mode 100644 2022/04/test.js diff --git a/2022/04/input b/2022/04/input new file mode 100644 index 0000000..6ca3e13 --- /dev/null +++ b/2022/04/input @@ -0,0 +1,1000 @@ +21-82,22-81 +46-47,21-47 +7-88,27-89 +37-38,33-42 +5-99,51-99 +58-83,59-84 +8-12,11-53 +9-55,10-11 +29-55,30-56 +11-78,12-77 +26-57,5-62 +85-91,5-85 +21-58,15-93 +27-27,27-57 +2-9,12-96 +21-30,26-29 +1-99,98-99 +13-93,14-95 +81-81,21-82 +12-13,12-78 +43-83,4-42 +25-25,25-95 +54-77,53-96 +36-92,72-93 +24-30,24-26 +60-60,21-59 +55-55,54-95 +77-77,10-78 +56-96,18-93 +61-61,61-72 +63-98,63-64 +35-50,36-49 +8-87,1-85 +59-81,81-81 +95-96,92-97 +1-58,2-57 +32-57,32-82 +62-66,67-67 +15-33,27-46 +9-35,36-88 +63-93,1-3 +63-86,63-64 +20-28,19-29 +32-85,32-32 +19-71,29-71 +4-66,6-65 +67-77,66-78 +91-96,1-95 +7-57,8-93 +45-45,45-46 +23-23,22-97 +1-2,2-98 +10-23,22-83 +32-46,36-46 +93-94,20-94 +12-87,11-91 +10-77,9-88 +11-20,21-43 +15-76,15-15 +10-98,10-97 +59-71,12-27 +3-56,2-56 +24-88,25-25 +40-40,39-46 +54-89,54-88 +18-93,94-94 +23-62,22-62 +23-23,23-49 +21-95,63-95 +2-95,94-94 +8-13,11-12 +29-82,29-81 +24-46,25-46 +15-92,58-92 +5-86,5-78 +3-98,4-96 +21-56,56-67 +78-98,19-99 +16-28,16-29 +95-96,96-96 +4-95,16-96 +21-68,21-68 +18-94,19-91 +7-56,8-90 +8-56,8-8 +28-66,29-76 +72-73,74-89 +21-42,22-41 +30-88,47-77 +39-99,40-98 +70-71,30-71 +29-90,89-90 +44-75,44-76 +32-35,36-95 +18-48,19-48 +10-67,9-69 +18-70,17-69 +39-51,5-82 +7-96,96-99 +9-27,10-82 +86-86,53-86 +34-53,49-54 +5-91,91-99 +73-76,68-81 +53-94,53-93 +1-62,40-62 +34-52,53-53 +49-63,48-66 +53-53,53-93 +2-72,3-71 +22-97,21-99 +46-91,47-91 +8-53,7-98 +20-21,15-21 +5-99,5-98 +6-7,6-51 +5-64,6-88 +21-87,20-87 +30-81,81-82 +6-82,6-83 +9-9,9-12 +8-19,9-19 +64-80,63-80 +34-34,33-66 +20-20,19-70 +1-97,97-99 +87-88,12-87 +13-88,14-87 +11-94,5-99 +46-84,45-83 +24-90,25-40 +24-74,30-73 +6-20,7-21 +10-76,60-91 +35-57,35-56 +21-74,75-75 +18-77,76-78 +6-85,84-84 +13-94,14-97 +60-75,61-69 +58-59,58-97 +47-48,2-48 +25-59,26-31 +27-28,27-96 +12-79,6-78 +37-83,44-84 +15-46,11-45 +42-90,41-95 +44-79,27-79 +5-55,5-6 +55-56,55-83 +81-92,80-99 +31-68,32-68 +8-71,9-9 +15-85,16-84 +41-48,49-61 +86-87,66-87 +86-96,26-85 +10-42,10-10 +20-28,26-48 +6-86,7-58 +30-77,75-80 +10-65,9-9 +18-91,17-95 +31-76,77-85 +26-28,28-68 +29-37,29-32 +92-92,13-93 +6-61,7-61 +1-98,2-2 +52-70,60-80 +4-91,2-91 +7-45,4-6 +40-85,41-61 +5-6,5-89 +23-71,70-71 +4-68,46-67 +57-83,57-75 +2-98,21-99 +4-98,3-98 +10-79,10-11 +41-41,41-44 +17-17,17-93 +6-85,7-7 +3-12,2-80 +25-49,25-60 +72-90,52-72 +8-42,40-43 +25-95,25-26 +27-58,28-59 +1-92,1-1 +14-90,15-89 +6-73,7-20 +5-92,5-93 +99-99,84-98 +66-68,28-67 +14-96,95-95 +41-75,69-76 +25-69,20-69 +10-43,5-15 +1-92,17-93 +51-52,23-52 +32-43,44-44 +28-28,28-86 +23-55,54-55 +20-70,21-27 +24-52,25-25 +5-88,6-6 +59-82,60-82 +18-52,8-53 +34-48,12-33 +3-3,2-17 +12-87,13-62 +63-75,23-76 +40-92,41-93 +30-91,29-30 +73-95,72-96 +2-45,1-3 +48-99,18-98 +43-75,75-84 +96-96,1-97 +27-28,27-97 +97-99,4-97 +94-96,50-95 +29-29,27-28 +3-5,6-31 +21-87,52-88 +21-92,92-95 +4-6,11-46 +18-33,21-34 +30-78,31-40 +39-46,45-47 +48-69,68-76 +8-37,37-91 +18-75,21-98 +32-43,16-20 +36-87,59-88 +6-66,65-67 +3-76,3-77 +47-95,48-88 +4-70,1-1 +40-94,12-40 +95-99,12-95 +14-71,70-70 +32-90,69-92 +99-99,14-94 +1-69,69-89 +43-77,53-76 +60-62,21-69 +11-31,18-91 +9-83,9-9 +2-90,1-90 +30-87,31-31 +65-66,64-65 +66-67,3-66 +31-35,30-36 +4-93,92-93 +9-16,10-15 +68-86,68-71 +8-20,20-64 +4-31,5-5 +48-99,49-99 +2-94,95-96 +58-98,10-80 +33-63,62-62 +19-52,18-53 +5-43,17-38 +62-62,61-62 +21-44,21-39 +18-73,73-74 +1-32,1-39 +2-5,5-99 +36-67,10-38 +37-71,33-70 +70-72,69-73 +53-81,52-90 +57-98,9-97 +33-82,95-99 +90-97,13-96 +39-94,94-99 +33-85,32-84 +4-78,5-78 +51-82,51-81 +67-86,64-85 +31-77,77-78 +8-33,8-9 +21-71,22-70 +4-91,7-70 +11-98,12-97 +27-39,27-28 +3-54,3-53 +65-99,52-65 +53-98,24-88 +74-94,44-95 +21-38,39-95 +59-60,58-93 +1-20,9-19 +11-61,10-61 +30-89,88-89 +10-71,11-47 +9-97,10-96 +21-81,80-81 +11-18,21-66 +52-97,53-85 +7-94,6-95 +57-94,23-95 +59-60,23-60 +94-94,27-95 +96-97,62-97 +1-82,81-83 +70-86,68-85 +45-74,44-97 +2-56,3-57 +7-91,50-90 +33-78,32-86 +52-52,22-53 +6-55,7-23 +1-91,3-90 +26-59,26-60 +4-94,4-95 +60-89,16-92 +45-46,1-46 +7-58,58-59 +36-96,23-97 +6-95,5-96 +59-59,59-63 +20-21,20-41 +68-68,3-67 +79-89,78-90 +27-29,28-29 +96-97,26-64 +18-18,17-96 +41-41,41-66 +5-95,4-94 +37-95,36-97 +42-90,41-42 +57-57,15-56 +95-98,94-99 +28-93,27-94 +94-94,30-95 +50-67,54-84 +9-91,8-92 +2-92,1-93 +10-34,26-33 +28-99,23-95 +37-56,56-65 +8-98,9-94 +5-89,6-88 +12-13,12-89 +5-15,16-68 +18-69,23-69 +66-99,67-67 +20-72,20-21 +50-75,25-49 +35-50,35-36 +41-65,63-66 +14-82,81-82 +50-51,17-81 +59-90,58-89 +12-93,93-97 +14-97,15-15 +8-48,8-13 +4-98,5-99 +38-85,38-84 +4-4,3-52 +94-95,2-95 +4-84,3-84 +8-76,7-76 +13-87,13-86 +2-99,98-99 +36-83,37-76 +4-46,4-65 +97-97,43-88 +8-92,33-92 +70-70,64-69 +10-54,11-54 +18-95,19-28 +3-91,4-4 +12-87,26-88 +81-85,78-85 +49-65,65-66 +84-90,90-94 +16-83,15-97 +16-77,15-95 +5-99,61-99 +4-75,2-3 +33-67,17-80 +41-96,40-97 +6-48,2-5 +18-22,19-21 +44-47,44-48 +1-95,2-94 +5-60,4-79 +11-99,12-38 +20-96,96-97 +81-81,1-82 +22-63,23-62 +10-79,9-78 +45-96,46-96 +62-85,86-86 +6-79,36-78 +3-90,3-93 +17-36,17-25 +13-81,12-82 +98-99,8-99 +1-99,98-98 +47-71,46-70 +89-90,18-90 +16-56,55-55 +15-21,24-48 +14-31,30-31 +25-36,25-29 +58-86,75-91 +64-70,65-69 +13-68,14-69 +12-86,12-51 +17-73,18-74 +98-98,1-99 +89-92,90-91 +2-99,1-99 +20-69,60-70 +27-47,26-47 +11-71,12-71 +8-91,9-91 +1-89,4-88 +27-96,27-85 +63-92,92-97 +48-87,47-98 +25-90,26-85 +39-95,43-98 +37-98,37-99 +98-99,7-98 +4-61,4-60 +17-98,17-99 +59-63,31-64 +24-54,25-53 +46-99,10-16 +7-99,6-99 +18-93,92-93 +46-98,3-95 +26-96,25-81 +2-97,3-90 +22-22,21-77 +81-81,25-81 +19-44,20-47 +79-79,42-80 +35-95,4-95 +1-91,2-2 +70-79,69-80 +12-87,8-88 +16-78,17-73 +7-88,7-91 +17-18,1-18 +5-86,4-75 +39-89,40-87 +9-39,9-24 +14-96,13-97 +2-80,2-3 +5-28,21-29 +69-75,11-74 +12-32,10-31 +9-76,9-77 +87-88,6-88 +15-78,15-15 +95-99,32-95 +6-11,12-26 +59-60,10-60 +39-94,39-39 +97-97,55-98 +38-42,37-43 +8-8,8-98 +30-94,30-98 +90-91,9-91 +4-96,5-91 +14-61,1-4 +33-58,32-59 +86-91,24-86 +85-85,84-96 +38-96,37-91 +1-41,12-94 +22-95,78-94 +43-44,38-43 +37-69,37-68 +78-98,78-95 +68-86,45-90 +10-56,10-48 +76-76,2-77 +11-54,12-32 +43-73,43-74 +79-99,7-98 +6-95,19-98 +32-97,96-97 +41-41,4-42 +40-57,24-40 +10-13,12-28 +1-4,3-24 +85-95,85-86 +6-98,5-7 +35-54,42-51 +17-80,27-71 +93-93,2-94 +21-68,21-69 +14-45,13-45 +55-56,55-67 +44-80,17-79 +41-84,42-44 +57-91,91-96 +40-98,41-98 +85-88,78-85 +24-95,24-25 +52-95,55-96 +8-28,7-27 +22-96,19-97 +70-73,74-81 +20-70,2-47 +3-39,2-40 +4-20,3-20 +33-34,33-92 +1-96,2-85 +13-93,12-92 +45-59,46-59 +34-73,34-72 +4-90,4-91 +11-57,11-13 +7-94,5-24 +26-97,25-96 +43-76,13-75 +67-75,76-99 +52-80,51-79 +18-18,17-67 +25-86,26-87 +18-79,17-18 +44-44,44-96 +51-80,38-52 +5-64,6-63 +27-54,37-55 +47-47,47-78 +6-76,7-75 +14-95,14-14 +8-68,9-49 +35-44,35-43 +2-67,1-67 +32-88,30-57 +19-80,79-80 +8-54,7-9 +25-49,8-48 +18-40,19-39 +38-92,39-96 +4-7,6-82 +2-97,1-94 +11-42,12-41 +22-47,21-57 +11-97,2-12 +55-98,69-98 +9-51,8-50 +62-63,2-62 +1-7,8-98 +35-48,36-47 +55-96,29-97 +85-85,61-81 +45-56,44-55 +16-19,7-17 +19-33,20-20 +16-77,15-76 +38-91,17-90 +10-51,3-9 +28-99,7-29 +78-97,97-99 +4-51,5-35 +54-73,35-72 +62-63,62-62 +14-14,14-97 +55-74,55-59 +22-85,55-86 +27-84,26-97 +36-37,37-87 +1-96,5-97 +1-71,3-71 +26-87,27-88 +83-99,73-96 +1-98,2-98 +12-16,21-87 +82-82,83-89 +42-92,42-91 +68-72,68-69 +13-30,12-31 +6-10,9-97 +78-78,12-79 +47-86,86-93 +57-94,58-81 +30-85,29-86 +14-17,18-96 +94-96,63-94 +37-82,38-81 +23-90,42-91 +30-97,31-98 +82-94,14-81 +8-35,9-9 +65-98,97-99 +30-50,29-31 +1-2,1-60 +69-70,70-76 +20-84,20-96 +19-46,36-88 +1-90,5-89 +4-4,4-87 +18-79,17-78 +14-99,13-98 +46-86,47-98 +79-81,35-80 +26-51,25-50 +78-78,14-79 +9-92,10-91 +12-46,12-96 +36-93,1-93 +77-78,76-79 +56-93,94-94 +1-85,13-76 +43-95,9-42 +79-90,78-89 +32-98,9-97 +9-92,5-10 +37-84,3-45 +59-85,60-85 +9-95,8-94 +31-87,30-87 +10-17,18-18 +77-77,76-89 +12-83,38-96 +34-91,35-90 +12-95,70-96 +14-79,13-78 +1-94,93-94 +19-29,25-28 +68-99,64-68 +37-79,8-80 +9-76,11-78 +5-98,3-48 +47-59,48-58 +65-72,39-73 +27-67,27-35 +60-77,59-89 +46-88,35-87 +67-97,68-99 +4-97,3-98 +4-79,80-80 +42-58,58-70 +39-97,7-39 +10-49,11-48 +22-74,23-23 +13-58,12-58 +7-79,8-78 +83-84,80-99 +97-98,35-94 +36-36,36-66 +66-79,65-90 +5-32,3-33 +41-86,87-87 +41-54,32-41 +14-99,10-98 +9-93,9-92 +53-58,59-98 +60-61,5-60 +13-30,12-31 +8-97,7-98 +25-34,29-32 +69-69,6-70 +18-18,7-19 +23-48,23-23 +31-59,32-41 +1-7,6-67 +1-88,2-87 +9-9,8-91 +8-96,8-31 +25-83,21-21 +45-46,45-80 +10-92,91-92 +3-45,2-63 +22-48,22-52 +52-97,52-98 +10-90,12-89 +3-48,25-51 +62-96,92-98 +2-97,6-98 +70-83,70-71 +98-99,94-99 +6-84,7-81 +16-70,71-82 +16-16,16-81 +83-84,11-83 +30-74,71-75 +2-25,1-26 +79-79,30-80 +67-72,66-68 +7-96,8-97 +8-13,11-14 +10-73,10-72 +20-22,20-20 +88-92,89-97 +75-96,68-74 +4-98,1-99 +39-47,38-48 +39-77,40-77 +38-42,38-41 +50-94,51-94 +61-82,62-72 +4-75,3-96 +3-20,1-4 +18-97,9-17 +1-94,2-93 +95-99,88-94 +83-89,19-83 +49-57,49-55 +18-26,19-77 +34-46,38-47 +11-93,10-98 +6-80,7-94 +5-91,90-91 +21-44,43-44 +91-91,12-90 +1-2,1-96 +5-96,18-95 +36-65,5-65 +18-18,18-71 +31-32,31-35 +13-96,12-96 +25-74,24-26 +54-54,14-55 +14-79,15-80 +4-64,5-5 +24-28,23-27 +20-89,2-21 +30-98,30-50 +69-69,6-70 +78-79,77-79 +24-96,25-74 +68-91,8-37 +3-98,4-98 +13-95,14-97 +2-13,3-14 +39-92,40-91 +16-88,87-87 +70-73,64-72 +55-96,95-97 +8-10,15-72 +23-44,24-33 +48-82,48-49 +59-72,59-60 +10-54,11-11 +8-47,44-47 +15-81,14-82 +30-46,5-37 +67-81,69-99 +70-97,69-99 +88-88,40-88 +39-97,38-96 +81-85,80-84 +56-57,15-56 +5-84,78-85 +7-59,6-60 +61-63,62-92 +61-93,87-94 +5-80,5-6 +7-66,7-7 +1-99,2-98 +3-39,3-29 +41-85,69-85 +38-60,8-59 +6-45,6-72 +62-82,29-81 +21-94,22-93 +41-42,41-52 +24-24,24-52 +53-98,12-98 +28-95,27-27 +83-83,55-84 +16-96,95-96 +49-90,89-89 +2-96,2-95 +3-3,3-88 +24-77,61-78 +83-85,39-84 +3-65,2-97 +15-81,2-80 +14-32,13-15 +66-80,67-79 +23-23,23-92 +34-89,33-90 +5-94,4-4 +7-96,95-96 +47-92,48-60 +15-41,14-15 +33-77,47-77 +11-88,11-89 +4-38,18-23 +7-91,8-92 +65-66,19-65 +64-93,92-92 +25-82,25-81 +32-32,31-98 +34-71,34-71 +52-61,48-66 +61-85,60-96 +8-64,16-65 +1-3,4-82 +9-95,10-10 +3-59,1-56 +2-28,2-7 +11-95,11-99 +58-78,78-85 +27-75,27-28 +26-26,25-87 +7-39,7-40 +32-66,10-67 +14-93,13-94 +15-96,96-99 +67-87,90-91 +94-95,35-95 +16-40,2-17 +30-81,62-82 +52-53,34-53 +5-93,92-92 +17-94,94-95 +31-87,83-84 +35-41,34-72 +84-85,84-97 +46-99,47-96 +28-80,1-27 +41-99,37-69 +28-78,29-77 +49-69,64-70 +46-65,65-73 +16-91,16-92 +88-88,12-89 +38-84,39-85 +7-8,7-27 +27-97,97-99 +67-67,68-75 +66-67,67-67 +12-58,17-86 +12-98,13-99 +14-57,15-58 +27-32,28-32 +65-68,69-82 +98-99,64-99 +48-68,48-87 +51-51,51-54 +18-84,32-90 +1-16,8-93 +6-88,7-7 +3-91,1-91 +86-97,86-86 +72-96,72-72 +9-61,8-60 +10-75,75-76 +75-88,87-87 +65-75,65-77 +97-98,22-93 +55-55,42-56 +8-63,1-63 +13-64,35-51 +7-88,45-89 +77-79,74-79 +24-97,24-26 +2-67,7-70 +14-62,47-72 +3-84,56-94 +6-71,20-72 +2-82,6-81 +82-83,16-82 +69-84,68-85 +83-85,82-85 +79-86,79-79 +46-91,90-91 +27-97,27-98 +21-67,68-89 +80-85,4-80 +25-85,25-86 +25-82,27-81 +26-95,94-96 +83-93,82-99 +6-97,7-94 +40-97,18-40 +3-3,3-85 +97-98,1-98 +5-98,5-6 +5-83,6-83 +16-94,82-97 +19-56,2-18 +15-84,16-79 +29-31,30-97 +43-90,42-43 +3-12,2-4 +23-76,22-24 +43-80,79-80 +19-81,19-82 +1-90,2-89 +37-37,23-38 +91-99,56-91 +27-87,28-88 +14-16,15-91 +50-66,32-49 +48-93,48-49 +30-85,29-84 +13-76,58-77 +69-98,40-97 +27-55,19-54 +14-98,13-99 +45-78,78-79 +5-67,6-67 +46-91,47-90 +37-55,36-67 +55-62,61-62 +1-95,48-96 +16-97,17-99 +40-62,41-61 +18-59,56-57 +49-61,60-62 +66-71,65-73 +45-47,46-82 +4-51,3-50 +68-77,7-68 +59-96,59-91 +40-69,41-68 +4-96,3-96 +4-94,4-4 +8-18,15-25 +26-26,27-27 +5-62,8-75 +88-88,4-89 +39-67,17-68 +81-85,12-66 +51-65,50-52 +15-63,15-15 +63-64,30-63 +88-92,2-88 +36-81,35-87 +21-93,6-93 +28-91,28-28 +60-94,5-94 +2-96,95-97 +11-92,92-94 +82-86,80-82 +30-80,38-80 +6-58,5-85 +24-35,34-36 +55-99,55-89 +24-99,25-97 +11-25,19-26 +11-73,73-90 +13-85,14-84 +4-87,5-89 +3-3,4-91 +54-71,55-71 +28-42,29-43 +31-31,31-81 +15-28,14-16 +72-72,26-71 +85-93,72-84 +7-73,6-74 +23-24,23-29 +28-77,29-76 +1-97,1-1 +14-80,13-80 +60-62,61-61 +41-81,44-79 +21-87,22-58 +25-60,25-59 +34-91,35-99 +16-63,64-64 +6-99,6-98 +39-92,11-91 +54-99,51-92 +5-93,6-95 +5-5,4-95 +1-4,3-85 +82-83,8-82 +56-57,57-57 +33-35,10-34 +44-51,43-57 +25-62,26-61 +1-76,2-87 +8-11,7-63 +10-10,9-92 +34-69,5-70 +5-97,74-99 +22-54,53-55 +71-89,88-89 +50-84,51-83 +4-16,15-94 +45-58,34-99 +18-96,4-29 +3-91,4-80 +91-92,57-93 +28-28,28-94 +7-35,7-36 +41-91,42-72 +49-55,49-49 +3-82,3-91 +8-9,8-66 diff --git a/2022/04/part1.js b/2022/04/part1.js new file mode 100644 index 0000000..5c5acd2 --- /dev/null +++ b/2022/04/part1.js @@ -0,0 +1,20 @@ +import * as R from "remeda"; + +import { readFile } from '../03/part1.js'; + +export const sample = readFile("2022", "04", "sample"); +export const puzzleInput = readFile("2022", "04", "input"); + + +const rangeLength = ([a,b]) => b-a+1; + +const isContainedBy = ( [a1,a2],[b1,b2] ) => + ( (a1 >= b1) && (a2 <= b2) ); + +export const solutionPart1 = R.createPipe( + (text) => text.split("\n"), + R.filter(R.identity), + R.map( line => line.split(',').map( range => range.split('-').map( x => parseInt(x) ) ) ), + R.map( R.sortBy( x => rangeLength(x) ) ), + R.countBy( ([a,b]) => isContainedBy(a,b) ) +); diff --git a/2022/04/part2.js b/2022/04/part2.js new file mode 100644 index 0000000..31477e8 --- /dev/null +++ b/2022/04/part2.js @@ -0,0 +1,2 @@ +import * as R from "remeda"; + diff --git a/2022/04/puzzle.md b/2022/04/puzzle.md new file mode 100644 index 0000000..2288234 --- /dev/null +++ b/2022/04/puzzle.md @@ -0,0 +1,57 @@ +\--- Day 4: Camp Cleanup --- +---------- + +Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique *ID number*, and each Elf is assigned a range of section IDs. + +However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments *overlap*. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a *big list of the section assignments for each pair* (your puzzle input). + +For example, consider the following list of section assignment pairs: + +``` +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 + +``` + +For the first few pairs, this list means: + +* Within the first pair of Elves, the first Elf was assigned sections `2-4` (sections `2`, `3`, and `4`), while the second Elf was assigned sections `6-8` (sections `6`, `7`, `8`). +* The Elves in the second pair were each assigned two sections. +* The Elves in the third pair were each assigned three sections: one got sections `5`, `6`, and `7`, while the other also got `7`, plus `8` and `9`. + +This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this: + +``` +.234..... 2-4 +.....678. 6-8 + +.23...... 2-3 +...45.... 4-5 + +....567.. 5-7 +......789 7-9 + +.2345678. 2-8 +..34567.. 3-7 + +.....6... 6-6 +...456... 4-6 + +.23456... 2-6 +...45678. 4-8 + +``` + +Some of the pairs have noticed that one of their assignments *fully contains* the other. For example, `2-8` fully contains `3-7`, and `6-6` is fully contained by `4-6`. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are `*2*` such pairs. + +*In how many assignment pairs does one range fully contain the other?* + +To begin, [get your puzzle input](4/input). + +Answer: + +You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Camp+Cleanup%22+%2D+Day+4+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle. \ No newline at end of file diff --git a/2022/04/sample b/2022/04/sample new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/04/sample @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 diff --git a/2022/04/test.js b/2022/04/test.js new file mode 100644 index 0000000..9cf5b07 --- /dev/null +++ b/2022/04/test.js @@ -0,0 +1,24 @@ +import { test, expect, describe } from "vitest"; + +import { expectSolution } from "../01/main.js"; +import { + solutionPart1, + puzzleInput, + sample, +} from "./part1.js"; +import { solutionPart2 } from "./part2.js"; + +describe("part 1", () => { + test("sample", () => { + expectSolution(solutionPart1(sample)).toEqual(2); + }); + test("solution", () => { + expectSolution(solutionPart1(puzzleInput)).toEqual('TODO'); + }); +}); + +describe("part 2", () => { + test.todo("solution", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual('TODO'); + }); +}); From aa8bc986a5939f3e2b8c9f8a688dbc3bb2f9b3e3 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 4 Dec 2022 12:42:17 -0500 Subject: [PATCH 8/8] part 2 --- 2022/03/part1.js | 2 +- 2022/04/part1.js | 16 ++++++++-------- 2022/04/part2.js | 11 +++++++++++ 2022/04/puzzle.md | 40 +++++++++++++++++++++++++++++----------- 2022/04/test.js | 17 ++++++++--------- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/2022/03/part1.js b/2022/03/part1.js index 023ee91..7366b96 100644 --- a/2022/03/part1.js +++ b/2022/03/part1.js @@ -2,7 +2,7 @@ import * as R from "remeda"; import fs from "fs-extra"; import path from "path"; -const readFile = (year, day, file) => +export const readFile = (year, day, file) => fs.readFileSync(path.join(year, day, file), "utf8"); export const sample = readFile("2022", "03", "sample"); diff --git a/2022/04/part1.js b/2022/04/part1.js index 5c5acd2..7a346cb 100644 --- a/2022/04/part1.js +++ b/2022/04/part1.js @@ -1,20 +1,20 @@ import * as R from "remeda"; -import { readFile } from '../03/part1.js'; +import { readFile } from "../03/part1.js"; export const sample = readFile("2022", "04", "sample"); export const puzzleInput = readFile("2022", "04", "input"); +const rangeLength = ([a, b]) => b - a + 1; -const rangeLength = ([a,b]) => b-a+1; - -const isContainedBy = ( [a1,a2],[b1,b2] ) => - ( (a1 >= b1) && (a2 <= b2) ); +const isContainedBy = ([a1, a2], [b1, b2]) => a1 >= b1 && a2 <= b2; export const solutionPart1 = R.createPipe( (text) => text.split("\n"), R.filter(R.identity), - R.map( line => line.split(',').map( range => range.split('-').map( x => parseInt(x) ) ) ), - R.map( R.sortBy( x => rangeLength(x) ) ), - R.countBy( ([a,b]) => isContainedBy(a,b) ) + R.map((line) => + line.split(",").map((range) => range.split("-").map((x) => parseInt(x))) + ), + R.map(R.sortBy((x) => rangeLength(x))), + R.countBy(([a, b]) => isContainedBy(a, b)) ); diff --git a/2022/04/part2.js b/2022/04/part2.js index 31477e8..744c09b 100644 --- a/2022/04/part2.js +++ b/2022/04/part2.js @@ -1,2 +1,13 @@ import * as R from "remeda"; +const overlapsWith = ([a1, a2], [b1, b2]) => a2 >= b1; + +export const solutionPart2 = R.createPipe( + (text) => text.split("\n"), + R.filter(R.identity), + R.map((line) => + line.split(",").map((range) => range.split("-").map((x) => parseInt(x))) + ), + R.map(R.sortBy(([x]) => x)), + R.countBy(([a, b]) => overlapsWith(a, b)) +); diff --git a/2022/04/puzzle.md b/2022/04/puzzle.md index 2288234..c5d9dc1 100644 --- a/2022/04/puzzle.md +++ b/2022/04/puzzle.md @@ -1,9 +1,8 @@ -\--- Day 4: Camp Cleanup --- ----------- +## \--- Day 4: Camp Cleanup --- -Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique *ID number*, and each Elf is assigned a range of section IDs. +Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique _ID number_, and each Elf is assigned a range of section IDs. -However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments *overlap*. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a *big list of the section assignments for each pair* (your puzzle input). +However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments _overlap_. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a _big list of the section assignments for each pair_ (your puzzle input). For example, consider the following list of section assignment pairs: @@ -19,9 +18,9 @@ For example, consider the following list of section assignment pairs: For the first few pairs, this list means: -* Within the first pair of Elves, the first Elf was assigned sections `2-4` (sections `2`, `3`, and `4`), while the second Elf was assigned sections `6-8` (sections `6`, `7`, `8`). -* The Elves in the second pair were each assigned two sections. -* The Elves in the third pair were each assigned three sections: one got sections `5`, `6`, and `7`, while the other also got `7`, plus `8` and `9`. +- Within the first pair of Elves, the first Elf was assigned sections `2-4` (sections `2`, `3`, and `4`), while the second Elf was assigned sections `6-8` (sections `6`, `7`, `8`). +- The Elves in the second pair were each assigned two sections. +- The Elves in the third pair were each assigned three sections: one got sections `5`, `6`, and `7`, while the other also got `7`, plus `8` and `9`. This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this: @@ -46,12 +45,31 @@ This example list uses single-digit section IDs to make it easier to draw; your ``` -Some of the pairs have noticed that one of their assignments *fully contains* the other. For example, `2-8` fully contains `3-7`, and `6-6` is fully contained by `4-6`. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are `*2*` such pairs. +Some of the pairs have noticed that one of their assignments _fully contains_ the other. For example, `2-8` fully contains `3-7`, and `6-6` is fully contained by `4-6`. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are `*2*` such pairs. -*In how many assignment pairs does one range fully contain the other?* +_In how many assignment pairs does one range fully contain the other?_ -To begin, [get your puzzle input](4/input). +Your puzzle answer was `605`. + +The first half of this puzzle is complete! It provides one gold star: \* + +## \--- Part Two --- + +It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of pairs that _overlap at all_. + +In the above example, the first two pairs (`2-4,6-8` and `2-3,4-5`) don't overlap, while the remaining four pairs (`5-7,7-9`, `2-8,3-7`, `6-6,4-6`, and `2-6,4-8`) do overlap: + +- `5-7,7-9` overlaps in a single section, `7`. +- `2-8,3-7` overlaps all of the sections `3` through `7`. +- `6-6,4-6` overlaps in a single section, `6`. +- `2-6,4-8` overlaps in sections `4`, `5`, and `6`. + +So, in this example, the number of overlapping assignment pairs is `*4*`. + +_In how many assignment pairs do the ranges overlap?_ Answer: -You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Camp+Cleanup%22+%2D+Day+4+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle. \ No newline at end of file +Although it hasn't changed, you can still [get your puzzle input](4/input). + +You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Camp+Cleanup%22+%2D+Day+4+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode) [Mastodon]()] this puzzle. diff --git a/2022/04/test.js b/2022/04/test.js index 9cf5b07..a96bd6e 100644 --- a/2022/04/test.js +++ b/2022/04/test.js @@ -1,11 +1,7 @@ -import { test, expect, describe } from "vitest"; +import { test, describe } from "vitest"; import { expectSolution } from "../01/main.js"; -import { - solutionPart1, - puzzleInput, - sample, -} from "./part1.js"; +import { solutionPart1, puzzleInput, sample } from "./part1.js"; import { solutionPart2 } from "./part2.js"; describe("part 1", () => { @@ -13,12 +9,15 @@ describe("part 1", () => { expectSolution(solutionPart1(sample)).toEqual(2); }); test("solution", () => { - expectSolution(solutionPart1(puzzleInput)).toEqual('TODO'); + expectSolution(solutionPart1(puzzleInput)).toEqual(605); }); }); describe("part 2", () => { - test.todo("solution", () => { - expectSolution(solutionPart2(puzzleInput)).toEqual('TODO'); + test("sample", () => { + expectSolution(solutionPart2(sample)).toEqual(4); + }); + test("solution", () => { + expectSolution(solutionPart2(puzzleInput)).toEqual(914); }); });