From 307db3fd03f53ddc8e13c57586d3fbe393696e60 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Wed, 4 Dec 2024 12:52:13 +0100 Subject: kürzer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2024/src/day04.cpp | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to '2024') diff --git a/2024/src/day04.cpp b/2024/src/day04.cpp index f586afb..b82e4d6 100644 --- a/2024/src/day04.cpp +++ b/2024/src/day04.cpp @@ -57,32 +57,14 @@ part2(map, char> data, size_t size) long count = 0; for ( size_t y = 0; y != size; ++y ) { for ( size_t x = 0; x != size; ++x ) { - if ( data[{ x, y }] == 'A' && - data[{ x - 1, y - 1 }] == 'M' && - data[{ x - 1, y + 1 }] == 'M' && - data[{ x + 1, y - 1 }] == 'S' && - data[{ x + 1, y + 1 }] == 'S' ) { - ++count; - } - if ( data[{ x, y }] == 'A' && - data[{ x - 1, y - 1 }] == 'S' && - data[{ x - 1, y + 1 }] == 'M' && - data[{ x + 1, y - 1 }] == 'S' && - data[{ x + 1, y + 1 }] == 'M' ) { - ++count; - } - if ( data[{ x, y }] == 'A' && - data[{ x - 1, y - 1 }] == 'S' && - data[{ x - 1, y + 1 }] == 'S' && - data[{ x + 1, y - 1 }] == 'M' && - data[{ x + 1, y + 1 }] == 'M' ) { - ++count; - } - if ( data[{ x, y }] == 'A' && - data[{ x - 1, y - 1 }] == 'M' && - data[{ x - 1, y + 1 }] == 'S' && - data[{ x + 1, y - 1 }] == 'M' && - data[{ x + 1, y + 1 }] == 'S' ) { + string str; + str += data[{ x, y }]; + str += data[{ x - 1, y - 1 }]; + str += data[{ x - 1, y + 1 }]; + str += data[{ x + 1, y - 1 }]; + str += data[{ x + 1, y + 1 }]; + + if ( str == "AMMSS" || str == "ASMSM" || str == "ASSMM" || str == "AMSMS" ) { ++count; } } -- cgit v1.3