-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanternfish.f95
More file actions
44 lines (34 loc) · 1.15 KB
/
lanternfish.f95
File metadata and controls
44 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
program day04
implicit none
! Variables related to file I/O
integer :: io
! Problem related variables
integer, dimension(300) :: start_fish
integer, parameter :: long_int = selected_int_kind(12)
integer(kind=long_int), dimension(10) :: fish
integer(kind=long_int) :: spawned_fish
integer :: i
integer :: day
open(newunit=io, file="input.txt", status="old", action="read")
read(io, *) start_fish
close(io)
! Initializing the fish status counts
fish = [(count(start_fish == i), i=1, 10)]
do day=1, 256
! Saving the number of spawning fish
spawned_fish = fish(10)
! Index 10 is reserved for spawning fish
! Moving the 1 day left fish to be spawning next day
fish(10) = fish(1)
! Moving the other fish one day up
fish(1:7) = fish(2:8)
! Adding the spawned fish
fish(8) = spawned_fish
! And resetting the counter for the spawning fish
fish(6) = fish(6) + spawned_fish
if (day == 80) then
write (*,*) "Part 1", sum(fish)
end if
end do
write (*,*) "Part 2", sum(fish)
end program day04