diff options
| -rw-r--r-- | 2024/day_04_part_2.f90 | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/2024/day_04_part_2.f90 b/2024/day_04_part_2.f90 new file mode 100644 index 0000000..ed363ac --- /dev/null +++ b/2024/day_04_part_2.f90 @@ -0,0 +1,39 @@ +program day_04 + implicit none + character(len=140) :: lines(140) + character(len=1) :: c + integer :: io, row, col, score, z + logical :: left_m, right_m + + left_m = .false. + right_m = .false. + score = 0 + open(newunit=io, file='./day_04_input.txt', status='old', action='read') + read(io, '(a)') lines + do row = 2, size(lines) - 1 + do col = 2, len(lines(row)) - 1 + if (lines(row)(col:col) == 'A') then + c = lines(row-1)(col-1:col-1) + if (c == 'S' .or. c == 'M') then + left_m = c == 'M' + c = lines(row-1)(col+1:col+1) + if (c == 'S' .or. c == 'M') then + right_m = c == 'M' + c = lines(row+1)(col-1:col-1) + if (right_m .and. c == 'S' .or. (.not. right_m .and. c == 'M')) then + c = lines(row+1)(col+1:col+1) + if (left_m .and. c == 'S' .or. (.not. left_m .and. c =='M')) then + score = score + 1 + end if + end if + end if + end if + end if + left_m = .false. + right_m = .false. + c = '' + end do + end do + print*, score + +end program day_04 |
