diff options
| author | Trey Bastian <2991824+TreyBastian@users.noreply.github.com> | 2024-12-06 08:53:47 +0000 |
|---|---|---|
| committer | Trey Bastian <2991824+TreyBastian@users.noreply.github.com> | 2024-12-06 08:53:47 +0000 |
| commit | a0a6eca1ee2041d1264ca37e0e236208c8cb3aa2 (patch) | |
| tree | 7761768919db19bf8b5b1ca31557e6c89cbad807 /2024 | |
| parent | fe76f7204ae665dd2bea75fe7026d38beda01891 (diff) | |
day 6 part 1
Diffstat (limited to '2024')
| -rw-r--r-- | 2024/day_06.f90 | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/2024/day_06.f90 b/2024/day_06.f90 new file mode 100644 index 0000000..46ba2cf --- /dev/null +++ b/2024/day_06.f90 @@ -0,0 +1,64 @@ +program day_06 + implicit none + character(len=130) :: line, lines(130) + integer:: io, x,y, xd,yd, i, ct + + open(newunit=io, file='./day_06_input.txt', status='old', action='read') + read(io, '(a)') lines + + ct = 0 + ! find starting position + do i = 1, size(lines) + if (index(lines(i), '^') > 0) then + y = i + x = index(lines(i), '^') + xd = 0 + yd = -1 + exit + end if + end do + + ! move until we leave the bounds when we hit a valid spot mark it with an X and increase count + do + ! are we going out of bounds? + if (x+xd < 1 .or. x+xd > len(lines(y)) .or. y+yd < 1 .or. y+yd > size(lines)) then + ct = ct + 1 + lines(y)(x:x) = 'X' + exit + end if + + ! try to move + select case(lines(y+yd)(x+xd:x+xd)) + case('.') + ! valid move + ct = ct + 1 + x = x + xd + y = y + yd + lines(y)(x:x) = 'X' + case('X') + ! valid move but we've been here before + x = x + xd + y = y + yd + case('#') + ! we are blocked lets rotate 90 degrees + if(xd == 0 .and. yd == -1) then + xd = 1 + yd = 0 + else if (xd == 1 .and. yd == 0) then + xd = 0 + yd = 1 + else if (xd == 0 .and. yd == 1) then + xd = -1 + yd = 0 + else if (xd == -1 .and. yd == 0) then + xd = 0 + yd = -1 + end if + case default + exit + end select + end do + print*, lines + print*, "distinct: ", ct +end program day_06 + |
