From f745249762e6a22fd63a64bbe9da2eb61432b3b4 Mon Sep 17 00:00:00 2001 From: Travis Hardiman Date: Mon, 2 Dec 2024 21:53:26 -0500 Subject: [PATCH 1/3] day 2, part 1, sample works --- README.md | 2 +- package.json | 2 +- public/funs.js | 30 +++++++++++++++++++++++++++++- views/index.html | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9410ba9..9173ece 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ my 2024 solutions on ~~glitch: [meowing-holy-carbon](https://meowing-holy-carbon also on github: [dieseltravis/aoc2024](https://github.com/dieseltravis/aoc2024) -[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-01-blueviolet)](https://adventofcode.com/2024/) [![Node.js CI](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml/badge.svg)](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard) +[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-2-blueviolet)](https://adventofcode.com/2024/) [![Node.js CI](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml/badge.svg)](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard) ## solutions: Install node `>18.18.x`, `yarn`, and then run `yarn install` and then `yarn start`. diff --git a/package.json b/package.json index 2aa64af..7dea2ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meowing-holy-carbon", - "version": "2024.12.01", + "version": "2024.12.02", "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 80eed54..01c5e31 100644 --- a/public/funs.js +++ b/public/funs.js @@ -45,7 +45,35 @@ } }, day2: { - part1: d => d, + part1: (data) => { + const input = data.trim().split('\n').map(r => r.split(' ').map(Number)).reduce((acc, r) => { + let ascending = 0 + let descending = 0 + const max = r.reduce((diff, c, i) => { + if (i > 0) { + const fromPrev = r[i - 1] - c; + diff = Math.max(diff, Math.abs(fromPrev)); + const ordering = fromPrev > 0 ? 1 : fromPrev < 0 ? -1 : 0; + if (ordering > 0) { + ascending++; + } else if (ordering < 0) { + descending++; + } + } + return diff; + }, 0); + acc.push({ + row: r, + max, + allMoved: (r.length - 1 === ascending + descending), + isOrder: (ascending === 0 || descending === 0) + }); + return acc; + }, []); + console.log(input); + + return input.filter(r => r.max <= 3 && r.allMoved && r.isOrder).length; + }, part2: d => d }, day3: { diff --git a/views/index.html b/views/index.html index a7715bd..3b1e63e 100644 --- a/views/index.html +++ b/views/index.html @@ -21,8 +21,8 @@

Travis's Advent of Code 2024

solutions:

  1. day 01
  2. -