WIP aoc 2015 day 9

This commit is contained in:
2023-12-04 08:46:18 +01:00
parent 1910caab51
commit 2a60712f44
3 changed files with 70 additions and 0 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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);
}