diff options
| author | Trey Bastian <2991824+TreyBastian@users.noreply.github.com> | 2024-12-04 12:10:56 +0000 |
|---|---|---|
| committer | Trey Bastian <2991824+TreyBastian@users.noreply.github.com> | 2024-12-04 12:10:56 +0000 |
| commit | f84bda29e5ab1145f5842703d9497cce9edf2fc4 (patch) | |
| tree | b596f0769568ed5eb8c20657cbdedd59645cead9 /2024/day_04_part_2.f90 | |
| parent | c9a13513b814b63d376bde94a35821ad5fb046df (diff) | |
day 4 part 2
Diffstat (limited to '2024/day_04_part_2.f90')
| -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 |
