diff --git a/2023/day/2/main.rs b/2023/day/2/main.rs new file mode 100644 index 0000000..b3cf52a --- /dev/null +++ b/2023/day/2/main.rs @@ -0,0 +1,44 @@ +use std::fs::File; +use std::io::{self, BufRead}; +use std::path::Path; +use regex::Regex; + +fn main() { + if let Ok(lines) = read_lines("./input") { + for line in lines { + if let Ok(text) = line { + Game g = parse_game(text); + } else { + println!("Error on line \"{:?}\"", line); + } + } + } +} + +struct Bag { + red: u32, + green: u32, + blue: u32, +} + +struct Set { + red: u32, + green: u32, + blue: u32, +} + +struct Game { + ID: u32, + Vec, +} + +fn parse_game(text: &String) -> Result { + let re = Regex::new(r"^Game ([0-9]+)(?:(?:(?::|;) )((?:[0-9]+ (?:red|blue|green)(?:, )?)+))+$").unwrap(); + // TODO: Extract all captures. The second capture group only returns the last of the match. +} + +fn read_lines

(filename: P) -> io::Result>> +where P: AsRef, { + let file = File::open(filename)?; + Ok(io::BufReader::new(file).lines()) +}