Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
skidadpa committed Dec 1, 2023
1 parent 5b15de1 commit dde4f04
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
results.txt
.*.sw?
*.so
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AWK solutions for Advent of Code 2023
=====================================
I decided to implement the Advent of Code challenges this year in AWK. This
daily programming challenge can be found at http://www.adventofcode.com.

Here are my solutions. There is a folder for each day, each containing:

| file | description |
| ------------ | ------------------------------------------- |
| Makefile | Makefile that runs a regression by default |
| expected.txt | Expected results of regression test |
| sample.txt | sample input from the challenge description |
| input.txt | test input from the challenge description |
| one.awk | first solution |
| two.awk | second solution |
| * | additional files as needed |

Jerry Williams
gsw@wfam.info
7 changes: 7 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
cd $(dirname $0)
for d in day*
do
echo + $d
make -C $d clean
done
20 changes: 20 additions & 0 deletions day00/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: test clean update

test : expected.txt results.txt
diff -s expected.txt results.txt

PROGRAMS = one.awk two.awk
INPUTS = sample.txt input.txt

results.txt : $(PROGRAMS) $(INPUTS)
./one.awk sample.txt > $@
./one.awk input.txt >> $@
./two.awk sample.txt >> $@
./two.awk input.txt >> $@
cat $@

clean:
$(RM) results.txt

update: results.txt
cp $< expected.txt
4 changes: 4 additions & 0 deletions day00/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
2
0
2
2 changes: 2 additions & 0 deletions day00/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
2
15 changes: 15 additions & 0 deletions day00/one.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env gawk -f
BEGIN {
}
{
if (_error) {
print "DATA ERROR"
exit _exit=1
}
}
END {
if (_exit) {
exit _exit
}
print NR
}
Empty file added day00/sample.txt
Empty file.
15 changes: 15 additions & 0 deletions day00/two.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env gawk -f
BEGIN {
}
{
if (_error) {
print "DATA ERROR"
exit _exit=1
}
}
END {
if (_exit) {
exit _exit
}
print NR
}
8 changes: 8 additions & 0 deletions regress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
cd $(dirname $0)
export PREVENT_LONG_RUN=1
for d in day*
do
echo + $d
make -C $d
done

0 comments on commit dde4f04

Please sign in to comment.