···
3
-
integer ::io, ios, a, b, state, res, cmd_state, digit_state
4
+
integer ::io, ios, a, b, state, res
5
-
character(len=10) :: buffer ! buffer to store the number
6
+
character(len=10) :: buffer
7
+
character(len=4) :: mul_cmd = 'mul('
open(newunit=io, file='./day_03_input.txt', status='old', action='read', access='stream')
8
-
state = 0 ! 0 = find command, 1 = find number, 3 = calculate
9
-
digit_state = 0 ! 0 = find a, 1 = find b
10
-
cmd_state = 0 ! 0 = find m, 1 = find u, 2 = find l 3 = find (
11
+
state = 0 ! 0 = find command, 1 = find number, 2 = calculate
17
-
select case(cmd_state)
19
+
buffer = trim(buffer) // c
20
+
if(buffer == mul_cmd) then
23
+
else if(trim(buffer) /= mul_cmd(1:len(trim(buffer)))) then
buffer = trim(buffer) // c
49
-
if (digit_state == 0 .and. len(trim(buffer)) > 0) then
32
+
if (find_a .and. len(trim(buffer)) > 0) then
60
-
if(digit_state == 1 .and. len(trim(buffer)) > 0) then
42
+
if(.not. find_a .and. len(trim(buffer)) > 0) then
63
-
state = 3 ! reset state