aboutsummaryrefslogtreecommitdiff
path: root/2024/day_02.f90
diff options
context:
space:
mode:
authorTrey Bastian <2991824+TreyBastian@users.noreply.github.com>2024-12-02 19:12:25 +0000
committerTrey Bastian <2991824+TreyBastian@users.noreply.github.com>2024-12-02 19:12:25 +0000
commit4a18141f582733953fff0fe7a6ee116b6094c14d (patch)
tree2ae99c428055df84b0996eab46314ed23de92ab0 /2024/day_02.f90
parent8121f151f19f407363b20b9de673a908069d63cd (diff)
formatting and part 2 done
Diffstat (limited to '2024/day_02.f90')
-rw-r--r--2024/day_02.f9098
1 files changed, 49 insertions, 49 deletions
diff --git a/2024/day_02.f90 b/2024/day_02.f90
index f60a9bb..574e948 100644
--- a/2024/day_02.f90
+++ b/2024/day_02.f90
@@ -1,54 +1,54 @@
program day_02
- implicit none
- logical :: is_decrement, fail
- integer :: io, i,x, spaces, res
- integer, dimension(:), allocatable :: list
- character(len=100) :: line
+ implicit none
+ logical :: is_decrement, fail
+ integer :: io, i,x, spaces, res
+ integer, dimension(:), allocatable :: list
+ character(len=100) :: line
- open(newunit=io, file='./day_02_input.txt', status='old', action='read')
+ open(newunit=io, file='./day_02_input.txt', status='old', action='read')
- res = 0
- do i = 1, 1000
- read(io, '(a)') line ! reading the line
- spaces = 1 ! reset space count
- do x = 1, len(trim(line))
- ! counting spaces to see how big of an array we need to allocate
- if(iachar(line(x:x))== 32 ) then
- spaces = spaces+1
- end if
- end do
+ res = 0
+ do i = 1, 1000
+ read(io, '(a)') line ! reading the line
+ spaces = 1 ! reset space count
+ do x = 1, len(trim(line))
+ ! counting spaces to see how big of an array we need to allocate
+ if(iachar(line(x:x))== 32 ) then
+ spaces = spaces+1
+ end if
+ end do
- allocate(list(spaces))
- read(line, *) list !reading the ints into an array
- fail = .false.
-
- do x = 1, size(list) -1
- if (list(x) == list(x+1)) then
- fail = .true.
- exit
- end if
- if(x == 1 .and. list(x) > list(x+1)) then
- is_decrement = .true.
- else if (x==1 .and. list(x) < list(x+1)) then
- is_decrement = .false.
- end if
-
- if(is_decrement) then
- if (list(x) < list(x+1) .or. abs(list(x) - list(x+1)) > 3) then
- fail = .true.
- exit
- end if
- else
- if (list(x) > list(x+1) .or. abs(list(x) - list(x+1)) > 3) then
- fail = .true.
- exit
- end if
- end if
- end do
- if (fail .eqv. .false.) then
- res = res + 1
- endif
- deallocate(list)
- end do
- print*, res
+ allocate(list(spaces))
+ read(line, *) list !reading the ints into an array
+ fail = .false.
+
+ do x = 1, size(list) -1
+ if (list(x) == list(x+1)) then
+ fail = .true.
+ exit
+ end if
+ if(x == 1 .and. list(x) > list(x+1)) then
+ is_decrement = .true.
+ else if (x==1 .and. list(x) < list(x+1)) then
+ is_decrement = .false.
+ end if
+
+ if(is_decrement) then
+ if (list(x) < list(x+1) .or. abs(list(x) - list(x+1)) > 3) then
+ fail = .true.
+ exit
+ end if
+ else
+ if (list(x) > list(x+1) .or. abs(list(x) - list(x+1)) > 3) then
+ fail = .true.
+ exit
+ end if
+ end if
+ end do
+ if (fail .eqv. .false.) then
+ res = res + 1
+ endif
+ deallocate(list)
+ end do
+ print*, res
end program day_02