diff --git a/2023/day5/example-input.txt b/2023/day5/example-input.txt new file mode 100644 index 0000000..bd902a4 --- /dev/null +++ b/2023/day5/example-input.txt @@ -0,0 +1,33 @@ +seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4 \ No newline at end of file diff --git a/2023/day5/src/main.rs b/2023/day5/src/main.rs index e7a11a9..43148d4 100644 --- a/2023/day5/src/main.rs +++ b/2023/day5/src/main.rs @@ -1,3 +1,82 @@ +use std::ops::Range; +use std::collections::HashMap; +const FILE_STR: &'static str = include_str!("input.txt"); + +#[derive(Debug)] +enum DataType { + Seeds, + Soil, + Fertilizer, + Water, + Light, + Temperature, + Humidity, + Location, +} + +#[derive(Debug, Default)] +struct DataMap { + from_range: Range, + to_range: Range, +} + +impl DataMap { + fn new(from_start: u64, to_start: u64, map_length: u64) -> Self { + let to_range = to_start..to_start + map_length; + let from_range = from_start..from_start + map_length; + + DataMap { + from_range, + to_range + } + } + + fn get_dest_idx(&self, src_value: u64) -> u64 { + let src_index = src_value.checked_sub(self.to_range.start); + let dest_index = if let Some(idx) = src_index { + self.from_range.start.checked_add(idx) + } else { + Some(src_value) + }; + + match dest_index { + Some(n) => n, + None => src_value + } + } + + fn get_src_idx(&self, dest_value: u64) -> u64 { + let dest_index = dest_value.checked_sub(self.from_range.start); + let src_index = if let Some(idx) = dest_index { + self.to_range.start.checked_add(idx) + } else { + Some(dest_value) + }; + + match src_index { + Some(n) => n, + None => dest_value + } + } +} + +#[derive(Debug, Default)] +struct Almanac { + seeds: Vec, + maps: HashMap<(DataType, DataType), Vec>, +} + +impl Almanac { + fn parse(input: &str) -> Self { + todo!(); + } +} + fn main() { println!("Hello, world!"); } + +#[cfg(test)] +mod tests { + const EXAMPLE_FILE_STR: &'static str = include_str!("example-input.txt"); +} \ No newline at end of file