Mock up data structures for 2023 day5

This commit is contained in:
Timothy Warren 2023-12-11 11:19:44 -05:00
parent fb82f2970f
commit 05f4a22e69
2 changed files with 112 additions and 0 deletions

View File

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

View File

@ -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<u64>,
to_range: Range<u64>,
}
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<u64>,
maps: HashMap<(DataType, DataType), Vec<DataMap>>,
}
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");
}