progree
This commit is contained in:
parent
c0827d7824
commit
9b79bdeefa
7
aoc-01/Cargo.lock
generated
Normal file
7
aoc-01/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aoc-01"
|
||||
version = "0.1.0"
|
||||
1000
aoc-01/input
Normal file
1000
aoc-01/input
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,70 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::fmt;
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
struct LocationList {
|
||||
left: Vec<i64>,
|
||||
right: Vec<i64>,
|
||||
}
|
||||
|
||||
impl LocationList {
|
||||
fn add_entries(&mut self, left: i64, right: i64) {
|
||||
self.left.push(left);
|
||||
self.right.push(right);
|
||||
}
|
||||
|
||||
fn parse_data(&mut self, data: String) {
|
||||
for entry in data.split('\n') {
|
||||
let values = entry.split(" ");
|
||||
let values_vec = values.collect::<Vec<&str>>();
|
||||
self.add_entries(
|
||||
values_vec[0].parse::<i64>().unwrap(),
|
||||
values_vec[1].parse::<i64>().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_dupes(&mut self) {
|
||||
for (outer_pos, entry_outer) in self.left.iter().enumerate() {
|
||||
for (inner_pos, entry_inner) in self.right.iter().enumerate() {
|
||||
if entry_inner == entry_outer {
|
||||
println!(
|
||||
"Outer: {}, Inner: {}, O_Pos: {}, I_POS: {}",
|
||||
entry_outer, entry_inner, outer_pos, inner_pos
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for LocationList {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Left len: {}, Right len: {}",
|
||||
self.left.len(),
|
||||
self.right.len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn load_file(path: String) -> String {
|
||||
let mut buf = String::new();
|
||||
let mut fp = File::open(path).expect("Unable to open file");
|
||||
|
||||
fp.read_to_string(&mut buf).expect("Failed to read file");
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut location_list = LocationList {
|
||||
left: Vec::<i64>::new(),
|
||||
right: Vec::<i64>::new(),
|
||||
};
|
||||
let data = load_file(String::from("input"));
|
||||
|
||||
location_list.parse_data(data);
|
||||
|
||||
println!("{:?}", location_list.check_dupes());
|
||||
}
|
||||
|
||||
6
aoc-01/test_input
Normal file
6
aoc-01/test_input
Normal file
@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
Loading…
x
Reference in New Issue
Block a user