diff --git a/README.md b/README.md index 9033054..e52f45a 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,4 @@ _in which I attempt to use a different language every day_ 9. Picat 10. Hy 11. GNU Octave -12. ?? \ No newline at end of file +12. fasmg macros \ No newline at end of file diff --git a/d12/README.md b/d12/README.md index 3556f78..d676d5e 100644 --- a/d12/README.md +++ b/d12/README.md @@ -1,11 +1,20 @@ # Day 12 -| | | -|-------------------|-------------------| -| Language | ?? | -| Input Method | ?? | -| Output Method | ?? | +| | | +|-------------------|-----------------------------------------------| +| Language | fasmg macros | +| Input Method | File | +| Output Method | File (raw 16-bit little endian binary number) | ## Running +```sh +fasmg -i'include "day12.inc"' +``` -## Notes \ No newline at end of file +## Notes +This relies on a particular property of real inputs which doesn't hold for the example, so this will not provide the correct answer for +the example input. + +The output will be left in a binary file with the same name as the input file but with the extension removed. The output file will be a +2-byte binary, which is the puzzle answer as a 16-bit little endian number. Note that the output file will be left in the same directory +as the input file, not the current working directory. \ No newline at end of file diff --git a/d12/day12.inc b/d12/day12.inc new file mode 100644 index 0000000..db575a3 --- /dev/null +++ b/d12/day12.inc @@ -0,0 +1,78 @@ +macro count_hashes: res*, line* + match ## , line + res = 2 + else match #., line + res = 1 + else match .#, line + res = 1 + else match .., line + res = 0 + else match # rest , line + local recursive_res + count_hashes recursive_res, rest + res = 1 + recursive_res + else match . rest , line + count_hashes res, rest + end match +end macro + +macro sum_areas: res*, count*, line* + match n rest, line + local tmp + sum_areas tmp, count, rest + repeat 1, i:count + res = tmp + (area#i * n) + end repeat + else + repeat 1, i:count + res = area#i * line + end repeat + end match +end macro + +ans = 0 + +macro ? line + match num:, line + current_shape = num + repeat 1, i:current_shape + area#i = 0 + end repeat + else match # rest, line + local tmp + count_hashes tmp, rest + repeat 1, i:current_shape + area#i = area#i + tmp + 1 + end repeat + else match . rest, line + local tmp + count_hashes tmp, rest + repeat 1, i:current_shape + area#i = area#i + tmp + end repeat + else match dims: rest, line + virtual at 0 + db `dims + load tmp:byte from $-5 + a = 10 * (tmp - $30) + load tmp:byte from $-4 + a = a + (tmp - $30) + load tmp:byte from $-2 + b = 10 * (tmp - $30) + load tmp:byte from $-1 + b = b + (tmp - $30) + end virtual + + local area + sum_areas area, 0, rest + if area <= (a * b) + ans = ans + 1 + end if + else + line + end match +end macro + +postpone + dw ans +end postpone \ No newline at end of file