about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-27 01:23:43 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-27 01:24:09 +0900
commit905e53bfd90a81f6eb27e272e3c199eec17d9629 (patch)
treea776cefaf6419b3bc669d04ca91ee2430b18ca87
parent746118270a11697fa9453b5fc1125c51655a17bf (diff)
downloadsite-905e53bfd90a81f6eb27e272e3c199eec17d9629.tar.gz
Finish 2022's advent journal
-rw-r--r--blog/advent.md97
1 files changed, 76 insertions, 21 deletions
diff --git a/blog/advent.md b/blog/advent.md
index 96303ae..a141c74 100644
--- a/blog/advent.md
+++ b/blog/advent.md
@@ -1,10 +1,8 @@
-<!--
-  -- +++
-  -- rss = "Doing Advent of Code in a new programming language each day"
-  -- date = Date(2022, 12, 26)
-  -- tags = ["fun", "exp"]
-  -- +++
-  -->
++++
+rss = "Doing Advent of Code in a new programming language each day"
+date = Date(2022, 12, 26)
+tags = ["fun", "exp"]
++++
 
 # Advent of Programming Languages
 
@@ -100,42 +98,85 @@ had I chosen differently.
 
 ## Day Six
 
-Bit set and byte queue in D
+The [sixth problem][p06] essentially asked for maintaining a finite queue
+of English letters until it is distinct.  The most efficient way to do this
+is employing bit shifting for the FIFO and a bit set for the letters.
+[I implemented that][s06] literally in the [Better C] subset of [D].
 
-poor docs
+Although the language is around my age and influenced the big names
+like modern C++, Swift and Zig,[^cmp] its documentation is pretty underwhelming
+and inconsistent.  For instance, the 128-bit integer type `cent` is documented
+as a [basic data type], however it only exists in the [core.int128] library
+with more cumbersome usage (and doesn't work with `dmd -betterC`).
 
-no hyphen
+Like with Nim, D compilers also don't allow hyphens in source filenames,
+so I had to pipe the code to `dmd -of=a.out -` (the executable name
+would be randomized otherwise).
 
 ## Day Seven
 
-Janet PEG parse console log
+On the first [Wednesday] of the month of celebration, the [problem][p07]
+was parsing `cd` and `ls`-like invocation and output to reconstruct
+a directory tree and do, uh, tree stuff.  [Janet]'s [PEG module]
+was much more [delightful][s07] for parsing than regular expression
+on steroids like Raku's [grammar].
+
+Writing imperative code in Lisp syntax felt dirty, though it's IMHO
+a quite better take than Lua, which is understandable as it was originally
+a redesign of [Fennel].
 
 ## Day Eight
 
-2D dynamic programming in Fortran
-hardcoded size
+The [eighth problem][p08] could be efficiently solved via dynamic programming
+on multidimensional arrays so I [used][s08] Fortran for array programming.
+There's not much to say other than that it werkt and, ah yea, dynamic allocation
+didn't seem worth the effort so I ended up hardcoding the sizes.
 
 ## Day Nine
 
-Tcl with hash table
+The [ninth task][p09] was about sparse matrix transformation.
+Naturally I used hash table in Tcl for this purpose
+and the [solution][s09] was straightforward enough.
+I am planning on extending a video game's level configuration
+to be programmable and the top contenders are now Lua/Fennel,
+Janet and Tcl.  No idea when I'll get to it, but I'mma keep ya posted.
 
 ## Day Ten
 
-AWK w/o loop
+On [day 10][p10], I needed to build a less-than-basic[^egg] calculator.
+I thought using AWK would spice things up a bit, but it actually simplified
+the [solution][s10].  Instead of having to read and parse each operation,
+the script is executed for each input line, even allowing interleaving
+matching.  Therefore, the behavior specification could be followed closely
+without any significant effort on adapting the logic for the language.
+
+I used to think of AWK as just a more verbose sed(1).
+I was wrong and am glad that I was.  I guess AWK can come in
+pretty handy for similar real-world usages, such as log processing
+or moderately complex transformation of textual data.
 
 ## May Day
 
-[Oops!… I did it again.][^2021]  If you think because I published this
+[Oops!… I did it again.][^2021]  If you thought because I published this
 right after Christmas it must be a complete advent journal, I have played you
 for absolute fools!  The later problems were increasingly parsing heavy,
 and while I still had languages I wanted to try, none left was designed
 for text processing.  I was also busy in meatspace at the time thus I couldn't
 find the time to write byte-level parsers in languages I didn't know.
 
+I didn't try really hard nor got really far, but [in the end]
+maybe the [real treasure] was the experiences I had along the way.
+I suppose the [contact hypothesis] *might* be true, at least
+in this context[;] my prejudice against many languages had been
+cleared away even after surface-level interactions.  You should probably
+also give it a try, who knows, it could be much [gay]er than you'd expect!
+
 [^master]: No, I have not been given any slave.
 [^2021]: I know, last year I already quit citing how janky later problems were.
 [^obj]: camelCase was popularized by mainstream object oriented languages.
 [^re]: Not really, reading byte-by-byte would also work, just less cool.
+[^cmp]: I feel underachieved now.
+[^egg]: No eggs were harmed in the making of the solution.
 
 [UNIST]: https://unist.ac.kr
 [Advent of Code]: https://adventofcode.com
@@ -174,18 +215,32 @@ find the time to write byte-level parsers in languages I didn't know.
 [weeaboo]: https://en.wikipedia.org/wiki/Japanophilia#21st_century
 
 [p06]: https://adventofcode.com/2022/day/6
-[s06]: https://git.sr.ht/~cnx/cp/commit/
+[s06]: https://git.sr.ht/~cnx/cp/commit/f82f0b1a08f1
+[Better C]: https://dlang.org/spec/betterc.html
+[D]: https://dlang.org
+[basic data type]: https://dlang.org/spec/type.html#basic-data-types
+[core.int128]: https://dlang.org/phobos/core_int128.html
 
+[Wednesday]: https://vine.co/v/iM0HnpBebd0
 [p07]: https://adventofcode.com/2022/day/7
-[s07]: https://git.sr.ht/~cnx/cp/commit/
+[Janet]: https://janet-lang.org
+[PEG module]: https://janet-lang.org/docs/peg.html
+[s07]: https://git.sr.ht/~cnx/cp/commit/38d8920c7d7c
+[grammar]: https://docs.raku.org/language/grammars
+[Fennel]: https://fennel-lang.org
 
 [p08]: https://adventofcode.com/2022/day/8
-[s08]: https://git.sr.ht/~cnx/cp/commit/
+[s08]: https://git.sr.ht/~cnx/cp/commit/f8b0528d933f
 
 [p09]: https://adventofcode.com/2022/day/9
-[s09]: https://git.sr.ht/~cnx/cp/commit/
+[s09]: https://git.sr.ht/~cnx/cp/commit/cde44cdda55d
 
 [p10]: https://adventofcode.com/2022/day/10
-[s10]: https://git.sr.ht/~cnx/cp/commit/
+[s10]: https://git.sr.ht/~cnx/cp/commit/5e4395eab495
 
 [Oops!… I did it again.]: https://en.wikipedia.org/wiki/Oops!..._I_Did_It_Again_(album)
+[in the end]: https://www.youtube.com/watch?v=eVTXPUF4Oz4
+[real treasure]: https://www.youtube.com/watch?v=l7r-R61W1DQ
+[contact hypothesis]: https://en.wikipedia.org/wiki/Contact_hypothesis
+[;]: https://www.youtube.com/watch?v=M94ii6MVilw
+[gay]: https://en.wiktionary.org/wiki/gay#Middle_English