diff --git a/advent_of_code/2015/9/Cargo.toml b/advent_of_code/2015/9/Cargo.toml new file mode 100644 index 0000000..c3650cd --- /dev/null +++ b/advent_of_code/2015/9/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "main" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +nom = "7.1.3" diff --git a/advent_of_code/2015/9/input.txt b/advent_of_code/2015/9/input.txt new file mode 100644 index 0000000..38d4369 --- /dev/null +++ b/advent_of_code/2015/9/input.txt @@ -0,0 +1,28 @@ +Faerun to Norrath = 129 +Faerun to Tristram = 58 +Faerun to AlphaCentauri = 13 +Faerun to Arbre = 24 +Faerun to Snowdin = 60 +Faerun to Tambi = 71 +Faerun to Straylight = 67 +Norrath to Tristram = 142 +Norrath to AlphaCentauri = 15 +Norrath to Arbre = 135 +Norrath to Snowdin = 75 +Norrath to Tambi = 82 +Norrath to Straylight = 54 +Tristram to AlphaCentauri = 118 +Tristram to Arbre = 122 +Tristram to Snowdin = 103 +Tristram to Tambi = 49 +Tristram to Straylight = 97 +AlphaCentauri to Arbre = 116 +AlphaCentauri to Snowdin = 12 +AlphaCentauri to Tambi = 18 +AlphaCentauri to Straylight = 91 +Arbre to Snowdin = 129 +Arbre to Tambi = 53 +Arbre to Straylight = 40 +Snowdin to Tambi = 15 +Snowdin to Straylight = 99 +Tambi to Straylight = 70 \ No newline at end of file diff --git a/advent_of_code/2015/9/src/main.rs b/advent_of_code/2015/9/src/main.rs new file mode 100644 index 0000000..7dacb01 --- /dev/null +++ b/advent_of_code/2015/9/src/main.rs @@ -0,0 +1,33 @@ +use nom::{ + bytes::complete::tag, + character::complete::{alpha1, i64, multispace1}, + multi::separated_list1, + sequence::tuple, + IResult, +}; + +fn parse_input(input: &str) -> IResult<&str, Vec<(String, String, i64)>> { + let (input, result) = separated_list1( + multispace1, + tuple((alpha1, tag(" to "), alpha1, tag(" = "), i64)) + .map(|(from, _, to, _, distance)| (from.to_string(), to.to_string(), distance)), + )(input)?; + + Ok((input, result)) +} + +fn solve_first(distances: &[(String, String, i64)]) -> i64 { + todo!() +} + +fn main() { + println!("Hello, Patrick!"); + + let input_txt = include_str!("../input.txt"); + + let (_, distances) = parse_input(input_txt).unwrap(); + + let first_result = solve_first(&distances[..]); + + println!("The shortest route is {}", first_result); +}