Advent of code day 1

The accompanying challenge doggie

For the first time, I started the Advent of Code challenge. I’ll be working with Swift using the AoC project template from Apple folks in GitHub, announced in the Swift discussion forums.

Got the two stars from the first day of the challenge. ? and rewarded myself with the traditional Friday pizza with red wine ??

Part two of day one required some interpretation. I finally got the idea and finished with success.

Don’t want to spoil the challenge but I did the part two in two different ways:

  • Going through the input string using String.Index, character by character, picking up words of numbers (“one” etc) converting them to digits (“1”) to a result string. This should be O(n) where n is the number of chars in the input data string.
  • Replacing words using Swift String replaceOccurrences using two different Dictionaries. This has two consecutive for loops iterating two dictionaries replacing text in input string using keys in dictionaries (eg “oneight”) with values (“18”) in dictionaries. This should be O(n*m) where m is the number of entries in the two dictionaries (ca 15 +/- some), n being the number of characters in the input string.

Surprisingly, the first option took 12 secs as using the higher APIs took only 0.007 secs. Maybe I did the first wrong somehow or Swift String index operations are really slow here because of Unicode perfectness. I’ve understood that the collections APIs used with strings are not so picky about Unicode correctness.

Otherwise I used conditional removal of characters that are letters from the string, map algorithms to map the strings containing numbers to integers and reduce algorithm to calculate the sum.

Challenges like this are a good way to brush up my skills. And learn more about Swift. I added myself to the Swift leaderboard to see how other Swift programmers do.

Tomorrow is the day two. Should have time for that in the morning since I wake up early nowadays, both because of myself and the dog. He is already 14+ years and having health issues unfortunately. Meaning early wake-ups every now and then.

The end part of the AoC maybe a real challenge because of all the Christmas hassle in the house. And the busy end of the semester at the university. Interesting to see how far I get and with how many gaps.

New Swift tools

I’ve been working on my sorting methods demonstration app recently when I’ve had time for it. Most of my time currently is spend with evaluating student exercise projects submitted at the end of June for the Software Architectures course.

So, not much new functionality in the sorting app now. I am now mostly trying to make sure code so far is good and documented. Since my plan is to use it as an example and demonstration in the new course I am teaching in Fall, Data structures and Algorithms, I want the demo well documented and of good quality.

To make this happen, I’ve installed several Swift related tools and tried them out.

I am using Swift lint to make sure code is clean and following the Swift coding conventions. Though I had to disable some rules that are too tight for this demo app, using the .swiftlint.yml configuration file.

disabled_rules:
 - multiple_closures_with_trailing_closure
 - line_length
 - todo

For generating html documentation from the comments in the code, I’ve experimented with Jazzy and Swift-doc. Currently Jazzy seems to be in a better shape for my needs, since Swift-doc currently documents only public properties of the project.

Apparently Swift-doc has been used mainly for documenting APIs and libraries and their public APIs. There is a pull request in the GitHub repository, not yet accepted, enabling specifying the level of protection (open, public, fileprivate, private) to document. I tried out the fork which enables protection level configuration, results of which can be seen here. In addition to the protection level issues, there are issues with links. If you try to navigate using the class graphs on the page, the links are not correctly generated by the tool.

The Jazzy generated documentation does not have these issues, and I like the visual apprearance of the Apple themed documentation page (screenshot below).

Well, back to evaluating the SWA exercise work projects, after finishing the study program Zoom meeting I am currently listening to ?

Jazzy generated html documentation of the sorting demo app.