Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs;
- use std::collections::HashSet;
- use std::borrow::BorrowMut;
- #[derive(Eq)]
- #[derive(PartialEq)]
- #[derive(Hash)]
- struct Coordinate {
- x: i64,
- y: i64
- }
- impl Coordinate {
- fn new(x: i64, y: i64) -> Coordinate {
- Coordinate {
- x,
- y
- }
- }
- }
- fn main() {
- println!("AoC 2015, Day 3");
- let string = fs::read_to_string("/home/michelle/AoC_2015/Day_3/input.txt")
- .expect("Error reading the file!");
- let mut set: HashSet<Coordinate> = HashSet::new();
- let mut set_2: HashSet<Coordinate> = HashSet::new();
- let mut santa = Coordinate::new(0, 0);
- let mut santa_2 = Coordinate::new(0, 0);
- let mut robo_santa = Coordinate::new(0, 0);
- let mut is_santa = true;
- for i in string.chars() {
- let current = if is_santa {
- santa_2.borrow_mut()
- } else {
- robo_santa.borrow_mut()
- };
- match i {
- '^' => {
- santa.y += 1;
- current.y += 1
- },
- '>' => {
- santa.x += 1;
- current.x += 1
- },
- 'v' => {
- santa.y -= 1;
- current.y -= 1
- },
- '<' => {
- santa.x -= 1;
- current.x -= 1
- },
- _ => ()
- }
- is_santa = !is_santa;
- set.insert(Coordinate::new(santa.x, santa.y));
- set_2.insert(Coordinate::new(current.x, current.y));
- }
- println!("Part 1: {}", set.len());
- println!("Part 2: {}", set_2.len());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement