--- /dev/null
+use std::collections::HashSet;
+
+fn parse(input: &str) -> (HashSet<&str>, Vec<&str>) {
+ let [tokens, buffers] = input.split("\n\n").collect::<Vec<_>>()[..] else {
+ panic!()
+ };
+ (tokens.split(", ").collect(), buffers.lines().collect())
+}
+
+fn consume<'a>(tokens: &HashSet<&str>, buf: &'a str, i: usize, j: usize) -> &'a str {
+ if j > buf.len() {
+ &buf[i..]
+ } else if tokens.contains(&buf[i..j]) {
+ if j == buf.len() {
+ ""
+ } else if !consume(tokens, buf, j, j + 1).is_empty() {
+ consume(tokens, buf, i, j + 1)
+ } else {
+ ""
+ }
+ } else {
+ consume(tokens, buf, i, j + 1)
+ }
+}
+
+pub fn part1(input: &str) -> u64 {
+ let (tokens, buffers) = parse(input);
+ buffers
+ .iter()
+ .filter(|&b| consume(&tokens, b, 0, 0).is_empty())
+ .count()
+ .try_into()
+ .unwrap()
+}
+
+pub fn part2(input: &str) -> u64 {
+ 0
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ const INPUT_STR: &str = concat!(
+ "r, wr, b, g, bwu, rb, gb, br\n",
+ "\n",
+ "brwrr\n",
+ "bggr\n",
+ "gbbr\n",
+ "rrbgbr\n",
+ "ubwu\n",
+ "bwurrg\n",
+ "brgr\n",
+ "bbrgwb\n",
+ );
+
+ #[test]
+ fn test_parse() {
+ assert_eq!(
+ parse(INPUT_STR),
+ (
+ HashSet::from(["g", "rb", "bwu", "wr", "r", "br", "b", "gb"]),
+ vec!["brwrr", "bggr", "gbbr", "rrbgbr", "ubwu", "bwurrg", "brgr", "bbrgwb"]
+ )
+ )
+ }
+
+ #[test]
+ fn test_consume() {
+ let (tokens, _) = parse(INPUT_STR);
+ assert_eq!(consume(&tokens, "brwrr", 0, 0), "");
+ assert_eq!(consume(&tokens, "bggr", 0, 0), "");
+ assert_eq!(consume(&tokens, "gbbr", 0, 0), "");
+ assert_eq!(consume(&tokens, "rrbgbr", 0, 0), "");
+ assert_eq!(consume(&tokens, "ubwu", 0, 0), "ubwu");
+ assert_eq!(consume(&tokens, "bwurrg", 0, 0), "");
+ assert_eq!(consume(&tokens, "brgr", 0, 0), "");
+ assert_eq!(consume(&tokens, "bbrgwb", 0, 0), "bbrgwb");
+ }
+
+ #[test]
+ fn test_part1() {
+ assert_eq!(part1(&crate::input(19).unwrap()), 285)
+ }
+
+ #[test]
+ #[ignore]
+ fn test_part2() {
+ assert_eq!(part2(&crate::input(0).unwrap()), 0)
+ }
+}
pub mod day12;
pub mod day13;
pub mod day14;
-pub mod day15;
+// pub mod day15;
// pub mod day16;
// pub mod day17;
// pub mod day18;
-// pub mod day19;
+pub mod day19;
// pub mod day20;
// pub mod day21;
// pub mod day22;
(day12::part1, day12::part2),
(day13::part1, day13::part2),
(day14::part1, day14::part2),
- (day15::part1, day15::part2),
+ // (day15::part1, day15::part2),
// (day16::part1, day16::part2),
// (day17::part1, day17::part2),
// (day18::part1, day18::part2),
- // (day19::part1, day19::part2),
+ (day19::part1, day19::part2),
+ (day19::part1, day19::part2),
+ (day19::part1, day19::part2),
+ (day19::part1, day19::part2),
+ (day19::part1, day19::part2),
// (day20::part1, day20::part2),
// (day21::part1, day21::part2),
// (day22::part1, day22::part2),