From 796d8b8bd12a027980df734417e3945d54533a59 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 9 Dec 2022 11:30:43 -0500 Subject: [PATCH 1/5] typo in template --- _templates/day/new/part1.ejs | 2 +- _templates/day/new/part2.ejs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_templates/day/new/part1.ejs b/_templates/day/new/part1.ejs index 14531b0..33430d6 100644 --- a/_templates/day/new/part1.ejs +++ b/_templates/day/new/part1.ejs @@ -13,4 +13,4 @@ const readInput = (...args) => export const puzzleInput = readInput(import.meta.url, "input"); export const sample = readInput(import.meta.url, "sample"); -export default = () => {}; +export default () => {}; diff --git a/_templates/day/new/part2.ejs b/_templates/day/new/part2.ejs index e59c761..ec6f9e3 100644 --- a/_templates/day/new/part2.ejs +++ b/_templates/day/new/part2.ejs @@ -4,4 +4,4 @@ to: 2022/<%= day %>/part2.js import * as R from "remeda"; -export default = () => {}; +export default () => {}; From ceb92bd58912a3f33dc9fe108e87cbc2fc55d300 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 9 Dec 2022 12:28:05 -0500 Subject: [PATCH 2/5] part 1 --- 2022/09/input | 2000 +++++++++++++++++++++++++++++++++++++++++++++ 2022/09/part1.js | 70 ++ 2022/09/part2.js | 4 + 2022/09/puzzle.md | 272 ++++++ 2022/09/sample | 8 + 2022/09/test.js | 40 + 6 files changed, 2394 insertions(+) create mode 100644 2022/09/input create mode 100644 2022/09/part1.js create mode 100644 2022/09/part2.js create mode 100644 2022/09/puzzle.md create mode 100644 2022/09/sample create mode 100644 2022/09/test.js diff --git a/2022/09/input b/2022/09/input new file mode 100644 index 0000000..be008e2 --- /dev/null +++ b/2022/09/input @@ -0,0 +1,2000 @@ +L 2 +D 2 +L 2 +R 2 +L 1 +U 2 +D 1 +U 2 +L 2 +D 2 +L 2 +R 1 +D 2 +L 2 +R 2 +U 1 +R 1 +U 2 +D 2 +R 1 +U 1 +L 2 +D 1 +U 2 +L 2 +R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1 +L 18 +D 15 +L 3 +R 5 +L 15 +U 5 +R 11 +D 10 +L 14 +D 2 +R 5 +U 12 +R 8 +D 10 +R 14 +D 18 +U 4 +R 18 +D 11 +R 11 +U 2 +L 7 +R 1 +U 18 +L 3 +U 13 +R 16 +D 8 +U 7 +R 1 +U 2 +R 15 +U 3 +R 13 +D 14 +L 15 +U 10 +L 12 +U 6 +R 14 +D 14 +U 1 +D 8 +R 13 +D 14 +L 10 +R 4 +D 1 +L 3 +U 13 +R 17 +D 12 +L 4 +U 15 +R 3 +U 19 +D 15 +U 2 +D 7 +U 8 +L 19 +D 17 +U 16 +D 13 +L 3 +R 16 +D 4 +R 17 +L 10 +R 5 +U 10 +L 18 +U 15 +R 11 +D 1 +R 14 +D 7 +R 4 +U 19 +R 14 +U 19 +D 16 +L 14 +R 17 +L 9 +R 16 +L 14 +D 10 +R 1 +U 2 +L 3 +R 12 +D 4 +U 12 +R 16 +L 4 +R 3 +U 9 +R 19 +U 2 +L 13 +D 11 +L 7 +D 11 +U 3 +R 1 +L 8 +R 7 +L 15 +D 9 +U 12 +D 10 +R 9 +U 16 +R 11 +L 11 +R 6 +U 11 +D 9 +L 8 +R 7 +L 9 +R 13 +D 14 +U 11 +R 14 +L 17 +U 9 +L 17 +R 9 +L 10 diff --git a/2022/09/part1.js b/2022/09/part1.js new file mode 100644 index 0000000..3027d39 --- /dev/null +++ b/2022/09/part1.js @@ -0,0 +1,70 @@ +import * as R from "remeda"; +import Victor from "@a-robu/victor"; + +import { readFile } from "../05/part1.js"; +import { passthru } from '../08/part1.js' + +const directions = { + R: new Victor(1,0), + L: new Victor(-1,0), + U: new Victor(0,1), + D: new Victor(0,-1), +} + +const parseLine = R.createPipe( + line => line.split(" "), + ([direction,times]) => Array(parseInt(times)).fill(directions[direction]) +); + + +const readInput = (...args) => R.pipe( + readFile(...args), + text => text.split("\n"), + R.compact, + R.map( parseLine ), + R.flatten, +) + +export const puzzleInput = readInput(import.meta.url, "input"); +export const sample = readInput(import.meta.url, "sample"); + +const touching = (v1,v2) => [v1.distanceX(v2), v1.distanceY(v2)].every( + x => x*x <= 1 +); + +export function moveOnce( head, tail, d ) { + head.add(d); + + if( touching(head,tail) ) return; + + const delta = head.clone().subtract(tail).normalize(); + + if( delta.x * delta.y ) { + delta.x = delta.x > 0 ? 1 : -1; + delta.y = delta.y > 0 ? 1 : -1; + } + + tail.add(delta); +} + +const moveAround = (directives) => { + const head = new Victor(0,0); + const tail = new Victor(0,0); + + const visited = [ tail.toString() ] + + for ( const d of directives ) { + moveOnce(head,tail,d); + + visited.push( tail.toString() ); + } + + return visited; +}; + +export default R.createPipe( + moveAround, + passthru( x => console.log(x) ), + R.uniq, + R.countBy( R.identity ) +); diff --git a/2022/09/part2.js b/2022/09/part2.js new file mode 100644 index 0000000..10fc179 --- /dev/null +++ b/2022/09/part2.js @@ -0,0 +1,4 @@ +import * as R from "remeda"; + + +export default () => {}; diff --git a/2022/09/puzzle.md b/2022/09/puzzle.md new file mode 100644 index 0000000..470f754 --- /dev/null +++ b/2022/09/puzzle.md @@ -0,0 +1,272 @@ +\--- Day 9: Rope Bridge --- +---------- + +This rope bridge creaks as you walk along it. You aren't sure how old it is, or whether it can even support your weight. + +It seems to support the Elves just fine, though. The bridge spans a gorge which was carved out by the massive river far below you. + +You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where *not* to step. + +Consider a rope with a knot at each end; these knots mark the *head* and the *tail* of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head. + +Due to nebulous reasoning involving [Planck lengths](https://en.wikipedia.org/wiki/Planck_units#Planck_length), you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical *series of motions* (your puzzle input) for the head, you can determine how the tail will move. + +Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (`H`) and tail (`T`) must *always be touching* (diagonally adjacent and even overlapping both count as touching): + +``` +.... +.TH. +.... + +.... +.H.. +..T. +.... + +... +.H. (H covers T) +... + +``` + +If the head is ever two steps directly up, down, left, or right from the tail, the tail must also move one step in that direction so it remains close enough: + +``` +..... ..... ..... +.TH.. -> .T.H. -> ..TH. +..... ..... ..... + +... ... ... +.T. .T. ... +.H. -> ... -> .T. +... .H. .H. +... ... ... + +``` + +Otherwise, if the head and tail aren't touching and aren't in the same row or column, the tail always moves one step diagonally to keep up: + +``` +..... ..... ..... +..... ..H.. ..H.. +..H.. -> ..... -> ..T.. +.T... .T... ..... +..... ..... ..... + +..... ..... ..... +..... ..... ..... +..H.. -> ...H. -> ..TH. +.T... .T... ..... +..... ..... ..... + +``` + +You just need to work out where the tail goes as the head follows a series of motions. Assume the head and the tail both start at the same position, overlapping. + +For example: + +``` +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 + +``` + +This series of motions moves the head *right* four steps, then *up* four steps, then *left* three steps, then *down* one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (`s` marks the starting position as a reference point): + +``` +== Initial State == + +...... +...... +...... +...... +H..... (H covers T, s) + +== R 4 == + +...... +...... +...... +...... +TH.... (T covers s) + +...... +...... +...... +...... +sTH... + +...... +...... +...... +...... +s.TH.. + +...... +...... +...... +...... +s..TH. + +== U 4 == + +...... +...... +...... +....H. +s..T.. + +...... +...... +....H. +....T. +s..... + +...... +....H. +....T. +...... +s..... + +....H. +....T. +...... +...... +s..... + +== L 3 == + +...H.. +....T. +...... +...... +s..... + +..HT.. +...... +...... +...... +s..... + +.HT... +...... +...... +...... +s..... + +== D 1 == + +..T... +.H.... +...... +...... +s..... + +== R 4 == + +..T... +..H... +...... +...... +s..... + +..T... +...H.. +...... +...... +s..... + +...... +...TH. +...... +...... +s..... + +...... +....TH +...... +...... +s..... + +== D 1 == + +...... +....T. +.....H +...... +s..... + +== L 5 == + +...... +....T. +....H. +...... +s..... + +...... +....T. +...H.. +...... +s..... + +...... +...... +..HT.. +...... +s..... + +...... +...... +.HT... +...... +s..... + +...... +...... +HT.... +...... +s..... + +== R 2 == + +...... +...... +.H.... (H covers T) +...... +s..... + +...... +...... +.TH... +...... +s..... + +``` + +After simulating the rope, you can count up all of the positions the *tail visited at least once*. In this diagram, `s` again marks the starting position (which the tail also visited) and `#` marks other positions the tail visited: + +``` +..##.. +...##. +.####. +....#. +s###.. + +``` + +So, there are `*13*` positions the tail visited at least once. + +Simulate your complete hypothetical series of motions. *How many positions does the tail of the rope visit at least once?* + +To begin, [get your puzzle input](9/input). + +Answer: + +You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Rope+Bridge%22+%2D+Day+9+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle. \ No newline at end of file diff --git a/2022/09/sample b/2022/09/sample new file mode 100644 index 0000000..9874df2 --- /dev/null +++ b/2022/09/sample @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 diff --git a/2022/09/test.js b/2022/09/test.js new file mode 100644 index 0000000..4a1df81 --- /dev/null +++ b/2022/09/test.js @@ -0,0 +1,40 @@ +import { test, expect, describe } from "vitest"; +import Victor from "@a-robu/victor"; + +const V = (...args) => new Victor(...args); + +import { expectSolution } from "../01/main.js"; +import part1, { moveOnce, sample, puzzleInput } from "./part1.js"; +import part2 from "./part2.js"; + +describe("part 1", () => { + test( "moveOnce", () => { + let head = V(1,0); + let tail = V(0,0); + moveOnce(head,tail,V(1,0)); + + expect(tail).toMatchObject({x:1,y:0}); + + moveOnce(head,tail,V(0,1)); + + expect(tail).toMatchObject({x:1,y:0}); + + moveOnce(head,tail,V(0,1)); + + expect(tail).toMatchObject({x:2,y:1}); + + } ); + + test( "sample", () => { + expect(part1(sample)).toEqual(13); + } ) + test("solution", () => { + expectSolution(part1(puzzleInput)).toEqual(6030); + }); +}); + +describe("part 2", () => { + test.todo("solution", () => { + expectSolution(part2(puzzleInput)).toEqual("TODO"); + }); +}); From 8e2126fe51516b14bdd30170cbe62c49982575b9 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 9 Dec 2022 12:33:37 -0500 Subject: [PATCH 3/5] optimize --- 2022/09/part1.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/2022/09/part1.js b/2022/09/part1.js index 3027d39..6a35258 100644 --- a/2022/09/part1.js +++ b/2022/09/part1.js @@ -35,7 +35,7 @@ const touching = (v1,v2) => [v1.distanceX(v2), v1.distanceY(v2)].every( export function moveOnce( head, tail, d ) { head.add(d); - if( touching(head,tail) ) return; + if( touching(head,tail) ) return tail.toString(); const delta = head.clone().subtract(tail).normalize(); @@ -45,26 +45,23 @@ export function moveOnce( head, tail, d ) { } tail.add(delta); + + return tail.toString(); } const moveAround = (directives) => { const head = new Victor(0,0); const tail = new Victor(0,0); - const visited = [ tail.toString() ] - - for ( const d of directives ) { - moveOnce(head,tail,d); - - visited.push( tail.toString() ); - } - - return visited; + const move = d => moveOnce(head,tail,d); + return [ + tail.toString(), + ...directives.map( move ) + ] }; export default R.createPipe( moveAround, - passthru( x => console.log(x) ), R.uniq, - R.countBy( R.identity ) + moves => moves.length ); From 0083f6995da26690f933655afcd3c3d62267c542 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 9 Dec 2022 13:05:42 -0500 Subject: [PATCH 4/5] part 2 --- 2022/09/bigSample | 8 +++++ 2022/09/part1.js | 82 +++++++++++++++++++++-------------------------- 2022/09/part2.js | 34 +++++++++++++++++++- 2022/09/puzzle.md | 19 ++++++----- 2022/09/test.js | 38 ++++++++++++---------- 5 files changed, 108 insertions(+), 73 deletions(-) create mode 100644 2022/09/bigSample diff --git a/2022/09/bigSample b/2022/09/bigSample new file mode 100644 index 0000000..60bd43b --- /dev/null +++ b/2022/09/bigSample @@ -0,0 +1,8 @@ +R 5 +U 8 +L 8 +D 3 +R 17 +D 10 +L 25 +U 20 diff --git a/2022/09/part1.js b/2022/09/part1.js index 6a35258..fcad02d 100644 --- a/2022/09/part1.js +++ b/2022/09/part1.js @@ -2,66 +2,58 @@ import * as R from "remeda"; import Victor from "@a-robu/victor"; import { readFile } from "../05/part1.js"; -import { passthru } from '../08/part1.js' +import { passthru } from "../08/part1.js"; const directions = { - R: new Victor(1,0), - L: new Victor(-1,0), - U: new Victor(0,1), - D: new Victor(0,-1), -} + R: new Victor(1, 0), + L: new Victor(-1, 0), + U: new Victor(0, 1), + D: new Victor(0, -1), +}; const parseLine = R.createPipe( - line => line.split(" "), - ([direction,times]) => Array(parseInt(times)).fill(directions[direction]) + (line) => line.split(" "), + ([direction, times]) => Array(parseInt(times)).fill(directions[direction]) ); - -const readInput = (...args) => R.pipe( - readFile(...args), - text => text.split("\n"), - R.compact, - R.map( parseLine ), - R.flatten, -) +export const readInput = (...args) => + R.pipe( + readFile(...args), + (text) => text.split("\n"), + R.compact, + R.map(parseLine), + R.flatten + ); export const puzzleInput = readInput(import.meta.url, "input"); export const sample = readInput(import.meta.url, "sample"); -const touching = (v1,v2) => [v1.distanceX(v2), v1.distanceY(v2)].every( - x => x*x <= 1 -); +export const touching = (v1, v2) => + [v1.distanceX(v2), v1.distanceY(v2)].every((x) => x * x <= 1); -export function moveOnce( head, tail, d ) { - head.add(d); +export const moveOnce = (head, tail) => (d) => { + head.add(d); - if( touching(head,tail) ) return tail.toString(); + if (touching(head, tail)) return tail.toString(); - const delta = head.clone().subtract(tail).normalize(); + const delta = head.clone().subtract(tail).normalize(); - if( delta.x * delta.y ) { - delta.x = delta.x > 0 ? 1 : -1; - delta.y = delta.y > 0 ? 1 : -1; - } + if (delta.x * delta.y) { + delta.x = delta.x > 0 ? 1 : -1; + delta.y = delta.y > 0 ? 1 : -1; + } - tail.add(delta); + tail.add(delta); - return tail.toString(); -} - -const moveAround = (directives) => { - const head = new Victor(0,0); - const tail = new Victor(0,0); - - const move = d => moveOnce(head,tail,d); - return [ - tail.toString(), - ...directives.map( move ) - ] + return tail.toString(); }; -export default R.createPipe( - moveAround, - R.uniq, - moves => moves.length -); +const moveAround = (directives) => { + const head = new Victor(0, 0); + const tail = new Victor(0, 0); + + const move = moveOnce(head, tail); + return directives.map(move); +}; + +export default R.createPipe(moveAround, R.uniq, (moves) => moves.length); diff --git a/2022/09/part2.js b/2022/09/part2.js index 10fc179..5221a09 100644 --- a/2022/09/part2.js +++ b/2022/09/part2.js @@ -1,4 +1,36 @@ import * as R from "remeda"; +import Victor from "@a-robu/victor"; +import { touching, readInput } from "./part1.js"; -export default () => {}; +export const bigSample = readInput(import.meta.url, "bigSample"); + +export const moveOnce = (knots) => (d) => { + R.first(knots).add(d); + + for (const i of R.range(1, knots.length)) { + if (touching(knots[i - 1], knots[i])) break; + + const delta = knots[i - 1].clone().subtract(knots[i]).normalize(); + + if (delta.x * delta.y) { + delta.x = delta.x > 0 ? 1 : -1; + delta.y = delta.y > 0 ? 1 : -1; + } + + knots[i].add(delta); + } + + return R.last(knots).toString(); +}; + +const moveAround = (directives) => { + const knots = Array(10) + .fill(null) + .map(() => new Victor(0, 0)); + + const move = moveOnce(knots); + return directives.map(move); +}; + +export default R.createPipe(moveAround, R.uniq, (moves) => moves.length); diff --git a/2022/09/puzzle.md b/2022/09/puzzle.md index 470f754..762df8a 100644 --- a/2022/09/puzzle.md +++ b/2022/09/puzzle.md @@ -1,17 +1,16 @@ -\--- Day 9: Rope Bridge --- ----------- +## \--- Day 9: Rope Bridge --- This rope bridge creaks as you walk along it. You aren't sure how old it is, or whether it can even support your weight. It seems to support the Elves just fine, though. The bridge spans a gorge which was carved out by the massive river far below you. -You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where *not* to step. +You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where _not_ to step. -Consider a rope with a knot at each end; these knots mark the *head* and the *tail* of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head. +Consider a rope with a knot at each end; these knots mark the _head_ and the _tail_ of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head. -Due to nebulous reasoning involving [Planck lengths](https://en.wikipedia.org/wiki/Planck_units#Planck_length), you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical *series of motions* (your puzzle input) for the head, you can determine how the tail will move. +Due to nebulous reasoning involving [Planck lengths](https://en.wikipedia.org/wiki/Planck_units#Planck_length), you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical _series of motions_ (your puzzle input) for the head, you can determine how the tail will move. -Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (`H`) and tail (`T`) must *always be touching* (diagonally adjacent and even overlapping both count as touching): +Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (`H`) and tail (`T`) must _always be touching_ (diagonally adjacent and even overlapping both count as touching): ``` .... @@ -77,7 +76,7 @@ R 2 ``` -This series of motions moves the head *right* four steps, then *up* four steps, then *left* three steps, then *down* one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (`s` marks the starting position as a reference point): +This series of motions moves the head _right_ four steps, then _up_ four steps, then _left_ three steps, then _down_ one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (`s` marks the starting position as a reference point): ``` == Initial State == @@ -250,7 +249,7 @@ s..... ``` -After simulating the rope, you can count up all of the positions the *tail visited at least once*. In this diagram, `s` again marks the starting position (which the tail also visited) and `#` marks other positions the tail visited: +After simulating the rope, you can count up all of the positions the _tail visited at least once_. In this diagram, `s` again marks the starting position (which the tail also visited) and `#` marks other positions the tail visited: ``` ..##.. @@ -263,10 +262,10 @@ s###.. So, there are `*13*` positions the tail visited at least once. -Simulate your complete hypothetical series of motions. *How many positions does the tail of the rope visit at least once?* +Simulate your complete hypothetical series of motions. _How many positions does the tail of the rope visit at least once?_ To begin, [get your puzzle input](9/input). Answer: -You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Rope+Bridge%22+%2D+Day+9+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode) [Mastodon](javascript:void(0);)] this puzzle. \ No newline at end of file +You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Rope+Bridge%22+%2D+Day+9+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode) [Mastodon]()] this puzzle. diff --git a/2022/09/test.js b/2022/09/test.js index 4a1df81..6692da7 100644 --- a/2022/09/test.js +++ b/2022/09/test.js @@ -5,36 +5,40 @@ const V = (...args) => new Victor(...args); import { expectSolution } from "../01/main.js"; import part1, { moveOnce, sample, puzzleInput } from "./part1.js"; -import part2 from "./part2.js"; +import part2, { bigSample } from "./part2.js"; describe("part 1", () => { - test( "moveOnce", () => { - let head = V(1,0); - let tail = V(0,0); - moveOnce(head,tail,V(1,0)); + test("moveOnce", () => { + let head = V(1, 0); + let tail = V(0, 0); + moveOnce(head, tail)(V(1, 0)); - expect(tail).toMatchObject({x:1,y:0}); + expect(tail).toMatchObject({ x: 1, y: 0 }); - moveOnce(head,tail,V(0,1)); + moveOnce(head, tail)(V(0, 1)); - expect(tail).toMatchObject({x:1,y:0}); + expect(tail).toMatchObject({ x: 1, y: 0 }); - moveOnce(head,tail,V(0,1)); + moveOnce(head, tail)(V(0, 1)); - expect(tail).toMatchObject({x:2,y:1}); + expect(tail).toMatchObject({ x: 2, y: 1 }); + }); - } ); - - test( "sample", () => { - expect(part1(sample)).toEqual(13); - } ) + test("sample", () => { + expect(part1(sample)).toEqual(13); + }); test("solution", () => { expectSolution(part1(puzzleInput)).toEqual(6030); }); }); describe("part 2", () => { - test.todo("solution", () => { - expectSolution(part2(puzzleInput)).toEqual("TODO"); + test("sample", () => { + expect(part2(sample)).toEqual(1); + expect(part2(bigSample)).toEqual(36); + }); + + test("solution", () => { + expectSolution(part2(puzzleInput)).toEqual(2545); }); }); From e09cacc5c538b632ba7b4c6496d6674f3ed7d538 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 9 Dec 2022 13:06:20 -0500 Subject: [PATCH 5/5] cm remove example template --- _templates/day/new/hello.ejs.t | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 _templates/day/new/hello.ejs.t diff --git a/_templates/day/new/hello.ejs.t b/_templates/day/new/hello.ejs.t deleted file mode 100644 index 099ef04..0000000 --- a/_templates/day/new/hello.ejs.t +++ /dev/null @@ -1,13 +0,0 @@ ---- -to: app/hello.js ---- -const hello = ``` -Hello! -This is your first hygen template. - -Learn what it can do here: - -https://github.com/jondot/hygen -``` - -console.log(hello)