DEVELOPMENT ENVIRONMENT

~liljamo/aoc2024

e7712b210e6f57dad3ec2170862538c4ee3b118e — Jonni Liljamo a month ago 9bedcc7
chore: clippy, because i can't just keep ignoring it
7 files changed, 48 insertions(+), 68 deletions(-)

M src/day2/mod.rs
M src/day3/mod.rs
M src/day4/mod.rs
M src/day6/mod.rs
M src/day8/part1.rs
M src/day8/part2.rs
M src/main.rs
M src/day2/mod.rs => src/day2/mod.rs +8 -8
@@ 36,10 36,10 @@ fn part_one(input: &Path) -> anyhow::Result<i32> {
            let last = last_level.unwrap();
            let diff = (current - last).abs();
            if diff < 4 && diff > 0 {
                if current > last {
                    safes += 1;
                } else if current < last {
                    safes -= 1;
                match current.cmp(last) {
                    std::cmp::Ordering::Greater => safes += 1,
                    std::cmp::Ordering::Less => safes -= 1,
                    _ => {}
                }
                if safes.abs() == (r.len() as i32) - 1 {
                    s = 1;


@@ 95,10 95,10 @@ fn is_safe_two(r: Vec<i32>) -> i32 {
        let last = last_level.unwrap();
        let diff = (current - last).abs();
        if diff < 4 && diff > 0 {
            if current > last {
                safes += 1;
            } else if current < last {
                safes -= 1;
            match current.cmp(last) {
                std::cmp::Ordering::Greater => safes += 1,
                std::cmp::Ordering::Less => safes -= 1,
                _ => {}
            }
            if safes.abs() == (r.len() as i32) - 1 {
                s = 1;

M src/day3/mod.rs => src/day3/mod.rs +25 -29
@@ 21,37 21,33 @@ fn part_one_orig(input: &Path) -> anyhow::Result<i32> {
    reader.read_to_string(&mut buf)?;

    let mut answer = 0;
    loop {
        if let Some(mul_beg) = buf.find("mul(") {
            if let Some(mul_end) = buf[mul_beg..].find(")").map(|i| i + mul_beg) {
                let mul_input = &buf.clone()[mul_beg + 4..mul_end];
                let mut mul_inputs = mul_input.split(",");

                let mut err = false;
                let first: i32 = match mul_inputs.next().unwrap_or_default().parse() {
                    Ok(f) => f,
                    Err(_) => {
                        err = true;
                        0
                    }
                };
                let second: i32 = match mul_inputs.next().unwrap_or_default().parse() {
                    Ok(f) => f,
                    Err(_) => {
                        err = true;
                        0
                    }
                };

                if err {
                    buf.replace_range(mul_beg..mul_beg + 4, "");
                } else {
                    answer += first * second;
                    buf.replace_range(mul_beg..mul_end + 1, "");
    while let Some(mul_beg) = buf.find("mul(") {
        if let Some(mul_end) = buf[mul_beg..].find(")").map(|i| i + mul_beg) {
            let mul_input = &buf.clone()[mul_beg + 4..mul_end];
            let mut mul_inputs = mul_input.split(",");

            let mut err = false;
            let first: i32 = match mul_inputs.next().unwrap_or_default().parse() {
                Ok(f) => f,
                Err(_) => {
                    err = true;
                    0
                }
            };
            let second: i32 = match mul_inputs.next().unwrap_or_default().parse() {
                Ok(f) => f,
                Err(_) => {
                    err = true;
                    0
                }
            };

            if err {
                buf.replace_range(mul_beg..mul_beg + 4, "");
            } else {
                answer += first * second;
                buf.replace_range(mul_beg..mul_end + 1, "");
            }
        } else {
            break;
        }
    }


M src/day4/mod.rs => src/day4/mod.rs +2 -2
@@ 33,8 33,8 @@ fn part_one(input: &Path) -> anyhow::Result<i32> {

    for y in 0..input[0].len() {
        let mut col = vec![];
        for x in 0..input.len() {
            col.push(input[x][y]);
        for c in &input {
            col.push(c[y]);
        }
        answer += String::from_iter(col)
            .as_bytes()

M src/day6/mod.rs => src/day6/mod.rs +11 -23
@@ 94,23 94,15 @@ fn part_one(input: &Path) -> anyhow::Result<i32> {
    }
    let mut guard = guard.unwrap();

    loop {
        //print_map(&map);
        if let Some(in_front) = get_in_front(&guard, &mut map) {
            if in_front.obstacle {
                guard.turn();
            } else {
                in_front.visited = true;
                guard.move_forward();
            }
    while let Some(in_front) = get_in_front(&guard, &mut map) {
        if in_front.obstacle {
            guard.turn();
        } else {
            break;
            in_front.visited = true;
            guard.move_forward();
        }
        //std::thread::sleep(std::time::Duration::from_millis(50));
    }

    //print_map(&map);

    Ok(map.iter().flatten().filter(|p| p.visited).count() as i32)
}



@@ 143,7 135,7 @@ fn get_in_front<'a>(guard: &'a Guard, map: &'a mut [Vec<Pos>]) -> Option<&'a mut
    }
}

fn print_map(map: &[Vec<Pos>]) {
fn _print_map(map: &[Vec<Pos>]) {
    for row in map {
        for pos in row {
            if pos.obstacle {


@@ 204,16 196,12 @@ fn part_two(input: &Path) -> anyhow::Result<i32> {
        let mut modified_map = map.clone();
        modified_map[pos.y][pos.x].obstacle = true;
        let start_time = std::time::Instant::now();
        loop {
            if let Some(in_front) = get_in_front(&guard, &mut modified_map) {
                if in_front.obstacle {
                    guard.turn();
                } else {
                    in_front.visited = true;
                    guard.move_forward();
                }
        while let Some(in_front) = get_in_front(&guard, &mut modified_map) {
            if in_front.obstacle {
                guard.turn();
            } else {
                break;
                in_front.visited = true;
                guard.move_forward();
            }

            if start_time.elapsed().as_millis() >= 1 {

M src/day8/part1.rs => src/day8/part1.rs +1 -1
@@ 10,7 10,7 @@ struct Map {
}

impl Map {
    fn print(&self) {
    fn _print(&self) {
        for row in &self.tiles {
            for tile in row {
                match tile.tile_type {

M src/day8/part2.rs => src/day8/part2.rs +1 -1
@@ 10,7 10,7 @@ struct Map {
}

impl Map {
    fn print(&self) {
    fn _print(&self) {
        for row in &self.tiles {
            for tile in row {
                match tile.tile_type {

M src/main.rs => src/main.rs +0 -4
@@ 1,7 1,3 @@
#![allow(clippy::comparison_chain)]
#![allow(clippy::while_let_loop)]
#![allow(clippy::needless_range_loop)]
#![allow(dead_code)]
use std::path::PathBuf;

use clap::{Parser, Subcommand};