diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-12-26 04:47:37 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-12-26 04:47:37 +0900 |
commit | d50da3ffbe80df244961a867b551d4e5b6e4f13b (patch) | |
tree | 9b63e5c9d83625a01ba0108bba3c8bdf21ad3ee2 /blog | |
parent | 51509e605d61b4ee52e70f5c5add46f69c5340c5 (diff) | |
download | site-d50da3ffbe80df244961a867b551d4e5b6e4f13b.tar.gz |
Draft first half of advent calendar
Diffstat (limited to 'blog')
-rw-r--r-- | blog/advent.md | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/blog/advent.md b/blog/advent.md new file mode 100644 index 0000000..96303ae --- /dev/null +++ b/blog/advent.md @@ -0,0 +1,191 @@ +<!-- + -- +++ + -- rss = "Doing Advent of Code in a new programming language each day" + -- date = Date(2022, 12, 26) + -- tags = ["fun", "exp"] + -- +++ + --> + +# Advent of Programming Languages + +Earlier this year I enrolled in a master's programme[^master] at [UNIST] +and joined the Programming Languages and Software Engineering lab (PLaSE) as +a student researcher. The stipend covers the school fees and living expenses, +and I'm given *an* academic freedom to choose what to work on and take risks. +I will review the life here in detail in another post, but (SPOILER ALERT!) +overall I'm quite content with it. + +That being said, PLaSE is new and small, we only do research +on software engineering and don't do its name justice. Because of that, +in the first year here I decided to do each day of [Advent of Code][^2021] +in a language I'd never used in competitive programming (CP) before. + +![Pitbull holding the globe, captioned: Mr. Worldwide](/assets/mr-worldwide.jpg) + +Here was my blacklist going in, chronologically: Pascal, Python, +Scheme, C, C++, Common Lisp, Lua, Raku, Go, Rust and Zig. I am only +proficient in over half of the listed languages, but dura lex, sed lex, +I'd already had my CP first time with the rest. + +## Day One + +The first day should have been the warm up so I challenged myself +with using POSIX utilities. This is a bit irony though as the majority +of my time spent outside of [*the* editor][Vim] or a web browser +is inside a ([Bourn-again][Born Again]) shell. + +The [problem][p01] was indeed simple, involving only [finding the maxima +among the sums of newline-separated numbers][s01]. I used [sed]\(1p) +to turn the input into [dc]\(1) eypressions, and [sort]\(1p) and [tail]\(1p) +for picking the largest sum. Probably the most interesting part +was that the summation was reusable to [grade an assignment] for a course +I was a teaching assistant for. + +## Day Two + +The [second problem][p02] didn't ramp up much in difficulty. +It only called for some rather [simple arithmetic][s02], +and the input format regularity convinced me to finally give [Hare] a try. + +For just a taste, Hare is boring in a good way. I was excited +for the tagged union of [error which can include and propagate +any debugging information][error], but unfortunately it wasn't needed +for programs of such complexity (nor that errors are ever handled in CP). +I'm looking forward to a chance to write more Hare in the future. + +## Day Three + +The [task for day 3][p03] was literally day $1 + 2$ in scope. +I went for another *better C* that is [Nim]. My first impression with it +wasn't positive: Nim insists on considering each source file as a model +and does not allow hyphens in identifier name, so [filenames mustn't have +any hyphen][hyphen] either. This had led me to piping the source code +to `nim c -` and executing `~/.cache/nim/stdinfile_d/stdinfile` to keep +my solution naming convention. `nim r -` wouldn't have worked either +since the convention also consists of reading the input from stdin. + +On the bright side, [uniform function call syntax][UFCS], identifier +case-(and underscore-)insensitivity and optional parentheses allowed me +to [dodge parentheses in calls and camelCasing altogether][s03]. +Although I *love* Lisp and don't have any problem with brackets, +I think their placement in ALGOL style hurts the readability +of nested calls and [camelCase is just objectively bad][camelCase], +pun[^obj] unintended. + +## Day Four + +The [forth problem][p04] wasn't any harder, only requiring +[simple logic operations and summation][s04]. To save time, +I opted for [Julia], which I was kinda sorta familiar with +in building this site (at the time this is published at least). +Like Nim, it has higher-order functions and a (reference) compiler +capable of producing fast binaries. + +## Day Five + +The [next day's task][p05] was finally a breath of fresh air +with [matrix parsing and LIFO (literal) stacks][s05]. It begged +for a regular expression parser,[^re] hence I mined a tiny bit of Ruby +for the task. Ruby had been designed to be an object-oriented Perl, +and expectedly it feels very similar to Raku. To an extend, I was also +able to avoid ALGOL-style call do quite a [Lisp impression]. + +When I was looking for a second language to learn after the peak +of my CP *career* in middle school, I was choosing between those +with garbage-collection that are most popularly used in [free software] +at the time, namely Perl, Python and Ruby. Perl was ruled out due to my fear +of [sigils] and I picked up Python as I didn't want to be a [weeaboo]. +Sometimes I wonder how my side projects would have turned out to be +had I chosen differently. + +## Day Six + +Bit set and byte queue in D + +poor docs + +no hyphen + +## Day Seven + +Janet PEG parse console log + +## Day Eight + +2D dynamic programming in Fortran +hardcoded size + +## Day Nine + +Tcl with hash table + +## Day Ten + +AWK w/o loop + +## May Day + +[Oops!… I did it again.][^2021] If you think 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. + +[^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. + +[UNIST]: https://unist.ac.kr +[Advent of Code]: https://adventofcode.com +[Vim]: https://www.vim.org +[Born Again]: https://www.youtube.com/watch?v=k5E6CExu204 + +[p01]: https://adventofcode.com/2022/day/1 +[s01]: https://git.sr.ht/~cnx/cp/commit/ff0bb53c15dd +[sed]: https://www.unix.com/man-page/posix/1p/sed +[dc]: https://linux.die.net/man/1/dc +[sort]: https://www.unix.com/man-page/posix/1p/sort +[tail]: https://www.unix.com/man-page/posix/1p/tail +[grade an assignment]: https://larkspur.one/notice/AQALVP69wAiotsVmgC + +[p02]: https://adventofcode.com/2022/day/2 +[s02]: https://git.sr.ht/~cnx/cp/commit/ada3a69b15ff +[Hare]: https://harelang.org +[error]: https://harelang.org/tutorials/introduction/#defining-new-error-types + +[p03]: https://adventofcode.com/2022/day/3 +[s03]: https://git.sr.ht/~cnx/cp/commit/eeb9a45346a8 +[Nim]: https://nim-lang.org +[hyphen]: https://forum.nim-lang.org/t/5024 +[UFCS]: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax +[camelCase]: http://www.cs.kent.edu/~jmaletic/papers/ICPC2010-CamelCaseUnderScoreClouds.pdf + +[p04]: https://adventofcode.com/2022/day/4 +[s04]: https://git.sr.ht/~cnx/cp/commit/8941f621840f +[Julia]: https://julialang.org + +[p05]: https://adventofcode.com/2022/day/5 +[s05]: https://git.sr.ht/~cnx/cp/commit/aa7616140a8b +[Lisp impression]: https://www.codesections.com/blog/raku-lisp-impression +[free software]: https://www.gnu.org/philosophy/free-sw.html +[sigils]: https://raku-advent.blog/2022/12/20/sigils +[weeaboo]: https://en.wikipedia.org/wiki/Japanophilia#21st_century + +[p06]: https://adventofcode.com/2022/day/6 +[s06]: https://git.sr.ht/~cnx/cp/commit/ + +[p07]: https://adventofcode.com/2022/day/7 +[s07]: https://git.sr.ht/~cnx/cp/commit/ + +[p08]: https://adventofcode.com/2022/day/8 +[s08]: https://git.sr.ht/~cnx/cp/commit/ + +[p09]: https://adventofcode.com/2022/day/9 +[s09]: https://git.sr.ht/~cnx/cp/commit/ + +[p10]: https://adventofcode.com/2022/day/10 +[s10]: https://git.sr.ht/~cnx/cp/commit/ + +[Oops!… I did it again.]: https://en.wikipedia.org/wiki/Oops!..._I_Did_It_Again_(album) |