This commit is contained in:
2024-03-13 22:58:13 -07:00
parent f2eb9929d7
commit 6a0ed15470
5 changed files with 92 additions and 0 deletions

31
day12/src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
use std::env;
use std::fs::File;
use std::io::{self, BufRead};
use std::collections::BinaryHeap;
use std::cmp::Reverse;
fn find<T: Eq + Copy>(haystack: &Vec<Vec<T>>, needle: T) -> (usize, usize) {
// I just wanna play around with iters; there are better ways...
haystack.iter().enumerate()
.map(|(i, &ref row)|
(i, row.iter().enumerate()
.filter(|(_j, &ref c)| *c == needle)
.map(|(j, _c)| j)
.collect::<Vec<usize>>()))
.filter(|(_i, row)| !row.is_empty())
.map(|(i, row)| (i, *row.iter().nth(0).unwrap()))
.nth(0).unwrap()
}
fn main() {
let file = File::open(&env::args().nth(1).unwrap()).unwrap();
let map: Vec<Vec<u8>> = io::BufReader::new(file).lines().flatten()
.map(|line| line.chars().map(|c| c as u8).collect())
.collect();
let (starti, startj) = find(&map, 'S' as u8);
let (endi, endj) = find(&map, 'E' as u8);
println!("{:?}", map);
println!("{:?}, {:?} -> {:?}, {:?}", starti, startj, endi, endj);
}