Created
December 3, 2018 22:06
-
-
Save ghusse/a3f012580d832a8f70540ece6a92fc4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Claim { | |
id: u32, | |
x: usize, | |
y: usize, | |
width: usize, | |
height: usize, | |
} | |
fn read_claims() -> Vec<Claim> { | |
let input_file = File::open("src/day_3/input.txt").expect("file not found"); | |
let parser = Regex::new("^#(\\d+) @ (\\d+),(\\d+): (\\d+)x(\\d+)$").unwrap(); | |
return BufReader::new(input_file) | |
.lines() | |
.map(|line| line.expect("error readding the line")) | |
.map(|line| { | |
let parsed = parser.captures(&line[..]).unwrap(); | |
return Claim { | |
id: parsed.get(1).unwrap().as_str().parse::<u32>().unwrap(), | |
x: parsed.get(2).unwrap().as_str().parse::<usize>().unwrap(), | |
y: parsed.get(3).unwrap().as_str().parse::<usize>().unwrap(), | |
width: parsed.get(4).unwrap().as_str().parse::<usize>().unwrap(), | |
height: parsed.get(5).unwrap().as_str().parse::<usize>().unwrap(), | |
}; | |
}) | |
.collect(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment