mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solution to day 9, in lex.
This commit is contained in:
1
2017/day-09/.gitignore
vendored
Normal file
1
2017/day-09/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
solution
|
||||
3
2017/day-09/Makefile
Normal file
3
2017/day-09/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
CFLAGS=-Wall -Wextra
|
||||
|
||||
all: solution
|
||||
1
2017/day-09/input.txt
Normal file
1
2017/day-09/input.txt
Normal file
File diff suppressed because one or more lines are too long
30
2017/day-09/solution.l
Normal file
30
2017/day-09/solution.l
Normal file
@@ -0,0 +1,30 @@
|
||||
%{
|
||||
#include <stdio.h>
|
||||
|
||||
int nest = 0;
|
||||
int score = 0;
|
||||
int garbage = 0;
|
||||
%}
|
||||
%x GARBAGE
|
||||
%%
|
||||
\{ ++nest;
|
||||
\} score += nest--;
|
||||
, ;
|
||||
\< BEGIN GARBAGE;
|
||||
|
||||
<GARBAGE>!. ;
|
||||
<GARBAGE>\> BEGIN 0;
|
||||
<GARBAGE>. ++garbage;
|
||||
|
||||
%%
|
||||
|
||||
int yywrap()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
yylex();
|
||||
printf("Groups: %d\nGarbage: %d\n", score, garbage);
|
||||
}
|
||||
Reference in New Issue
Block a user