From 3c49f99822c91ab74c42ab737dfa2fed3303719a Mon Sep 17 00:00:00 2001 From: Travis Hardiman Date: Fri, 13 Dec 2024 22:04:18 -0500 Subject: [PATCH 1/4] day 13, part 1 --- package.json | 2 +- public/funs.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++- views/index.html | 2 +- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f5e8e35..dbc367d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meowing-holy-carbon", - "version": "2024.12.12", + "version": "2024.12.13", "description": "Travis's Advent of Code 2024", "author": "Travis Hardiman", "homepage": "https://github.com/dieseltravis/aoc2024/", diff --git a/public/funs.js b/public/funs.js index 0e445fe..b2681b7 100644 --- a/public/funs.js +++ b/public/funs.js @@ -993,7 +993,60 @@ } }, day13: { - part1: d => d, + part1: (data) => { + const matchButtons = /X\+(\d+), Y\+(\d+)/; + const matchPrize = /X=(\d+), Y=(\d+)/; + let sum = 0; + const input = data.trim().split('\n\n').map(r => { + const claw = r.split('\n'); + const buttonA = claw[0].match(matchButtons); + const buttonB = claw[1].match(matchButtons); + const prize = claw[2].match(matchPrize); + const game = { + a: { + x: +buttonA[1], + y: +buttonA[2] + }, + b: { + x: +buttonB[1], + y: +buttonB[2] + }, + p: { + x: +prize[1], + y: +prize[2] + } + }; + // start at max B value + for (let b = 100; b--;) { + const bx = b * game.b.x; + if (bx <= game.p.x) { + const by = b * game.b.y; + if (by <= game.p.y) { + // remainder after B value + const rx = game.p.x - bx; + if (rx % game.a.x === 0) { + const ry = game.p.y - by; + if (ry % game.a.y === 0) { + // check A values are equal + const axv = rx / game.a.x; + const ayv = ry / game.a.y; + if (axv === ayv) { + game.p.b = b; + game.p.a = axv; + game.p.t = (axv * 3) + b; + sum += game.p.t; + break; + } + } + } + } + } + } + return game; + }); + console.log(input, sum); + return sum; + }, part2: d => d }, day14: { diff --git a/views/index.html b/views/index.html index 29e607c..111a487 100644 --- a/views/index.html +++ b/views/index.html @@ -32,8 +32,8 @@

solutions:

  • day 10
  • day 11
  • day 12
  • -