Compare commits
9 commits
35c23272cb
...
8e1ff94001
Author | SHA1 | Date | |
---|---|---|---|
8e1ff94001 | |||
65c3087c24 | |||
33edb499c8 | |||
6380a9a928 | |||
20f2212595 | |||
bc361d191a | |||
630f54811c | |||
ef694d7114 | |||
ad946ce70f |
7 changed files with 219233 additions and 12 deletions
|
@ -33,23 +33,24 @@ fn main() {
|
|||
let leny = frfrvec.clone().len();
|
||||
|
||||
for y in 1..leny {
|
||||
let widthup = y - 1 > 4;
|
||||
let widthdown = (leny - y) > 4;
|
||||
let widthup = y >= 4;
|
||||
let widthdown = (leny - y) >= 4;
|
||||
|
||||
for x in 1..lenx {
|
||||
for x in 1..lenx+1 {
|
||||
// check if enough space left and right
|
||||
|
||||
let widthleft = x >= 4;
|
||||
|
||||
let widthright = (lenx - x) >= 3;
|
||||
|
||||
// search algorithm starts here
|
||||
// check if the char is X
|
||||
if frfrvec[y][x] == 'X' {
|
||||
println!("x is {x}");
|
||||
println!("y is {y}");
|
||||
println!("width up: {}", widthup);
|
||||
println!("width down: {}", widthdown);
|
||||
let widthleft = x - 1 > 4;
|
||||
println!("width left: {}", widthleft);
|
||||
let widthright = (lenx - x) > 4;
|
||||
println!("width right: {}", widthright);
|
||||
|
||||
// search algorithm starts here
|
||||
// check if the char is s
|
||||
if frfrvec[y][x] == 'X' {
|
||||
// check if going upwards
|
||||
if widthup {
|
||||
if frfrvec[y - 1][x] == 'M'
|
||||
|
@ -57,6 +58,7 @@ fn main() {
|
|||
&& frfrvec[y - 3][x] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful up");
|
||||
}
|
||||
}
|
||||
// check if going diag up left
|
||||
|
@ -66,6 +68,7 @@ fn main() {
|
|||
&& frfrvec[y - 3][x - 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful up left");
|
||||
}
|
||||
}
|
||||
// check if going left
|
||||
|
@ -75,6 +78,7 @@ fn main() {
|
|||
&& frfrvec[y][x - 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful left");
|
||||
}
|
||||
}
|
||||
// check if going diag down left
|
||||
|
@ -84,6 +88,7 @@ fn main() {
|
|||
&& frfrvec[y + 3][x - 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful down left");
|
||||
}
|
||||
}
|
||||
// check if going down
|
||||
|
@ -93,6 +98,7 @@ fn main() {
|
|||
&& frfrvec[y + 3][x] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful down");
|
||||
}
|
||||
}
|
||||
// check if going diag down right
|
||||
|
@ -102,6 +108,7 @@ fn main() {
|
|||
&& frfrvec[y + 3][x + 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful down right");
|
||||
}
|
||||
}
|
||||
// check if going right
|
||||
|
@ -111,6 +118,7 @@ fn main() {
|
|||
&& frfrvec[y][x + 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful right");
|
||||
}
|
||||
}
|
||||
// check if going diag right up
|
||||
|
@ -120,9 +128,11 @@ fn main() {
|
|||
&& frfrvec[y - 3][x + 3] == 'S'
|
||||
{
|
||||
pointcounter += 1;
|
||||
println!("successful up right");
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
2024/day4/part2/Cargo.lock
generated
Normal file
7
2024/day4/part2/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "part1"
|
||||
version = "0.1.0"
|
6
2024/day4/part2/Cargo.toml
Normal file
6
2024/day4/part2/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "part1"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
60085
2024/day4/part2/output.txt
Normal file
60085
2024/day4/part2/output.txt
Normal file
File diff suppressed because one or more lines are too long
158194
2024/day4/part2/outputcatzou.txt
Normal file
158194
2024/day4/part2/outputcatzou.txt
Normal file
File diff suppressed because one or more lines are too long
821
2024/day4/part2/outputexample.txt
Normal file
821
2024/day4/part2/outputexample.txt
Normal file
|
@ -0,0 +1,821 @@
|
|||
ye the lines are ["MMMSXXMASM", "MSAMXMSMSA", "AMXSXMAAMM", "MSAMASMSMX", "XMASAMXAMM", "XXAMMXXAMA", "SMSMSASXSS", "SAXAMASAAA", "MAMMMXMMMM", "MXMXAXMASX"]
|
||||
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], ['0', 'M', 'M', 'M', 'S', 'X', 'X', 'M', 'A', 'S', 'M'], ['0', 'M', 'S', 'A', 'M', 'X', 'M', 'S', 'M', 'S', 'A'], ['0', 'A', 'M', 'X', 'S', 'X', 'M', 'A', 'A', 'M', 'M'], ['0', 'M', 'S', 'A', 'M', 'A', 'S', 'M', 'S', 'M', 'X'], ['0', 'X', 'M', 'A', 'S', 'A', 'M', 'X', 'A', 'M', 'M'], ['0', 'X', 'X', 'A', 'M', 'M', 'X', 'X', 'A', 'M', 'A'], ['0', 'S', 'M', 'S', 'M', 'S', 'A', 'S', 'X', 'S', 'S'], ['0', 'S', 'A', 'X', 'A', 'M', 'A', 'S', 'A', 'A', 'A'], ['0', 'M', 'A', 'M', 'M', 'M', 'X', 'M', 'M', 'M', 'M'], ['0', 'M', 'X', 'M', 'X', 'A', 'X', 'M', 'A', 'S', 'X']]
|
||||
x is 1
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
successful down right
|
||||
|
||||
|
||||
x is 6
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
successful right
|
||||
|
||||
|
||||
x is 7
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 1
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
successful left
|
||||
|
||||
|
||||
x is 6
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 2
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 3
|
||||
width up: false
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 4
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
successful down left
|
||||
successful down
|
||||
|
||||
|
||||
x is 1
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
successful right
|
||||
|
||||
|
||||
x is 2
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
successful up
|
||||
successful left
|
||||
|
||||
|
||||
x is 8
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 5
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
successful up right
|
||||
|
||||
|
||||
x is 2
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
successful up left
|
||||
|
||||
|
||||
x is 8
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 6
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 7
|
||||
width up: true
|
||||
width down: true
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 8
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 3
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 5
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 7
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 9
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 1
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 2
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
successful up right
|
||||
|
||||
|
||||
x is 3
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: false
|
||||
width right: true
|
||||
|
||||
|
||||
x is 4
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
successful up left
|
||||
successful up right
|
||||
|
||||
|
||||
x is 5
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
|
||||
|
||||
x is 6
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: true
|
||||
successful up left
|
||||
successful right
|
||||
successful up right
|
||||
|
||||
|
||||
x is 7
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 8
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 9
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
|
||||
|
||||
x is 10
|
||||
y is 10
|
||||
width up: true
|
||||
width down: false
|
||||
width left: true
|
||||
width right: false
|
||||
successful up
|
||||
successful up left
|
||||
|
||||
|
||||
18
|
98
2024/day4/part2/src/main.rs
Normal file
98
2024/day4/part2/src/main.rs
Normal file
|
@ -0,0 +1,98 @@
|
|||
use std::fs::read_to_string;
|
||||
|
||||
fn main() {
|
||||
let mut pointcounter = 0;
|
||||
|
||||
let lines: Vec<String> = read_to_string("input.txt")
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(String::from)
|
||||
.collect();
|
||||
let mut frfrvec: Vec<Vec<char>> = Vec::new();
|
||||
println!("ye the lines are {:?}", lines);
|
||||
|
||||
// make y coord offset by 1
|
||||
let lenxold = lines[1].chars().count();
|
||||
let mut lenvec: Vec<char> = Vec::new();
|
||||
for i in 0..lenxold {
|
||||
lenvec.push('0');
|
||||
}
|
||||
frfrvec.push(lenvec);
|
||||
|
||||
// main section where you push stuff
|
||||
for ministr in lines.clone() {
|
||||
let mut pushvec = Vec::new();
|
||||
pushvec.push('0'); // make x coord offset by 1
|
||||
for minichar in ministr.chars() {
|
||||
pushvec.push(minichar);
|
||||
}
|
||||
frfrvec.push(pushvec);
|
||||
}
|
||||
println!("{:?}", frfrvec);
|
||||
let lenx = lines[1].chars().count();
|
||||
let leny = frfrvec.clone().len();
|
||||
|
||||
for y in 1..leny {
|
||||
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 >= 2;
|
||||
|
||||
let widthright = (lenx - x) >= 1;
|
||||
|
||||
// search algorithm starts here
|
||||
// check if the char is 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);
|
||||
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 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 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 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("\n")
|
||||
}
|
||||
}
|
||||
|
||||
println!("{pointcounter}");
|
||||
}
|
Loading…
Reference in a new issue