WIP aoc 2015 day 9
This commit is contained in:
9
advent_of_code/2015/9/Cargo.toml
Normal file
9
advent_of_code/2015/9/Cargo.toml
Normal 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"
|
||||||
28
advent_of_code/2015/9/input.txt
Normal file
28
advent_of_code/2015/9/input.txt
Normal 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
|
||||||
33
advent_of_code/2015/9/src/main.rs
Normal file
33
advent_of_code/2015/9/src/main.rs
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user