Wednesday, April 15, 2015

Fjölnir - Problem 19

So, now that I am back to solving problems, I figured I needed to do something fun. I used Scratch, a blocks programming language, and then I did some mildly complicated stuff in Scala. Now, I am at a fairly difficult point of trying to push this challenge forward: the problems are getting actually difficult, and the number of reasonable languages is dwindling.

So, what do I do? I use a completely unreasonable language.

Fjölnir is a language developed in Iceland in the 1980s. All of the keywords are in Icelandic, the only documentation is in Iceland, and the only implementation is for MS-DOS.

The first difficulty for this problem was finding information: the only documentation other than a brief Wikipedia article is https://notendur.hi.is//~snorri/087133-03/fjolnir.pdf. Yes, that is a 180-page pdf written in Icelandic. I got a large amount of assistance from Dagur Ammendrup's 99-bottles solution at http://www.99-bottles-of-beer.net/language-fjoelnir-259.html, and all of the rest of the syntax I learned through arduous attempts at parsing Icelandic (luckily symbols and general knowledge of the structure of programs helped a lot here).

The last issue to address came from DOS. Now, running a DOS emulator isn't too hard, there are plenty in various repos. The difficulty is that DOS and unicode don't play well together. DOS uses a very peculiar text encoding: not UTF-8, but CP437. I didn't realize this at first (I don't just assume that things can't handle UTF-8). Once I realized this, I changed atom's encoding to CP437, but I still ran into issues, because CP437 doesn't map certain characters properly, so my code is even more nonsensical in its original DOS form than in the converted form presented below.

Hopefully for future problems I will be dealing with more reasonable issues, but I will say that this foray into the Icelandic CS community of the 1980s was pretty interesting: and now that the below program (which runs very quickly!) is done, I get a chance to use F# again, so we will see how that goes.
"e19" < main
{
    main ->
        stef(;)
        staðvær y,m,d,s
        stofn
            d := 2,
            s := 0,
            fyrir( y := 1; y <= 100; y := y + 1) lykkja
                fyrir( m := 0; m < 12; m := m + 1) lykkja
                    ef (m = 3) eða (m = 5) eða (m = 8) eða (m = 10) þá
                        d := (d  + 2) % 7,
                    annarsef (m = 1) þá
                        ef (y % 4 = 0) þá
                            d := (d + 1) % 7,
                        eflok
                    annars
                        d := (d + 3) % 7,
                    eflok,
                    ef (d = 0) þá
                        s := s + 1,
                    eflok
                lykkjulok,
            lykkjulok,
            skrifastreng(;"Solution\n"),
            skrifa(;s),
        stofnlok
}
*
"GRUNNUR"
;

No comments:

Post a Comment