Skip to content

Instantly share code, notes, and snippets.

@ghusse
Created December 3, 2018 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghusse/a3f012580d832a8f70540ece6a92fc4f to your computer and use it in GitHub Desktop.
Save ghusse/a3f012580d832a8f70540ece6a92fc4f to your computer and use it in GitHub Desktop.
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