add 2023/13/1
This commit is contained in:
parent
ff7cfe5768
commit
f23a95e2e2
File diff suppressed because it is too large
Load Diff
|
@ -40,21 +40,21 @@ fn part2(parsed: &Parsed) -> usize {
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
boilerplate! {
|
||||||
const TEST_INPUT_2: &str = "two1nine
|
TEST_INPUT == "\
|
||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet",
|
||||||
|
TEST_INPUT_2 == "\
|
||||||
|
two1nine
|
||||||
eightwothree
|
eightwothree
|
||||||
abcone2threexyz
|
abcone2threexyz
|
||||||
xtwone3four
|
xtwone3four
|
||||||
4nineeightseven2
|
4nineeightseven2
|
||||||
zoneight234
|
zoneight234
|
||||||
7pqrstsixteen";
|
7pqrstsixteen"
|
||||||
|
for tests: {
|
||||||
boilerplate! {
|
|
||||||
TEST_INPUT == "1abc2
|
|
||||||
pqr3stu8vwx
|
|
||||||
a1b2c3d4e5f
|
|
||||||
treb7uchet",
|
|
||||||
tests: {
|
|
||||||
part1: { TEST_INPUT => 142 },
|
part1: { TEST_INPUT => 142 },
|
||||||
part2: { TEST_INPUT_2 => 281 },
|
part2: { TEST_INPUT_2 => 281 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -49,8 +49,8 @@ Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green",
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 8 },
|
part1: { TEST_INPUT => 8 },
|
||||||
part2: { TEST_INPUT => 2286 },
|
part2: { TEST_INPUT => 2286 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -92,8 +92,8 @@ boilerplate! {
|
||||||
..592.....
|
..592.....
|
||||||
......755.
|
......755.
|
||||||
...$.*....
|
...$.*....
|
||||||
.664.598..",
|
.664.598.."
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 4361 },
|
part1: { TEST_INPUT => 4361 },
|
||||||
part2: { TEST_INPUT => 467835 },
|
part2: { TEST_INPUT => 467835 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,8 +46,8 @@ Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11",
|
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 13 },
|
part1: { TEST_INPUT => 13 },
|
||||||
part2: { TEST_INPUT => 30 },
|
part2: { TEST_INPUT => 30 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -116,8 +116,8 @@ temperature-to-humidity map:
|
||||||
|
|
||||||
humidity-to-location map:
|
humidity-to-location map:
|
||||||
60 56 37
|
60 56 37
|
||||||
56 93 4",
|
56 93 4"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 35 },
|
part1: { TEST_INPUT => 35 },
|
||||||
part2: { TEST_INPUT => 46 },
|
part2: { TEST_INPUT => 46 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,8 +29,8 @@ fn part2((_, (time, distance)): &Parsed) -> usize {
|
||||||
boilerplate! {
|
boilerplate! {
|
||||||
TEST_INPUT == "\
|
TEST_INPUT == "\
|
||||||
Time: 7 15 30
|
Time: 7 15 30
|
||||||
Distance: 9 40 200",
|
Distance: 9 40 200"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 288 },
|
part1: { TEST_INPUT => 288 },
|
||||||
part2: { TEST_INPUT => 71503 },
|
part2: { TEST_INPUT => 71503 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -93,8 +93,8 @@ boilerplate! {
|
||||||
T55J5 684
|
T55J5 684
|
||||||
KK677 28
|
KK677 28
|
||||||
KTJJT 220
|
KTJJT 220
|
||||||
QQQJA 483",
|
QQQJA 483"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 6440 },
|
part1: { TEST_INPUT => 6440 },
|
||||||
part2: { TEST_INPUT => 5905 },
|
part2: { TEST_INPUT => 5905 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -75,8 +75,15 @@ fn part2(parsed: &Parsed) -> usize {
|
||||||
parsed.1.iter().filter(|&&n| ends_with(n, b'A')).fold(1, |acc, n| lcm(acc, steps_until(parsed, *n)))
|
parsed.1.iter().filter(|&&n| ends_with(n, b'A')).fold(1, |acc, n| lcm(acc, steps_until(parsed, *n)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
boilerplate! {
|
||||||
const TEST_INPUT_P2: &str = "LR
|
TEST_INPUT == "\
|
||||||
|
LLR
|
||||||
|
|
||||||
|
AAA = (BBB, BBB)
|
||||||
|
BBB = (AAA, ZZZ)
|
||||||
|
ZZZ = (ZZZ, ZZZ)",
|
||||||
|
TEST_INPUT_P2 == "\
|
||||||
|
LR
|
||||||
|
|
||||||
11A = (11B, XXX)
|
11A = (11B, XXX)
|
||||||
11B = (XXX, 11Z)
|
11B = (XXX, 11Z)
|
||||||
|
@ -85,15 +92,8 @@ const TEST_INPUT_P2: &str = "LR
|
||||||
22B = (22C, 22C)
|
22B = (22C, 22C)
|
||||||
22C = (22Z, 22Z)
|
22C = (22Z, 22Z)
|
||||||
22Z = (22B, 22B)
|
22Z = (22B, 22B)
|
||||||
XXX = (XXX, XXX)";
|
XXX = (XXX, XXX)"
|
||||||
|
for tests: {
|
||||||
boilerplate! {
|
|
||||||
TEST_INPUT == "LLR
|
|
||||||
|
|
||||||
AAA = (BBB, BBB)
|
|
||||||
BBB = (AAA, ZZZ)
|
|
||||||
ZZZ = (ZZZ, ZZZ)",
|
|
||||||
tests: {
|
|
||||||
part1: { TEST_INPUT => 6 },
|
part1: { TEST_INPUT => 6 },
|
||||||
part2: { TEST_INPUT_P2 => 6 },
|
part2: { TEST_INPUT_P2 => 6 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -56,8 +56,8 @@ boilerplate! {
|
||||||
TEST_INPUT == "\
|
TEST_INPUT == "\
|
||||||
0 3 6 9 12 15
|
0 3 6 9 12 15
|
||||||
1 3 6 10 15 21
|
1 3 6 10 15 21
|
||||||
10 13 16 21 30 45",
|
10 13 16 21 30 45"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 114 },
|
part1: { TEST_INPUT => 114 },
|
||||||
part2: { TEST_INPUT => 2 },
|
part2: { TEST_INPUT => 2 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -128,8 +128,8 @@ boilerplate! {
|
||||||
7S-7|
|
7S-7|
|
||||||
L|7||
|
L|7||
|
||||||
-L-J|
|
-L-J|
|
||||||
L|-JF",
|
L|-JF"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 4 },
|
part1: { TEST_INPUT => 4 },
|
||||||
part2: {
|
part2: {
|
||||||
INPUT_P2 => 4,
|
INPUT_P2 => 4,
|
||||||
|
|
|
@ -61,8 +61,8 @@ boilerplate! {
|
||||||
.........#
|
.........#
|
||||||
..........
|
..........
|
||||||
.......#..
|
.......#..
|
||||||
#...#.....",
|
#...#....."
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 374 },
|
part1: { TEST_INPUT => 374 },
|
||||||
},
|
},
|
||||||
bench1 == 9623138,
|
bench1 == 9623138,
|
||||||
|
|
|
@ -122,8 +122,8 @@ boilerplate! {
|
||||||
?#?#?#?#?#?#?#? 1,3,1,6
|
?#?#?#?#?#?#?#? 1,3,1,6
|
||||||
????.#...#... 4,1,1
|
????.#...#... 4,1,1
|
||||||
????.######..#####. 1,6,5
|
????.######..#####. 1,6,5
|
||||||
?###???????? 3,2,1",
|
?###???????? 3,2,1"
|
||||||
tests: {
|
for tests: {
|
||||||
part1: { TEST_INPUT => 21 },
|
part1: { TEST_INPUT => 21 },
|
||||||
part2: { TEST_INPUT => 525152 },
|
part2: { TEST_INPUT => 525152 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
#![feature(test, try_blocks)]
|
||||||
|
extern crate test;
|
||||||
|
use aoc2023::{boilerplate, common::*};
|
||||||
|
|
||||||
|
const DAY: usize = 13;
|
||||||
|
type Parsed<'a> = Vec<Vec<Vec<u8>>>;
|
||||||
|
|
||||||
|
fn parse_input(raw: &str) -> Parsed {
|
||||||
|
raw.split("\n\n").map(|block| block.lines().map(|l| l.as_bytes().to_vec()).collect()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_reflection(block: &[Vec<u8>]) -> Option<usize> {
|
||||||
|
'outer: for i in 0..block.len() - 1 {
|
||||||
|
let mut offset = 0;
|
||||||
|
loop {
|
||||||
|
match try { (block.get(i.checked_sub(offset)?)?, block.get(i + 1 + offset)?) } {
|
||||||
|
None => return Some(i + 1),
|
||||||
|
Some((a, b)) if a == b => offset += 1,
|
||||||
|
Some(_) => continue 'outer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part1(blocks: &Parsed) -> usize {
|
||||||
|
blocks.iter().map(|block| find_reflection(block).map(|n| n * 100).or_else(|| find_reflection(&transpose(&block))).unwrap()).sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transpose(orig: &[Vec<u8>]) -> Vec<Vec<u8>> {
|
||||||
|
let mut out = vec![vec![0; orig.len()]; orig[0].len()];
|
||||||
|
for i in 0..orig.len() {
|
||||||
|
for j in 0..orig[0].len() {
|
||||||
|
out[j][i] = orig[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part2(parsed: &Parsed) -> usize {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
boilerplate! {
|
||||||
|
TEST_INPUT_HORIZONTAL == "\
|
||||||
|
#...##..#
|
||||||
|
#....#..#
|
||||||
|
..##..###
|
||||||
|
#####.##.
|
||||||
|
#####.##.
|
||||||
|
..##..###
|
||||||
|
#....#..#",
|
||||||
|
TEST_INPUT_VERTICAL == "\
|
||||||
|
#.##..##.
|
||||||
|
..#.##.#.
|
||||||
|
##......#
|
||||||
|
##......#
|
||||||
|
..#.##.#.
|
||||||
|
..##..##.
|
||||||
|
#.#.##.#."
|
||||||
|
for tests: {
|
||||||
|
part1: {
|
||||||
|
TEST_INPUT_HORIZONTAL => 400,
|
||||||
|
TEST_INPUT_VERTICAL => 5,
|
||||||
|
},
|
||||||
|
part2: { TEST_INPUT_VERTICAL => 0 },
|
||||||
|
},
|
||||||
|
bench1 == 37561,
|
||||||
|
bench2 == 0,
|
||||||
|
bench_parse: Vec::len => 100,
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! boilerplate {
|
macro_rules! boilerplate {
|
||||||
(
|
(
|
||||||
TEST_INPUT == $ti: literal,
|
$($tin: ident == $ti: literal),+
|
||||||
tests: {
|
for tests: {
|
||||||
$($part: ident: { $($tpi: expr $(,$ati: expr)* => $to: expr),+$(,)? }),*$(,)?
|
$($part: ident: { $($tpi: expr $(,$ati: expr)* => $to: expr),+$(,)? }),*$(,)?
|
||||||
},
|
},
|
||||||
$(unittests: {
|
$(unittests: {
|
||||||
|
@ -24,7 +24,9 @@ macro_rules! boilerplate {
|
||||||
use super::*;
|
use super::*;
|
||||||
use aoc2023::*;
|
use aoc2023::*;
|
||||||
|
|
||||||
const TEST_INPUT: &str = $ti;
|
$(
|
||||||
|
const $tin: &str = $ti;
|
||||||
|
)+
|
||||||
|
|
||||||
$($($(paste::paste! {
|
$($($(paste::paste! {
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user