aoc_omni/prolog/2015/1/problem.pl

14 lines
468 B
Prolog

main :-
open('../data/2015/1/input.txt',read,InStream),
get_char(InStream,NextChar),
navigateStairs(NextChar, InStream, 0).
navigateStairs(end_of_file, _, Floor) :-
Floor.
navigateStairs(40, InStream, Floor) :- % opening paren
get_char(InStream,NextChar),
navigateStairs(NextChar, InStream, Floor + 1).
navigateStairs(41, InStream, Floor) :- % closing paren
get_char(InStream,NextChar),
navigateStairs(NextChar, InStream, Floor - 1).