Solution to day 9, in lex.

This commit is contained in:
2017-12-10 13:06:34 +01:00
parent 65a3f8ad81
commit 836274331c
5 changed files with 36 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ The current plan, in no particular order:
- [ ] Haskell - [ ] Haskell
- [ ] Java - [ ] Java
- [ ] Kotlin - [ ] Kotlin
- [x] Lex - [Day 09](./day-09/solution.l)
- [x] Matlab - [Day 06](./day-06) - [x] Matlab - [Day 06](./day-06)
- [ ] Node.js - [ ] Node.js
- [ ] Objective C - [ ] Objective C

1
2017/day-09/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
solution

3
2017/day-09/Makefile Normal file
View File

@@ -0,0 +1,3 @@
CFLAGS=-Wall -Wextra
all: solution

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
View 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);
}