scene.org File Archive

File download

<root>­/­parties­/­2023­/­vccc23­/­christmas-diamonds/dmsc_ibm5110_apl_vc3-2023.zip

File size:
5 178 bytes (5.06K)
File date:
2024-01-03 14:15:17
Download count:
all-time: 36

Preview

  • ibm5110-apl/ dir
  • ibm5110-apl/apl-13x13.png 404B
  • ibm5110-apl/apl-7x7.png 414B
  • ibm5110-apl/apl-prog.png 352B
  • ibm5110-apl/apl-result.png 267B
  • ibm5110-apl/diamond-utf8.apl 34B
  • ibm5110-apl/file_id.diz 2.88K

file_id.diz

Diamond for APL under the IBM-5110

Author: dmsc
Category: Christmas Challenge
System:   IBM 5110
Language: APL
Len source code: 27
Len exe file:    N/A
Len code only:   N/A
Instructions:
  You can run the program using the web based IBM 5110 emulator at
  https://norbertkehrer.github.io/ibm_5110/emu5110.html

  In the emulator, switch to APL mode with the switch at the upper right, and
  then push the restar button.

  The screen of the IBM 5110 computer is only 64x16 characters, to see the full
  height of the pattern in a real computer you would need to connect a printer
  and see the printout.

Description:
  I decided to write an APL implementation of the challenge after seeing the
  last year entry by Peter De Watcher.

  The full program is:

    ' *'[1+3=6|V∘.-V←(5+⍳19)*2]

  The code explanation is the following:

        (5+⍳19)     : This gives the 19 numbers from 6 to 24
               *2   : Each number is squared: 36 49 64 ... 576 In modern APL
                      this could be written 2*⍨5+⍳19, avoiding parenthesis,
                      or even shorter ×⍨5+⍳19.
        V←          : The result is stored in the variable V = 36 49 ... 576.
      V∘.-          : The "outer product" of the subtraction of each element
                      of V and the list above.
                      This gives a matrix:
                          0  -13  -28  ... -540
                         13    0  -15  ... -527
                         28   15    0  ... -512
                        ...  ...  ...  ...  ...
                        540  527  512  ...    0
      6|            : Takes the modulo 6 of the numbers. Now, each position with
                      a star is exactly 3:
                          0 5 2 3 2 5 ... 0
                          1 0 3 4 3 0 ... 1
                          4 3 0 1 0 3 ... 4
                          3 2 5 0 5 2 ... 3
                          ...
     3=             : Selects all values equal to 3, so now we only have 1 or 0:
                          0 0 0 1 0 0 ... 0
                          0 0 1 0 1 0 ... 0
                          0 1 0 0 0 1 ... 0
                          1 0 0 0 0 0 ... 1
                          ...
     1+              : Adds 1, so now we have 1 (space) or 2 (star).
    ' *'[   ]        : String indexing - replace each 2 with the '*' symbol and
                       each 1 with a space.

  There are multiple variations of the same algorithm, for example:

  Subtracting 1 instead of adding 5 in at the start:

       ' *'[1+3=6|V∘.-V←(1-⍳19)*2]

  Using a temporary location "U" instead of the parenthesis:

       ' *'[1+3=6|V∘.-V←U×U←5+⍳19]

  Using multiple values instead of the 3=:

       '   *  '[1+6|V∘.-V←(5+⍳19)*2]

  Modern APL version, shorter by 4 characters (23 symbols):

       ' *'[1+3=6|∘.-⍨×⍨5+⍳19]