From 8e1ff9400154dd298a7dced2ab42602f064fff77 Mon Sep 17 00:00:00 2001 From: endernon Date: Wed, 4 Dec 2024 23:57:21 +0000 Subject: [PATCH] swap directories of part 1 part 2 because iw orked on part1 by accident --- 2024/day4/part1/src/main.rs | 94 ++++++++++++++------ 2024/day4/{part1 => part2}/output.txt | 0 2024/day4/{part1 => part2}/outputcatzou.txt | 0 2024/day4/{part1 => part2}/outputexample.txt | 0 2024/day4/part2/src/main.rs | 94 ++++++-------------- 5 files changed, 94 insertions(+), 94 deletions(-) rename 2024/day4/{part1 => part2}/output.txt (100%) rename 2024/day4/{part1 => part2}/outputcatzou.txt (100%) rename 2024/day4/{part1 => part2}/outputexample.txt (100%) diff --git a/2024/day4/part1/src/main.rs b/2024/day4/part1/src/main.rs index 56fa4b0..5d5c4a5 100644 --- a/2024/day4/part1/src/main.rs +++ b/2024/day4/part1/src/main.rs @@ -33,62 +33,104 @@ fn main() { let leny = frfrvec.clone().len(); for y in 1..leny { - let widthup = y >= 2; - let widthdown = (leny - y) >= 2; + let widthup = y >= 4; + let widthdown = (leny - y) >= 4; for x in 1..lenx+1 { // check if enough space left and right - let widthleft = x >= 2; + let widthleft = x >= 4; - let widthright = (lenx - x) >= 1; + let widthright = (lenx - x) >= 3; // search algorithm starts here // check if the char is X - if frfrvec[y][x] == 'A' { + if frfrvec[y][x] == 'X' { println!("x is {x}"); println!("y is {y}"); println!("width up: {}", widthup); println!("width down: {}", widthdown); println!("width left: {}", widthleft); - if widthup && widthleft && widthdown && widthright { - // check if start from top - if frfrvec[y - 1][x - 1] == 'M' // up left - && frfrvec[y - 1][x + 1] == 'M' // up right - && frfrvec[y + 1][x - 1] == 'S' // down left - && frfrvec[y + 1][x + 1] == 'S' // down right + // check if going upwards + if widthup { + if frfrvec[y - 1][x] == 'M' + && frfrvec[y - 2][x] == 'A' + && frfrvec[y - 3][x] == 'S' { pointcounter += 1; println!("successful up"); } - // check if start from left - if frfrvec[y - 1][x - 1] == 'M' // up left - && frfrvec[y - 1][x + 1] == 'S' // up right - && frfrvec[y + 1][x - 1] == 'M' // down left - && frfrvec[y + 1][x + 1] == 'S' // down right + } + // check if going diag up left + if widthup && widthleft { + if frfrvec[y - 1][x - 1] == 'M' + && frfrvec[y - 2][x - 2] == 'A' + && frfrvec[y - 3][x - 3] == 'S' + { + pointcounter += 1; + println!("successful up left"); + } + } + // check if going left + if widthleft { + if frfrvec[y][x - 1] == 'M' + && frfrvec[y][x - 2] == 'A' + && frfrvec[y][x - 3] == 'S' { pointcounter += 1; println!("successful left"); } - // check if start from bottom - if frfrvec[y - 1][x - 1] == 'S' // up left - && frfrvec[y - 1][x + 1] == 'S' // up right - && frfrvec[y + 1][x - 1] == 'M' // down left - && frfrvec[y + 1][x + 1] == 'M' // down right + } + // check if going diag down left + if widthdown && widthleft { + if frfrvec[y + 1][x - 1] == 'M' + && frfrvec[y + 2][x - 2] == 'A' + && frfrvec[y + 3][x - 3] == 'S' + { + pointcounter += 1; + println!("successful down left"); + } + } + // check if going down + if widthdown { + if frfrvec[y + 1][x] == 'M' + && frfrvec[y + 2][x] == 'A' + && frfrvec[y + 3][x] == 'S' { pointcounter += 1; println!("successful down"); } - // check if start from right - if frfrvec[y - 1][x - 1] == 'S' // up left - && frfrvec[y - 1][x + 1] == 'M' // up right - && frfrvec[y + 1][x - 1] == 'S' // down left - && frfrvec[y + 1][x + 1] == 'M' // down right + } + // check if going diag down right + if widthdown && widthright { + if frfrvec[y + 1][x + 1] == 'M' + && frfrvec[y + 2][x + 2] == 'A' + && frfrvec[y + 3][x + 3] == 'S' + { + pointcounter += 1; + println!("successful down right"); + } + } + // check if going right + if widthright { + if frfrvec[y][x + 1] == 'M' + && frfrvec[y][x + 2] == 'A' + && frfrvec[y][x + 3] == 'S' { pointcounter += 1; println!("successful right"); } } + // check if going diag right up + if widthright && widthup { + if frfrvec[y - 1][x + 1] == 'M' + && frfrvec[y - 2][x + 2] == 'A' + && frfrvec[y - 3][x + 3] == 'S' + { + pointcounter += 1; + println!("successful up right"); + } + } } println!("\n") } diff --git a/2024/day4/part1/output.txt b/2024/day4/part2/output.txt similarity index 100% rename from 2024/day4/part1/output.txt rename to 2024/day4/part2/output.txt diff --git a/2024/day4/part1/outputcatzou.txt b/2024/day4/part2/outputcatzou.txt similarity index 100% rename from 2024/day4/part1/outputcatzou.txt rename to 2024/day4/part2/outputcatzou.txt diff --git a/2024/day4/part1/outputexample.txt b/2024/day4/part2/outputexample.txt similarity index 100% rename from 2024/day4/part1/outputexample.txt rename to 2024/day4/part2/outputexample.txt diff --git a/2024/day4/part2/src/main.rs b/2024/day4/part2/src/main.rs index 5d5c4a5..56fa4b0 100644 --- a/2024/day4/part2/src/main.rs +++ b/2024/day4/part2/src/main.rs @@ -33,104 +33,62 @@ fn main() { let leny = frfrvec.clone().len(); for y in 1..leny { - let widthup = y >= 4; - let widthdown = (leny - y) >= 4; + let widthup = y >= 2; + let widthdown = (leny - y) >= 2; for x in 1..lenx+1 { // check if enough space left and right - let widthleft = x >= 4; + let widthleft = x >= 2; - let widthright = (lenx - x) >= 3; + let widthright = (lenx - x) >= 1; // search algorithm starts here // check if the char is X - if frfrvec[y][x] == 'X' { + if frfrvec[y][x] == 'A' { println!("x is {x}"); println!("y is {y}"); println!("width up: {}", widthup); println!("width down: {}", widthdown); println!("width left: {}", widthleft); - // check if going upwards - if widthup { - if frfrvec[y - 1][x] == 'M' - && frfrvec[y - 2][x] == 'A' - && frfrvec[y - 3][x] == 'S' + if widthup && widthleft && widthdown && widthright { + // check if start from top + if frfrvec[y - 1][x - 1] == 'M' // up left + && frfrvec[y - 1][x + 1] == 'M' // up right + && frfrvec[y + 1][x - 1] == 'S' // down left + && frfrvec[y + 1][x + 1] == 'S' // down right { pointcounter += 1; println!("successful up"); } - } - // check if going diag up left - if widthup && widthleft { - if frfrvec[y - 1][x - 1] == 'M' - && frfrvec[y - 2][x - 2] == 'A' - && frfrvec[y - 3][x - 3] == 'S' - { - pointcounter += 1; - println!("successful up left"); - } - } - // check if going left - if widthleft { - if frfrvec[y][x - 1] == 'M' - && frfrvec[y][x - 2] == 'A' - && frfrvec[y][x - 3] == 'S' + // check if start from left + if frfrvec[y - 1][x - 1] == 'M' // up left + && frfrvec[y - 1][x + 1] == 'S' // up right + && frfrvec[y + 1][x - 1] == 'M' // down left + && frfrvec[y + 1][x + 1] == 'S' // down right { pointcounter += 1; println!("successful left"); } - } - // check if going diag down left - if widthdown && widthleft { - if frfrvec[y + 1][x - 1] == 'M' - && frfrvec[y + 2][x - 2] == 'A' - && frfrvec[y + 3][x - 3] == 'S' - { - pointcounter += 1; - println!("successful down left"); - } - } - // check if going down - if widthdown { - if frfrvec[y + 1][x] == 'M' - && frfrvec[y + 2][x] == 'A' - && frfrvec[y + 3][x] == 'S' + // check if start from bottom + if frfrvec[y - 1][x - 1] == 'S' // up left + && frfrvec[y - 1][x + 1] == 'S' // up right + && frfrvec[y + 1][x - 1] == 'M' // down left + && frfrvec[y + 1][x + 1] == 'M' // down right { pointcounter += 1; println!("successful down"); } - } - // check if going diag down right - if widthdown && widthright { - if frfrvec[y + 1][x + 1] == 'M' - && frfrvec[y + 2][x + 2] == 'A' - && frfrvec[y + 3][x + 3] == 'S' - { - pointcounter += 1; - println!("successful down right"); - } - } - // check if going right - if widthright { - if frfrvec[y][x + 1] == 'M' - && frfrvec[y][x + 2] == 'A' - && frfrvec[y][x + 3] == 'S' + // check if start from right + if frfrvec[y - 1][x - 1] == 'S' // up left + && frfrvec[y - 1][x + 1] == 'M' // up right + && frfrvec[y + 1][x - 1] == 'S' // down left + && frfrvec[y + 1][x + 1] == 'M' // down right { pointcounter += 1; println!("successful right"); } } - // check if going diag right up - if widthright && widthup { - if frfrvec[y - 1][x + 1] == 'M' - && frfrvec[y - 2][x + 2] == 'A' - && frfrvec[y - 3][x + 3] == 'S' - { - pointcounter += 1; - println!("successful up right"); - } - } } println!("\n") }