Compare commits
No commits in common. "dbd597ad4198f046b7dd394fa46f4a6816aa0e66" and "e93f6d01cade8105fb4052aba503c49ad1355074" have entirely different histories.
dbd597ad41
...
e93f6d01ca
@ -1,102 +0,0 @@
|
|||||||
VHCKBFOVCHHKOHBPNCKO
|
|
||||||
|
|
||||||
SO -> F
|
|
||||||
OP -> V
|
|
||||||
NF -> F
|
|
||||||
BO -> V
|
|
||||||
BH -> S
|
|
||||||
VB -> B
|
|
||||||
SV -> B
|
|
||||||
BK -> S
|
|
||||||
KC -> N
|
|
||||||
SP -> O
|
|
||||||
CP -> O
|
|
||||||
VN -> O
|
|
||||||
HO -> S
|
|
||||||
PC -> B
|
|
||||||
CS -> O
|
|
||||||
PO -> K
|
|
||||||
KF -> B
|
|
||||||
BP -> K
|
|
||||||
VO -> O
|
|
||||||
HB -> N
|
|
||||||
PH -> O
|
|
||||||
FF -> O
|
|
||||||
FB -> K
|
|
||||||
CC -> H
|
|
||||||
FK -> F
|
|
||||||
HV -> P
|
|
||||||
CO -> S
|
|
||||||
OC -> N
|
|
||||||
KV -> V
|
|
||||||
SS -> O
|
|
||||||
FC -> O
|
|
||||||
NP -> B
|
|
||||||
OH -> B
|
|
||||||
OF -> K
|
|
||||||
KB -> K
|
|
||||||
BN -> C
|
|
||||||
OK -> C
|
|
||||||
NC -> O
|
|
||||||
NO -> O
|
|
||||||
FS -> C
|
|
||||||
VP -> K
|
|
||||||
KP -> S
|
|
||||||
VS -> B
|
|
||||||
VV -> N
|
|
||||||
NN -> P
|
|
||||||
KH -> P
|
|
||||||
OB -> H
|
|
||||||
HP -> H
|
|
||||||
KK -> H
|
|
||||||
FH -> F
|
|
||||||
KS -> V
|
|
||||||
BS -> V
|
|
||||||
SN -> H
|
|
||||||
CB -> B
|
|
||||||
HN -> K
|
|
||||||
SB -> O
|
|
||||||
OS -> K
|
|
||||||
BC -> H
|
|
||||||
OV -> N
|
|
||||||
PN -> B
|
|
||||||
VH -> N
|
|
||||||
SK -> C
|
|
||||||
PV -> K
|
|
||||||
VC -> N
|
|
||||||
PF -> S
|
|
||||||
NB -> B
|
|
||||||
PP -> S
|
|
||||||
NS -> F
|
|
||||||
PB -> B
|
|
||||||
CV -> C
|
|
||||||
HK -> P
|
|
||||||
PK -> S
|
|
||||||
NH -> B
|
|
||||||
SH -> V
|
|
||||||
KO -> H
|
|
||||||
NV -> B
|
|
||||||
HH -> V
|
|
||||||
FO -> O
|
|
||||||
CK -> O
|
|
||||||
VK -> F
|
|
||||||
HF -> O
|
|
||||||
BF -> C
|
|
||||||
BV -> P
|
|
||||||
KN -> K
|
|
||||||
VF -> C
|
|
||||||
FN -> V
|
|
||||||
ON -> C
|
|
||||||
SF -> F
|
|
||||||
SC -> C
|
|
||||||
OO -> S
|
|
||||||
FP -> K
|
|
||||||
PS -> C
|
|
||||||
NK -> O
|
|
||||||
BB -> V
|
|
||||||
HC -> H
|
|
||||||
FV -> V
|
|
||||||
CH -> N
|
|
||||||
HS -> V
|
|
||||||
CF -> F
|
|
||||||
CN -> S
|
|
||||||
@ -1,104 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::HashMap,
|
|
||||||
fmt::{Debug, Error, Formatter},
|
|
||||||
num::ParseIntError,
|
|
||||||
ops::{Index, IndexMut},
|
|
||||||
str::FromStr,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
fn expand(template: &[u8], rules: &HashMap<&[u8], u8>) -> Vec<u8> {
|
|
||||||
let mut res = vec![0u8; template.len() * 2 - 1];
|
|
||||||
template.windows(2).enumerate().for_each(|(i, xy)| {
|
|
||||||
let z = rules[xy];
|
|
||||||
res[i * 2] = xy[0];
|
|
||||||
res[i * 2 + 1] = z;
|
|
||||||
res[i * 2 + 2] = xy[1];
|
|
||||||
});
|
|
||||||
//dbg!(String::from_utf8_lossy(&res));
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
fn count(template: &[u8]) -> (usize, usize) {
|
|
||||||
let m = template
|
|
||||||
.iter()
|
|
||||||
.fold(HashMap::<u8, usize>::new(), |mut m, v| {
|
|
||||||
*m.entry(*v).or_insert(0) += 1;
|
|
||||||
m
|
|
||||||
});
|
|
||||||
m.values()
|
|
||||||
.fold((usize::MAX, 0), |(min, max), v| (min.min(*v), max.max(*v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[aoc(day14, part1)]
|
|
||||||
fn part1(input: &str) -> Result<usize> {
|
|
||||||
let (template, rules) = input.split_once("\n\n").unwrap();
|
|
||||||
let rules: HashMap<&[u8], u8> = rules
|
|
||||||
.lines()
|
|
||||||
.map(|l| {
|
|
||||||
let (pair, insert) = l.split_once(" -> ").unwrap();
|
|
||||||
(pair.as_bytes(), insert.as_bytes()[0])
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let mut template = template.as_bytes().to_vec();
|
|
||||||
for i in 1..11 {
|
|
||||||
template = expand(&template, &rules);
|
|
||||||
//println!("After step {}: {}", i, String::from_utf8_lossy(&template));
|
|
||||||
}
|
|
||||||
let (min, max) = count(&template);
|
|
||||||
Ok(max - min)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[aoc(day14, part2)]
|
|
||||||
fn part2(input: &[u64]) -> Result<u64> {
|
|
||||||
todo!("part2");
|
|
||||||
Ok(0)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_part1() -> Result<()> {
|
|
||||||
let input = r#"
|
|
||||||
NNCB
|
|
||||||
|
|
||||||
CH -> B
|
|
||||||
HH -> N
|
|
||||||
CB -> H
|
|
||||||
NH -> C
|
|
||||||
HB -> C
|
|
||||||
HC -> B
|
|
||||||
HN -> C
|
|
||||||
NN -> C
|
|
||||||
BH -> H
|
|
||||||
NC -> B
|
|
||||||
NB -> B
|
|
||||||
BN -> B
|
|
||||||
BB -> N
|
|
||||||
BC -> B
|
|
||||||
CC -> N
|
|
||||||
CN -> C
|
|
||||||
"#
|
|
||||||
.trim();
|
|
||||||
assert_eq!(part1(input)?, 1588);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[test]
|
|
||||||
fn test_part2()->Result<()> {
|
|
||||||
let input = r#"
|
|
||||||
"#
|
|
||||||
.trim();
|
|
||||||
assert_eq!(part2(&parse(input)?)?, u64::MAX);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@ -2,7 +2,6 @@ pub mod day1;
|
|||||||
pub mod day10;
|
pub mod day10;
|
||||||
pub mod day11;
|
pub mod day11;
|
||||||
pub mod day12;
|
pub mod day12;
|
||||||
pub mod day14;
|
|
||||||
pub mod day2;
|
pub mod day2;
|
||||||
pub mod day3;
|
pub mod day3;
|
||||||
pub mod day4;
|
pub mod day4;
|
||||||
|
|||||||
@ -9,15 +9,21 @@ use anyhow::Result;
|
|||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[aoc_generator(dayX)]
|
||||||
|
fn parse(input: &str) -> Result<Vec<u64>> {
|
||||||
|
todo!("parse");
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
#[aoc(dayX, part1)]
|
#[aoc(dayX, part1)]
|
||||||
fn part1(input: &str) -> Result<usize> {
|
fn part1(input: &[u64]) -> Result<u64> {
|
||||||
todo!("part1");
|
todo!("part1");
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#[aoc(dayX, part2)]
|
#[aoc(dayX, part2)]
|
||||||
fn part2(input: &str) -> Result<usize> {
|
fn part2(input: &[u64]) -> Result<u64> {
|
||||||
todo!("part2");
|
todo!("part2");
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
@ -32,7 +38,7 @@ mod tests {
|
|||||||
let input = r#"
|
let input = r#"
|
||||||
"#
|
"#
|
||||||
.trim();
|
.trim();
|
||||||
assert_eq!(part1(input)?, usize::MAX);
|
assert_eq!(part1(&parse(input)?)?, u64::MAX);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +48,7 @@ mod tests {
|
|||||||
let input = r#"
|
let input = r#"
|
||||||
"#
|
"#
|
||||||
.trim();
|
.trim();
|
||||||
assert_eq!(part2(input)?, usize::MAX);
|
assert_eq!(part2(&parse(input)?)?, u64::MAX);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user