Browse Source

Merge branch '2022-06'

main
Yanick Champoux 6 months ago
parent
commit
102a4bef76
  1. 4
      .gitignore
  2. 10
      2022/01/test.js
  3. 56
      2022/05/Part1.pm
  4. 21
      2022/05/part1.js
  5. 91
      2022/05/part1.js.orig
  6. 23
      2022/05/part2.js
  7. 73
      2022/05/puzzle.md
  8. 8
      2022/05/test.js
  9. 7
      2022/05/test.t
  10. 1
      2022/06/input
  11. 22
      2022/06/part1.js
  12. 19
      2022/06/part2.js
  13. 62
      2022/06/puzzle.md
  14. 37
      2022/06/test.js
  15. 1
      2022/template/part2.js
  16. 9
      2022/template/test.js
  17. 7
      Taskfile.yaml

4
.gitignore vendored

@ -2,3 +2,7 @@ node_modules @@ -2,3 +2,7 @@ node_modules
.pls_cache/
.perl-version
pnpm-lock.yaml
*_BACKUP_*
*_BASE_*
*_LOCAL_*
*_REMOTE_*

10
2022/01/test.js

@ -1,14 +1,17 @@ @@ -1,14 +1,17 @@
import * as R from "remeda";
import { test, expect } from "vitest";
import fs from "fs-extra";
import path from 'path';
import { expectSolution } from './main.js';
import path from "path";
import { expectSolution } from "./main.js";
const split = (splitter) => (text) => text.split(splitter);
const sum = R.sumBy(R.identity);
const input = R.pipe(
fs.readFileSync( path.join( path.dirname(import.meta.url), "input").replace('file:',''), "utf8"),
fs.readFileSync(
path.join(path.dirname(import.meta.url), "input").replace("file:", ""),
"utf8"
),
split("\n\n"),
R.map((x) =>
split("\n")(x)
@ -18,7 +21,6 @@ const input = R.pipe( @@ -18,7 +21,6 @@ const input = R.pipe(
R.map(sum)
);
test("part 1", () => {
const maxCalories = R.pipe(input, (calories) => Math.max(...calories));

56
2022/05/Part1.pm

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
package Part1;
use 5.36.0;
our @ISA = 'Exporter';
our @EXPORT_OK = qw/ part1 $sample /;
use Path::Tiny;
our $sample = path('./sample')->slurp;
sub parse_heaps($heaps) {
my( $header, @crates ) = reverse split "\n", $heaps;
my @stacks;
while( $header !~ /^\s*$/ ) {
$header =~ s/^(\s+)\d//;
my $n = length $1;
@crates = map { no warnings; substr $_, $n } @crates;
my @stack = grep { /\w/ } map { no warnings; s/(.)//; $1 } @crates;
push @stacks, \@stack;
}
return @stacks;
}
sub parse_commands($text) {
return map { [/\d+/g] } split "\n", $text
}
sub move_stacks($stacks, $commands) {
for my $command ( @$commands ) {
for( 1..$command->[0] ) {
push $stacks->[$command->[2] - 1]->@*,
pop $stacks->[$command->[1]- 1]->@*;
}
}
return @$stacks;
}
sub part1($text) {
my( $heaps, $commands ) = split "\n\n", $text;
my @heaps = parse_heaps($heaps);
my @commands = parse_commands($commands);
my @stacks = move_stacks( \@heaps, \@commands );
return join '', map { pop @$_ } @stacks;
}
1;

21
2022/05/part1.js

@ -1,9 +1,14 @@ @@ -1,9 +1,14 @@
import * as R from "remeda";
import { readFile } from "../03/part1.js";
import fs from "fs-extra";
import path from "path";
import { fileURLToPath } from "url";
export const sample = readFile("2022", "05", "sample");
export const puzzleInput = readFile("2022", "05", "input");
export const readFile = (url, file) =>
fs.readFileSync(path.join(fileURLToPath(new URL(".", url)), file), "utf8");
export const sample = readFile(import.meta.url, "sample");
export const puzzleInput = readFile(import.meta.url, "input");
function parseHeaps(text) {
const lines = text.split("\n").filter(R.identity);
@ -54,16 +59,20 @@ function moveStacks([stacks, commands]) { @@ -54,16 +59,20 @@ function moveStacks([stacks, commands]) {
return stacks;
}
const spy = (x) => {
export const spy = (x) => {
console.log(x);
return x;
};
export const parseLines = ([heaps, commands]) => [
parseHeaps(heaps),
parseCommands(commands),
];
export const solutionPart1 = R.createPipe(
(text) => text.split("\n\n"),
([heaps, commands]) => [parseHeaps(heaps), parseCommands(commands)],
parseLines,
moveStacks,
spy,
R.map((x) => x.pop()),
(x) => x.join("")
);

91
2022/05/part1.js.orig

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
import * as R from "remeda";
import fs from "fs-extra";
import path from "path";
import { fileURLToPath } from "url";
export const readFile = (url, file) =>
fs.readFileSync(path.join(fileURLToPath(new URL(".", url)), file), "utf8");
export const sample = readFile(import.meta.url, "sample");
export const puzzleInput = readFile(import.meta.url, "input");
function parseHeaps(text) {
const lines = text.split("\n").filter(R.identity);
lines.reverse();
let [header, ...crates] = lines;
const stacks = [];
while (header.trimEnd()) {
header = header.replace(/^(\s+)\d/, (...args) => {
crates = crates.map((c) => c.slice(args[1].length));
const stack = [];
crates = crates.map((l) =>
l.replace(/./, (c) => {
if (c !== " ") stack.push(c);
return "";
})
);
stacks.push(stack);
return "";
});
}
return stacks;
}
function parseCommands(text) {
return text
.split("\n")
.filter(R.identity)
.map((line) => line.match(/\d+/g).map((x) => parseInt(x)));
}
function moveStacks([stacks, commands]) {
for (let [move, from, to] of commands) {
console.log({ move, from, to });
while (move-- > 0) {
stacks[to - 1].push(stacks[from - 1].pop());
}
}
return stacks;
}
<<<<<<< HEAD
const spy = (x) => {
console.log(x);
return x;
};
export const solutionPart1 = R.createPipe(
(text) => text.split("\n\n"),
([heaps, commands]) => [parseHeaps(heaps), parseCommands(commands)],
moveStacks,
spy,
=======
export const spy = (x) => {
console.log(x);
return x;
};
export const parseLines = ([heaps, commands]) => [
parseHeaps(heaps),
parseCommands(commands),
];
export const solutionPart1 = R.createPipe(
(text) => text.split("\n\n"),
parseLines,
moveStacks,
>>>>>>> 2a1e7da (part 1)
R.map((x) => x.pop()),
(x) => x.join("")
);

23
2022/05/part2.js

@ -1 +1,24 @@ @@ -1 +1,24 @@
import * as R from "remeda";
import { parseLines, spy } from "./part1.js";
function moveStacks([stacks, commands]) {
for (let [move, from, to] of commands) {
console.log({ move, from, to });
stacks[to - 1].push(
...stacks[from - 1].splice(stacks[from - 1].length - move)
);
}
return stacks;
}
export default R.createPipe(
(text) => text.split("\n\n"),
parseLines,
moveStacks,
spy,
R.map((x) => x.pop()),
(x) => x.join("")
);

73
2022/05/puzzle.md

@ -70,8 +70,77 @@ The Elves just need to know _which crate will end up on top of each stack_; in t @@ -70,8 +70,77 @@ The Elves just need to know _which crate will end up on top of each stack_; in t
_After the rearrangement procedure completes, what crate ends up on top of each stack?_
To begin, [get your puzzle input](5/input).
Your puzzle answer was `VPCDMSLWJ`.
The first half of this puzzle is complete! It provides one gold star: \*
## \--- Part Two ---
As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction.
Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a _CrateMover 9001_.
The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and _the ability to pick up and move multiple crates at once_.
Again considering the example above, the crates begin in the same configuration:
```
[D]
[N] [C]
[Z] [M] [P]
1 2 3
```
Moving a single crate from stack 2 to stack 1 behaves the same as before:
```
[D]
[N] [C]
[Z] [M] [P]
1 2 3
```
However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates _stay in the same order_, resulting in this new configuration:
```
[D]
[N]
[C] [Z]
[M] [P]
1 2 3
```
Next, as both crates are moved from stack 2 to stack 1, they _retain their order_ as well:
```
[D]
[N]
[C] [Z]
[M] [P]
1 2 3
```
Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate `C` that gets moved:
```
[D]
[N]
[Z]
[M] [C] [P]
1 2 3
```
In this example, the CrateMover 9001 has put the crates in a totally different order: `*MCD*`.
Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. _After the rearrangement procedure completes, what crate ends up on top of each stack?_
Answer:
You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=%22Supply+Stacks%22+%2D+Day+5+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F5&related=ericwastl&hashtags=AdventOfCode) [Mastodon](<javascript:void(0);>)] this puzzle.
Although it hasn't changed, you can still [get your puzzle input](5/input).
You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Supply+Stacks%22+%2D+Day+5+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F5&related=ericwastl&hashtags=AdventOfCode) [Mastodon](<javascript:void(0);>)] this puzzle.

8
2022/05/test.js

@ -2,19 +2,19 @@ import { test, expect, describe } from "vitest"; @@ -2,19 +2,19 @@ import { test, expect, describe } from "vitest";
import { expectSolution } from "../01/main.js";
import { solutionPart1, puzzleInput, sample } from "./part1.js";
import { solutionPart2 } from "./part2.js";
import part2 from "./part2.js";
describe("part 1", () => {
test("sample", () => {
expect(solutionPart1(sample)).toEqual("CMZ");
});
test.only("solution", () => {
test("solution", () => {
expectSolution(solutionPart1(puzzleInput)).toEqual("VPCDMSLWJ");
});
});
describe("part 2", () => {
test.todo("solution", () => {
expectSolution(solutionPart2(puzzleInput)).toEqual("TODO");
test("solution", () => {
expectSolution(part2(puzzleInput)).toEqual("TPWCGNCCG");
});
});

7
2022/05/test.t

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
use 5.36.0;
use Test2::V0;
use Part1 qw/ part1 $sample /;
is part1($sample) => 'CMZ';

1
2022/06/input

@ -0,0 +1 @@ @@ -0,0 +1 @@
vftfrfcrfrpptffhnnnsznzgngqgsssczcjcdcssmgmtmnmqnmmfttbdttqtggmgpmmqrqzrzttptpdtpddqfdffgjgzjzczjcjjvttvmmrwmrwwjtwjttnccgbcbjbgjjcvvsqshszhzvhvsstjjljcczmzjmzzdtzzhfhvvvflljtllfqqdmmmhmfhffzhhtgtssqppgcppfjjrnngwwrvrvqvpppcspsrrsqqqlmmpcmcjmmjhmhzzpnnggmjjrprptpccdggcrrwfwggsfggbbqlqflqqcsqqccqzqbbnbmmlzllnhnwwsjsgstgttfdtffzfvzvbzzrlzlppcsctcncrncnjnfnqnvngnzzscslsppdqdbbthhqvqfvqqvccvdcddsllnwnqwwsccjmcjmmfmppnzpzffslffjrfjftftrffwcwppfsftssdwdzzffnwndnvnggbbfbgfbbfmbbjzzdqdtqtfqqpzzqpzpllvrrbqqbcqqzvznzmmwcwtwftwfwtftvtddhldldblbzlbzlllcjjwllvcllqplqplpzlzqzsqzsznnqwnqqrcqqnrrhmmqbqqlbqqrhrrdgrrsqssnwsnswsgsfsbbdhbdbqqtsqsbsmmbtmmghhcththrrnvvnlvvdvwwjwmwbmmvtvztzmtmrmprpvvmbmrbrsbbpsbbtccwgccbctbccjrjcjtccrrdnnwwqrwwjpjtptcpcfpfvfjjtqtnqqvzqqfhfrftrrgqgbqqtwwthwhqwqjqmmlglnlrnlrnnshsmspmmfnnqwqgwqqprpbbjbhjbbfqftfwwjhhcpcgcpcvppgfgcfgffbzbfzbzqzccmppndppspbssnbbpdpjpgpngpnggtztjzjdjhjmmwrmmqhhcvvvltvllvmvpvlplwplpmllgpllczlzpzczwzswwqgqbqppcjjhjddgccfmmctcjcscczzzjzwzjjsccdmdppdrdccmttjpttqvqdqtdqtqhqchhhtbbddmhhwdhdwdjdccnhcnndpdldvldlvddbjdbjbppjbpbssqnqnmmmclcggrmmdnnwmwddvjvdvrvzzglzlnnllhqqrbbcvvdtttdvvnfnqqstszsjsrscspszppfjjfttgqttdpdbbbvnndbdcdqdrdhhdhhdjjjzzhqqrcrvccrvrtvtnvnpppccpdpccjgjmjzzbsbgsbstsbbtdttrqtrrsrdrdcdjcddbcbjcbjbwbbslbbbbnmmtsmmrwrnwwqtqzqpprhrzhrhhldddrpdrpdpwdpwdpwwlmmzssbwswppldlmddphhnfhhczhhqrrdgdjjdttztftzffdvddqnqvvlbbncnffssbnbfnnzbnznhzhdzzrqzzptzppsnsnzntzzfwfzzvrzrbzrbzrbzrrqqltqlqppbwppmvpmvpmmbnnbhbmbdmbbhmmngmgmhgmghhvttzzfvfggrrchrrbffzjzlzsllbqqhqrrmqrrlzzsqzqqmhhmnmtntstnsnhsnnwwpdphhgjhjccbcqcjcbjbttmssqffjzjmzmqqrbbfnffcbfcfzfrzztftntbntttlddvwdvdcdhcdhdbbjfjzjwpbcvlqvcwjrcjssdfmgwrhrjvhpgqsbtzqqdwjrqsjplqjdzdcrtvqlcrfpcgwpjnbpcmbwnwbzhcvjvzzpvqnzdqdgpfrvdpfdmpprmzmghdfjjzfqjqcbplwntzmsrpqclgrqzhlsgwffqqntswnjsmrcpjlsvdrmcwdgqzsbsbvhbszqgwqffcgbqmjrfjdvbpwbrzwbjgvvjchwfscrhrtzbghjlcnsqqhdgqtdcqrrpsbzqvjwptblszrtffhwcvbngnsdjgpscfzwrncwlpfqgwdzffsqmjcbrlffftpvhjchmgmgqvjnpfsjnfzddqjsfqcpjgfrfgrtlmtfqphjfmdcvmghrdqvbbbhlstgpcgmqnwpdjwbrdbntbpncnztmnmzmsjzrwjmccqslngrvbjcjjgcvnvhsslfhwpwtjjcwgzqpdvqrlbttnnwdphztmwcdlvlqggrdprmzdfpbfhmsgqznzjhdqpmhfphqcvbfqmhnfpcvstrhdbtmljnnhqtfnpdwnszfrflsbbqjsvbvggzfhlcljwlrlfnlwlzzllzbqftlwzqsvwlldslnfnnbhlwmhqhrjlqzpdsjlhjncpwtnpnqvjtzzjnmdntmbjbcwphplbcwdfcqbhhnjnjsfplgwbrqpqmghnzvdprtlmgvwhdgpdwfvdtqtnqdvbntmsrhftwvrgwcbvhnwmhfggdzfgbdfqsbngmvjgssclqlhqggwndzzhcrzrmnzggnvbbbpzfdjtnlvlnprjtlljhtdqjlddmjdswjrwhwdbbbrmpwsgpfgnplbtzfzlvgnfrvvnbjtsglbzmtmcjbbjclmjgtdrrbpbbqzqnvrgqssfrwhrtpsbgsvnnfbmqgbvhshmpqtqljlpwptqzprdbgnzmlgtrvgnmmfhtccsvbmsfnlnzwhrmcnwmmhgwclghgmspwjvbgqrbbhhrglstdntwnvcgdcmwgbwrwhsqzsdnqsvmcbzrvtztspshrfmqbtrdtnsqdllqzdcbmvbdswzrrzchqgpgmhvjgwgnpqfwcmchsnqssnnslzwtwvbqjfbhlbdjzjrqjvsshcvcbwhsvvwtmjwjfgszmvfzclbqjhnczqcznprwzjnlgmdgbfjnrqfgvstcldnttbjmhsqgqlmzqtsqngvmdvrwcjtfljzdmnndnrbqnlqtmsqngflwsghzzsfcdnttpblqqhmtgnqmcdfmclsvgnsfpnnfssqzjtdsjbjnnmqhfctlddtwrqlpczlzvhddrtjfwgqhfcvchzqgfhdbfpbvtqcjvchqmwhvwjrbtcjgbfqjdsbfpgjrzvlgqwphshnqrvqsppgsnfswvrzpwmdfmmwntnsddzppffjvbnshhqgwclvtpjzvlbdzblhhmhrmjrpmltglsdffnstsdqwjhnjccqhbdrgnwmpwczflfvsbznpphgpbfzffbcdnbrqbwddlhvgqsdmdhmlzbdztrrswsbvdgptvhhcdtwzqqhzqpswwvftppwvwhrspfqwppjbdlhcchlftjhrpwhtvqhmwwtcbfhgbqzvzdlwlzwcsqgvmmsnhrfmwwpcrjlsgzmgdqstlwbzrzbqfnpqffmjqbqqzcnsqrfstnwjflwlpfgcjwjdvtjslrcpgwsvrbvjtzqvnjlqrvvwjhzbzqqjhcrbdtwqjbtmwfrmcgnbdcrhrvlcgrgtglpfmvpgwbzccddlrbsjzwbgwthhdmjjtpchtsbnnpgqfcpmsrgvqwhcdqzmtzlzbfdgmvtqzzdcrnhtlcwnmhdjtwdsrfnlmwpnfwdrptclvwrnwrnntwwqvfmjgswbtqcvmbfbgstvsntndzhjjnjfblqdqrgchchtgdwtvlqzrlpsqgbltjzjngdscdczwzhnlszpdnvnbrmfmjpdzvjfgvtwtpwdjjfgspbvtdjrwzncdpbsthgcwvvdbbvpvqdqpzjmlzhtjmjwmzsmrcstrsvbccqhppwrtmslggqbgglgrgffrbwzmbghfqclwwgssgghqjgfjgvwjhhwnntnrnhmfslqpmwzlggsbmrjjgfzfpjlvmshfsdjtshdlfzvjtlqwjbbgmnjhrhtpbgvcsjvwzlqvfchhpfwsbhcztmdgfzgsmszwfbvvgmgpqsrbzvtpmpqdvhgrjmmspnswjrjnjqfgjwsfbzhwhtlfwjfdhgsvcwqlbznqlnhsmzwltfwclcwgjdbhqvjbbchmcpptmpdqzwpfwrbmchpbqndtmdrwtcvlmrrnvhnpzwqcwwgmcblzvnzbzsspwchtqvjmphqtzgwdzqlbvgdjbssdjwljhlsjwzrdvqtrzcdwszqgfdwgnqdrmssqqhtblqzdhtqtqmlbbfhzvlbrphcjhzpvvshjffnsjcbgvngnsjmfdbgfzphjc

22
2022/06/part1.js

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
import * as R from "remeda";
import { readFile } from "../05/part1.js";
export const puzzleInput = readFile(import.meta.url, "input");
export default function (code) {
const size = 4;
let index = size;
while (true) {
if (
R.pipe(
code,
(c) => c.substr(index - size, size).split(""),
R.uniq,
(c) => c.length
) === size
)
return index;
index++;
}
}

19
2022/06/part2.js

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
import * as R from "remeda";
export default function (code) {
const size = 14;
let index = size;
while (true) {
if (
R.pipe(
code,
(c) => c.substr(index - size, size).split(""),
R.uniq,
(c) => c.length
) === size
)
return index;
index++;
}
}

62
2022/06/puzzle.md

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
## \--- Day 6: Tuning Trouble ---
The preparations are finally complete; you and the Elves leave camp on foot and begin to make your way toward the _star_ fruit grove.
As you move through the dense undergrowth, one of the Elves gives you a handheld _device_. He says that it has many fancy features, but the most important one to set up right now is the _communication system_.
However, because he's heard you have [significant](/2016/day/6) [experience](/2016/day/25) [dealing](/2019/day/7) [with](/2019/day/9) [signal-based](/2019/day/16) [systems](/2021/day/25), he convinced the other Elves that it would be okay to give you their one malfunctioning device - surely you'll have no problem fixing it.
As if inspired by comedic timing, the device emits a few colorful sparks.
To be able to communicate with the Elves, the device needs to _lock on to their signal_. The signal is a series of seemingly-random characters that the device receives one at a time.
To fix the communication system, you need to add a subroutine to the device that detects a _start-of-packet marker_ in the datastream. In the protocol being used by the Elves, the start of a packet is indicated by a sequence of _four characters that are all different_.
The device will send your subroutine a datastream buffer (your puzzle input); your subroutine needs to identify the first position where the four most recently received characters were all different. Specifically, it needs to report the number of characters from the beginning of the buffer to the end of the first such four-character marker.
For example, suppose you receive the following datastream buffer:
```
mjqjpqmgbljsphdztnvjfqwrcgsmlb
```
After the first three characters (`mjq`) have been received, there haven't been enough characters received yet to find the marker. The first time a marker could occur is after the fourth character is received, making the most recent four characters `mjqj`. Because `j` is repeated, this isn't a marker.
The first time a marker appears is after the _seventh_ character arrives. Once it does, the last four characters received are `jpqm`, which are all different. In this case, your subroutine should report the value `*7*`, because the first start-of-packet marker is complete after 7 characters have been processed.
Here are a few more examples:
- `bvwbjplbgvbhsrlpgdmjqwftvncz`: first marker after character `*5*`
- `nppdvjthqldpwncqszvftbrmjlhg`: first marker after character `*6*`
- `nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg`: first marker after character `*10*`
- `zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw`: first marker after character `*11*`
_How many characters need to be processed before the first start-of-packet marker is detected?_
Your puzzle answer was `1640`.
## \--- Part Two ---
Your device's communication system is correctly detecting packets, but still isn't working. It looks like it also needs to look for _messages_.
A _start-of-message marker_ is just like a start-of-packet marker, except it consists of _14 distinct characters_ rather than 4.
Here are the first positions of start-of-message markers for all of the above examples:
- `mjqjpqmgbljsphdztnvjfqwrcgsmlb`: first marker after character `*19*`
- `bvwbjplbgvbhsrlpgdmjqwftvncz`: first marker after character `*23*`
- `nppdvjthqldpwncqszvftbrmjlhg`: first marker after character `*23*`
- `nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg`: first marker after character `*29*`
- `zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw`: first marker after character `*26*`
_How many characters need to be processed before the first start-of-message marker is detected?_
Your puzzle answer was `3613`.
Both parts of this puzzle are complete! They provide two gold stars: \*\*
At this point, you should [return to your Advent calendar](/2022) and try another puzzle.
If you still want to see it, you can [get your puzzle input](6/input).
You can also [Shareon [Twitter](https://twitter.com/intent/tweet?text=I%27ve+completed+%22Tuning+Trouble%22+%2D+Day+6+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F6&related=ericwastl&hashtags=AdventOfCode) [Mastodon](<javascript:void(0);>)] this puzzle.

37
2022/06/test.js

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
import { test, expect, describe } from "vitest";
import { expectSolution } from "../01/main.js";
import part1, { puzzleInput } from "./part1.js";
import part2 from "./part2.js";
describe("part 1", () => {
test("samples", () => {
expect(part1("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(7);
Object.entries({
bvwbjplbgvbhsrlpgdmjqwftvncz: 5,
nppdvjthqldpwncqszvftbrmjlhg: 6,
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 10,
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 11,
}).forEach(([code, index]) => expect(part1(code)).toEqual(index));
});
test("solution", () => {
expectSolution(part1(puzzleInput)).toEqual(1640);
});
});
describe("part 2", () => {
test("samples", () => {
expect(part2("mjqjpqmgbljsphdztnvjfqwrcgsmlb")).toEqual(19);
Object.entries({
bvwbjplbgvbhsrlpgdmjqwftvncz: 23,
nppdvjthqldpwncqszvftbrmjlhg: 23,
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: 29,
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: 26,
}).forEach(([code, index]) => expect(part2(code)).toEqual(index));
});
test("solution", () => {
expectSolution(part2(puzzleInput)).toEqual(3613);
});
});

1
2022/template/part2.js

@ -1,2 +1 @@ @@ -1,2 +1 @@
import * as R from "remeda";

9
2022/template/test.js

@ -1,20 +1,17 @@ @@ -1,20 +1,17 @@
import { test, expect, describe } from "vitest";
import { expectSolution } from "../01/main.js";
import {
solutionPart1,
puzzleInput,
} from "./part1.js";
import { solutionPart1, puzzleInput } from "./part1.js";
import { solutionPart2 } from "./part2.js";
describe("part 1", () => {
test.todo("solution", () => {
expectSolution(solutionPart1(puzzleInput)).toEqual('TODO');
expectSolution(solutionPart1(puzzleInput)).toEqual("TODO");
});
});
describe("part 2", () => {
test.todo("solution", () => {
expectSolution(solutionPart2(puzzleInput)).toEqual('TODO');
expectSolution(solutionPart2(puzzleInput)).toEqual("TODO");
});
});

7
Taskfile.yaml

@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
version: "3"
vars:
YEAR: 2022
DAY:
sh: date '+%d' | perl -pe's/^0//'
GREETING: Hello, World!
tasks:
@ -18,6 +21,10 @@ tasks: @@ -18,6 +21,10 @@ tasks:
cmds:
- npx prettier --write {{.CLI_ARGS | default "." }}
page:
cmds:
- firefox https://adventofcode.com/{{.YEAR}}/day/{{.DAY}}
default:
cmds:
- echo "{{.GREETING}}"

Loading…
Cancel
Save