···
-
integer ::io, ios, a, b, state, res, cmd_state, digit_state
-
character(len=10) :: buffer ! buffer to store the number
open(newunit=io, file='./day_03_input.txt', status='old', action='read', access='stream')
-
state = 0 ! 0 = find command, 1 = find number, 3 = calculate
-
digit_state = 0 ! 0 = find a, 1 = find b
-
cmd_state = 0 ! 0 = find m, 1 = find u, 2 = find l 3 = find (
buffer = trim(buffer) // c
-
if (digit_state == 0 .and. len(trim(buffer)) > 0) then
-
if(digit_state == 1 .and. len(trim(buffer)) > 0) then
-
state = 3 ! reset state
···
+
integer ::io, ios, a, b, state, res
+
character(len=10) :: buffer
+
character(len=4) :: mul_cmd = 'mul('
open(newunit=io, file='./day_03_input.txt', status='old', action='read', access='stream')
+
state = 0 ! 0 = find command, 1 = find number, 2 = calculate
+
buffer = trim(buffer) // c
+
if(buffer == mul_cmd) then
+
else if(trim(buffer) /= mul_cmd(1:len(trim(buffer)))) then
buffer = trim(buffer) // c
+
if (find_a .and. len(trim(buffer)) > 0) then
+
if(.not. find_a .and. len(trim(buffer)) > 0) then