Ugggh not a fan of this but my brain... is tired
This commit is contained in:
parent
e0b38be791
commit
cf7b2507ae
|
@ -2,7 +2,7 @@
|
||||||
name = "aoc-vv"
|
name = "aoc-vv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "p08"
|
default-run = "p09"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,146 @@
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 1
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 4
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx -6
|
||||||
|
addx 12
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 1
|
||||||
|
addx -26
|
||||||
|
addx -12
|
||||||
|
addx 5
|
||||||
|
addx 19
|
||||||
|
addx -3
|
||||||
|
addx -13
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 15
|
||||||
|
addx -8
|
||||||
|
addx 2
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
addx -23
|
||||||
|
addx 20
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx -40
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 6
|
||||||
|
addx -2
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
addx -2
|
||||||
|
addx 9
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -14
|
||||||
|
addx 17
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 8
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -2
|
||||||
|
addx 4
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -35
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx -1
|
||||||
|
addx 5
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
addx -4
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
noop
|
||||||
|
addx 5
|
||||||
|
addx 14
|
||||||
|
addx -10
|
||||||
|
addx -25
|
||||||
|
addx 1
|
||||||
|
addx 38
|
||||||
|
addx -6
|
||||||
|
addx 2
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx -38
|
||||||
|
noop
|
||||||
|
addx 9
|
||||||
|
addx -4
|
||||||
|
noop
|
||||||
|
addx 25
|
||||||
|
addx -20
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 2
|
||||||
|
addx 5
|
||||||
|
addx 2
|
||||||
|
addx -9
|
||||||
|
addx 14
|
||||||
|
addx -2
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
addx 3
|
||||||
|
addx -2
|
||||||
|
addx 2
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx -38
|
||||||
|
noop
|
||||||
|
addx 7
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
addx 3
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 6
|
||||||
|
noop
|
||||||
|
addx 4
|
||||||
|
addx 1
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
addx 4
|
||||||
|
addx 1
|
||||||
|
addx 7
|
||||||
|
addx -3
|
||||||
|
addx 5
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
||||||
|
noop
|
|
@ -0,0 +1,55 @@
|
||||||
|
Monkey 0:
|
||||||
|
Starting items: 71, 56, 50, 73
|
||||||
|
Operation: new = old * 11
|
||||||
|
Test: divisible by 13
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 7
|
||||||
|
|
||||||
|
Monkey 1:
|
||||||
|
Starting items: 70, 89, 82
|
||||||
|
Operation: new = old + 1
|
||||||
|
Test: divisible by 7
|
||||||
|
If true: throw to monkey 3
|
||||||
|
If false: throw to monkey 6
|
||||||
|
|
||||||
|
Monkey 2:
|
||||||
|
Starting items: 52, 95
|
||||||
|
Operation: new = old * old
|
||||||
|
Test: divisible by 3
|
||||||
|
If true: throw to monkey 5
|
||||||
|
If false: throw to monkey 4
|
||||||
|
|
||||||
|
Monkey 3:
|
||||||
|
Starting items: 94, 64, 69, 87, 70
|
||||||
|
Operation: new = old + 2
|
||||||
|
Test: divisible by 19
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 6
|
||||||
|
|
||||||
|
Monkey 4:
|
||||||
|
Starting items: 98, 72, 98, 53, 97, 51
|
||||||
|
Operation: new = old + 6
|
||||||
|
Test: divisible by 5
|
||||||
|
If true: throw to monkey 0
|
||||||
|
If false: throw to monkey 5
|
||||||
|
|
||||||
|
Monkey 5:
|
||||||
|
Starting items: 79
|
||||||
|
Operation: new = old + 7
|
||||||
|
Test: divisible by 2
|
||||||
|
If true: throw to monkey 7
|
||||||
|
If false: throw to monkey 0
|
||||||
|
|
||||||
|
Monkey 6:
|
||||||
|
Starting items: 77, 55, 63, 93, 66, 90, 88, 71
|
||||||
|
Operation: new = old * 7
|
||||||
|
Test: divisible by 11
|
||||||
|
If true: throw to monkey 2
|
||||||
|
If false: throw to monkey 4
|
||||||
|
|
||||||
|
Monkey 7:
|
||||||
|
Starting items: 54, 97, 87, 70, 59, 82, 59
|
||||||
|
Operation: new = old + 8
|
||||||
|
Test: divisible by 17
|
||||||
|
If true: throw to monkey 1
|
||||||
|
If false: throw to monkey 3
|
|
@ -0,0 +1,168 @@
|
||||||
|
#![feature(iterator_try_collect)]
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::str;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
enum Direction {
|
||||||
|
Right,
|
||||||
|
Left,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Direction {
|
||||||
|
type Err = &'static str;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"R" => Ok(Direction::Right),
|
||||||
|
"L" => Ok(Direction::Left),
|
||||||
|
"U" => Ok(Direction::Up),
|
||||||
|
"D" => Ok(Direction::Down),
|
||||||
|
_ => Err("Can't parse into a direction"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
struct MoveDirective {
|
||||||
|
direction: Direction,
|
||||||
|
amount: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for MoveDirective {
|
||||||
|
type Err = Box<dyn Error>;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s.len() {
|
||||||
|
x if x >= 3 => {
|
||||||
|
Ok(MoveDirective {
|
||||||
|
direction: s[0..1].parse()?,
|
||||||
|
amount: s[2..].parse()?,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_ => Err("Can't parse.".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Movable {
|
||||||
|
fn do_move(&mut self, direction: &Direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pos = (i32, i32);
|
||||||
|
|
||||||
|
impl Movable for Pos {
|
||||||
|
fn do_move(&mut self, direction: &Direction) {
|
||||||
|
match direction {
|
||||||
|
Direction::Left => self.0 -= 1,
|
||||||
|
Direction::Right => self.0 += 1,
|
||||||
|
Direction::Up => self.1 -= 1,
|
||||||
|
Direction::Down => self.1 += 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
struct Rope {
|
||||||
|
front: Pos,
|
||||||
|
end: Pos,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Movable for Rope {
|
||||||
|
fn do_move(&mut self, direction: &Direction) {
|
||||||
|
self.front.do_move(direction);
|
||||||
|
self.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rope {
|
||||||
|
fn new() -> Rope {
|
||||||
|
Rope{
|
||||||
|
front: (0, 0),
|
||||||
|
end: (0, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
fn process(f: i32, e: i32, f2: i32, e2: i32) -> Pos {
|
||||||
|
// Check difference, clamp if abs greater than 1
|
||||||
|
// Then add the clamped difference to the front.
|
||||||
|
// E F
|
||||||
|
let d = e - f;
|
||||||
|
if d == 0 {
|
||||||
|
return (f, e2);
|
||||||
|
}
|
||||||
|
|
||||||
|
let abs = d.abs();
|
||||||
|
let endpos = f + d.signum();
|
||||||
|
(endpos, match abs {
|
||||||
|
x if x > 1 => f2,
|
||||||
|
_ => e2,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
(self.end.0, self.end.1) = process(self.front.0, self.end.0, self.front.1, self.end.1);
|
||||||
|
(self.end.1, self.end.0) = process(self.front.1, self.end.1, self.front.0, self.end.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct EtchASketch(HashSet<Pos>);
|
||||||
|
|
||||||
|
impl EtchASketch {
|
||||||
|
fn new() -> EtchASketch {
|
||||||
|
EtchASketch(HashSet::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit(&mut self, pos: Pos) {
|
||||||
|
self.0.insert(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let filename = "etc/p09.txt";
|
||||||
|
let file = fs::File::open(filename).expect("Can't open file");
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
|
||||||
|
let directives: Vec<MoveDirective> = reader.lines().flatten().flat_map(|l| l.parse()).collect();
|
||||||
|
let mut etch = EtchASketch::new();
|
||||||
|
|
||||||
|
let mut rope = Rope::new();
|
||||||
|
etch.visit(rope.end);
|
||||||
|
for directive in directives {
|
||||||
|
dbg!(&directive);
|
||||||
|
for _ in 0..directive.amount {
|
||||||
|
rope.do_move(&directive.direction);
|
||||||
|
etch.visit(rope.end);
|
||||||
|
}
|
||||||
|
dbg!(&rope);
|
||||||
|
}
|
||||||
|
|
||||||
|
//dbg!(rope, &etch);
|
||||||
|
|
||||||
|
println!("PART ONE ---------------");
|
||||||
|
dbg!(etch.0.len());
|
||||||
|
part1();
|
||||||
|
println!("\nPART TWO ---------------");
|
||||||
|
part2();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part1() {}
|
||||||
|
|
||||||
|
fn part2() {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_input() {
|
||||||
|
assert_eq!(MoveDirective{ direction: Direction::Down, amount: 42 }, "D 42".parse().unwrap());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue