15 April 2023

Torus puzzle


This is the first entry this year, since I almost forgot about the possibility of communications via this blog! In fact, yesterday I found a very early paper written by me, in an archive collection of old computer magazines. Here is it. I was so young that I was not even able to write a paper, but an enthusiastic journalist, Géza Győriványi started to mentor me via opening publicity for my first programming attempts.

I was not much older than 10 years. It was during the very last years of the socialist era in Hungary. Trading of home computers like ZX Spectrum were officially banned because Hungary was a good friend of the Soviet Union, but after Gorbachev's openings, restrictions were not taken so seriously by the Western countries as before. My father was among the lucky engineers who managed to buy a ZX Spectrum in Germany in 1984 during a business trip. But not only he. Many others found ways to obtain home computers. For example, an old lady, Auntie Lenke, born as Lenke Kardos, a later widow of Sándor Dárdai, exactly 60 years older than I.

Géza Győriványi, a journalist at Mikrovilág (and probably at other ones – I never met him in person and never communicated with him just by mail correspondence) decided to include one of my early submissions in that part of the journal that published source code from non-professionals. My contribution was a simple game, I saw some similar ideas in other computer games, but finally I wrote my own version in BASIC. ZX Spectrum's BASIC was very convenient, quite easy to learn. It provided a beginner friendly way to write simple programs, even computer games.

That is, my contribution was not really new, but in the sense of contribution of a young boy it was something different. And this fact started my friendship with Auntie Lenke at the same time. She went to the shop (she was 70), bought the magazine with my computer game, and started to type it in the computer. I guess she was quick enough in typing (note that she was the first female bookkeeper in Hungary after the World War II), but she must have been difficulties during entering line 62 DEF FN P()=FN Y()-(OR()*60)! In fact, she realized this issue sooner or later because she immediately contacted the magazine with the complain: it does not work!

Auntie Lenke was a typical figure who complained when something did not work. She complained at politicians because of their stupid decisions, she regularly wrote letters to ministers, and of course, she always complained at the market if vegetables were not fresh or cheap enough. I spent several days with her, after her complaining at the magazine, because the editors forwarded her letter to me. But, at the same time, she invited me to her home for a couple of days. She lived in Budapest, quite close to my home town Jászberény, it was just two hours by car or train. So, she invited me, I fixed the code, and this was just a beginning of a long friendship.

Actually, the issue was not my fault. The journal edited my source code with some strange system before printing it and the user defined functions FN O() and FN P() were rewritten as OR() and DPEEK(), respectively. Of course, this made no sense. Without having this piece of background information, Auntie Lenke had no chance to fix the problem on her own. I think we never clarified this issue at the editors of the magazine, but I guess it was quite usual that certain programs did not work. But that was fine like that. Programming was always a challenge and this remains so for several generations.

So, yesterday I gave it a try and typed my own program (gosh, I wrote it 37 years ago!) in a ZX Spectrum emulator. I used Fuse which is easy to install on a recent Ubuntu. However, I needed to install the original ZX Spectrum ROM (package spectrum-roms) as well, otherwise some commands like INK did not work (Fuse uses the file opense.rom by default which seems to provide a somewhat different BASIC dialect than the original one in the 48K BASIC). After some 2 hours of hard work I managed to type the code error-free and managed to run it. Luckily, there are nice tools to embed such programs in a web browsers, so you can see below how it used to look like:


Here you can find the corrected version of the source code. If you want to have a full look, click on the ▶ button, press ENTER or Y or some other keys (but don't use N or SPACE). If you want to quit listing, just press N (or SPACE). Then, by typing R you will get the keyword RUN, and by pressing ENTER you can start the game. OK, I know, it is in Hungarian, so you need some hints. First, you will hear some intro music that recalls some short Russian folk song, perhaps quite typical in the socialist era. I don't really remember why I used this melody. Then, you need the select the game level from 1-5, and then the squares will be scrambled accordingly. By using the key S you can start the game and try to reorganize the pieces into their original position by using the keys A-P. Note that you can have a limited amount of time to do that. If you succeed, your time will be listed among the best results. You can always give up by pressing Q. Finally you get back to the start screen and need to listen to the same melody.

Of course, there are several issues with this program. For example, the way it displays things is quite slow, the keyboard handling is a bit unresponsive. But note that this was one of my first programs, and actually I already used a reasonable amount of tricky things, so I find the source code not really bad.

But this is just one thing. Maybe you are interested in the mathematical background of this game. And yes, this is already quite well-discussed. The game is officially called torus puzzle, some variants can be found under the name LoopOver, and a 2012 paper is also available that discusses some details on the solvability. In fact, the torus puzzle is quite close to the 15 puzzle which has a quite large literature. It seems, however, that there are still open questions on the torus puzzle, so it can be an interesting research field for today's researchers!

I uploaded a demo video on how to solve the puzzle for level 2. This video was created by using Fuse's recording capability into an RZX file. Then, I had to run a command like fuse --movie-start output.fmf --rate 2 --sound-freq 44100 --separation ACB input.rzx to have an FMF file. Finally, a command like fmfconv -i output.fmf -o output.mov -f raw -Q 100 helped to get a movie file that was already well-prepared for a YouTube upload.

Some final words on Aunt Lenke: We spent then several weeks (usually one week a year) together. As the years went by, I visited her in her 6th district flat, and later, in the 5th district in a home for the elderly. We always had great discussion, mostly on computers, but also on other things. She taught me a lot, by introducing me some nice parts of Budapest, including the neighborhood of the Budapest-Nyugati (western) railway station and the Margaret Island. Sometimes we played chess.

She was indeed like my third grandmother. She passed away in 1999, 24 years ago, just a couple of weeks after I married my wife. And yes, this was the beginning of another story!

Credits: The ZX Spectrum emulator is an embedded version of Matt Wescott's JSSpeccy 3.


Entries on topic technical developments

  1. Embedding realgeom in GeoGebra (9 July 2021)
  2. Web version of Tarski (1 October 2021)
  3. Developing Giac with Qt Creator on Windows (24 January 2022)
  4. Compiling Giac via MSYS2/CLANG32 (2 April 2022)
  5. Terminals on the web (28 June 2022)
  6. Torus puzzle (15 April 2023)
  7. Tube amoeba (16 April 2023)
  8. XaoS in WebAssembly (30 August 2023)
  9. Debut of GNU Aris in WebAssembly (11 November 2023)
  10. JGEX 0.81 (in Hungarian) (10 December 2023)
  11. xaos.app (2 January 2024)

Zoltán Kovács
Linz School of Education
Johannes Kepler University
Altenberger Strasse 69
A-4040 Linz