25
\$\begingroup\$

A celebration of the many faces of APL

Given a string among those in column 1 or column 2 of the below table, return the string's neighbor to its right. In other words, if given a string in column 1 then return column 2's string on that row, and if given a string in column 2 then return column 3's string on that row.

The codepoints (other than :'s) are listed on the far right.

 column 1   column 2   column 3
:⊢ →  → ⊣:   U+22a2 U+2361 U+22a3
:▷ →  → ◁:   U+25b7 U+2362 U+25c1
:⋆ →  → ⋆:   U+22c6 U+2363 U+22c6
:∘ →  → ∘:   U+2218 U+2364 U+2218
:○ →  → ○:   U+25cb U+2365 U+25cb
:≀ →  → ≀:   U+2240 U+2368 U+2240
:∧ →  → ∨:   U+2227 U+2369 U+2228

Anecdote: Most of these symbols are valid or proposed in some APL dialect (they are all links).

Per request, just the symbols:

:⊢ ⍡ ⊣:
:▷ ⍢ ◁:
:⋆ ⍣ ⋆:
:∘ ⍤ ∘:
:○ ⍥ ○:
:≀ ⍨ ≀:
:∧ ⍩ ∨:
\$\endgroup\$
0

8 Answers 8

9
\$\begingroup\$

JavaScript (ES6), 108 107 bytes

s=>(S="⊢▷⋆∘○≀∧⍡⍢⍣⍤⍥⍨⍩⊣◁⋆∘○≀∨")[S.search(s[1]||s)+7]+(s[1]?'':':')

Demo

let f =

s=>(S="⊢▷⋆∘○≀∧⍡⍢⍣⍤⍥⍨⍩⊣◁⋆∘○≀∨")[S.search(s[1]||s)+7]+(s[1]?'':':')

;[
  ":⊢", ":▷", ":⋆", ":∘", ":○", ":≀", ":∧",
  "⍡", "⍢", "⍣", "⍤", "⍥", "⍨", "⍩"
]
.forEach(s => console.log(s + ' → ' + f(s)))

\$\endgroup\$
9
\$\begingroup\$

Python 3, 105 bytes

lambda s:":⊢⍡⊣:▷⍢◁:⋆⍣⋆:∘⍤∘:○⍥○:≀⍨≀:∧⍩∨:".split(s)[1][:3-len(s)]

Try it online!

\$\endgroup\$
5
\$\begingroup\$

C# (.NET Core), 148 134 bytes

s=>{var c="⊢⍡⊣▷⍢◁⋆⍣⋆∘⍤∘○⍥○≀⍨≀∧⍩∨";return c[c.IndexOf(s[s.Length-1])+1]+(s.Length<2?":":"");}

Try it online!

  • 14 bytes saved after golfing a little.
\$\endgroup\$
2
  • \$\begingroup\$ Wanted to ask, is it valid to just omit the obvious scaffolding (class Program, static void Main) you need from the byte count? I typically use JVM languages and of course it would be cool if I could just omit the class/main function declaration and just count the meat of my code, but I'm not sure if this is the case. \$\endgroup\$
    – Matej
    Jun 22, 2017 at 11:36
  • 1
    \$\begingroup\$ @Matej Standard code golf rules allow submission of a function/lambda or a full program. \$\endgroup\$ Jun 22, 2017 at 11:48
4
\$\begingroup\$

Jelly, 56 bytes

“¤'aẎṚl’b4ạ37ż“ɱaɲṢbḊİcİðdðṖeṖ@h@'i(‘ḅ⁹Ọɓi@€Ṁ‘ị;⁸LḂx@”:¤

A full program.

Try it online!

Note: (ɱaɲ!) While there is some pattern to the non-: ordinals (middle column almost consecutive, many left and rights being the same - only two off by one and one off by ten) it just does not seem quite enough for such a small data set to allow any byte saves over this.

The first thirteen bytes could also be “¡ÐɼU¹’ṃ“"%#‘.

How?

“¤'aẎṚl’b4ạ37ż“ ... ‘ḅ⁹Ọɓi@€Ṁ‘ị;⁸LḂx@”:¤ - Main link: list of characters, frown
“¤'aẎṚl’                                 - base 250 number = 4064044420859
        b4                               - to base 4 = [3, 2, 3, 0, 2, 0, 3, 2, 3, 3, 2, 3, 0, 2, 0, 3, 2, 3, 3, 2, 3]
          ạ37                            - absolute diffence with 37 = [34, 35, 34, 37, 35, 37, 34, 35, 34, 34, 35, 34, 37, 35, 37, 34, 35, 34, 34, 35, 34]
              “ ... ‘                    - code page indexes = [162, 97, 163, 183, 98, 193, 198, 99, 198, 24, 100, 24, 203, 101, 203, 64, 104, 64, 39, 105, 40]
             ż                           - zip together = [[34, 162], [35, 97], [34, 163], [37, 183], [35, 98], [37, 193], [34, 198], [35, 99], [34, 198], [34, 24], [35, 100], [34, 24], [37, 203], [35, 101], [37, 203], [34, 64], [35, 104], [34, 64], [34, 39], [35, 105], [34, 40]]
                      ⁹                  - literal 256
                     ḅ                   - convert from base = [8866, 9057, 8867, 9655, 9058, 9665, 8902, 9059, 8902, 8728, 9060, 8728, 9675, 9061, 9675, 8768, 9064, 8768, 8743, 9065, 8744]
                       Ọ                 - convert to characters = "⊢⍡⊣▷⍢◁⋆⍣⋆∘⍤∘○⍥○≀⍨≀∧⍩∨"
                        ɓ                - dyadic chain separation, call that smiles
                         i@€             - first index of €ach frown character in smiles
                            Ṁ            - maximum (any ':' was not found so yielded 0)
                             ‘           - increment
                              ị          - index into smiles
                                       ¤ - nilad followed by link(s) as a nilad
                                ⁸        -   chain's left argument, frown
                                 L       -   length
                                  Ḃ      -   mod 2
                                     ”:  -   literal ':'
                                   x@    -   repeat with swapped @rguments
                               ;         - concatenate
                                         - implicit print

Employing Emigna's 05AB1E method of compression saves three for 53 bytes:

“ȤỤ.ḍṅfḲBṆ µṾḢƲ¿ṭVÄ⁹L5ı;ṡaÐ’Ds3Ḍ+⁽œẉỌɓi@€Ṁ‘ị;⁸LḂx@”:¤

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ That's some serious Jelly right there. Ugh. \$\endgroup\$
    – Adám
    Jun 21, 2017 at 23:54
  • 1
    \$\begingroup\$ bashes ordinals with mallet "...fit in there you smiles!" \$\endgroup\$ Jun 21, 2017 at 23:59
  • \$\begingroup\$ Your comment made me laugh more than I'm proud to admit \$\endgroup\$
    – RGS
    Apr 28, 2020 at 17:57
3
\$\begingroup\$

Python 3, 140 137 116 bytes

lambda n,x=":⊢⍡⊣:▷⍢◁:⋆⍣⋆:∘⍤∘:○⍥○:≀⍨≀:∧⍩∨:":x[x.find(n)+len(n):x.find(n)+3]

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Fails for column 1 inputs \$\endgroup\$ Jun 21, 2017 at 18:24
  • \$\begingroup\$ Strange. It didn't work when I tried it earlier. Anyways, carry on. \$\endgroup\$ Jun 21, 2017 at 18:27
  • \$\begingroup\$ Your last character lost its : eyes. \$\endgroup\$
    – xnor
    Jun 21, 2017 at 19:43
3
\$\begingroup\$

05AB1E, 58 56 54 bytes

• î]D£Èтн»“¿āp÷ŒRÃÙŽ^мηWX·ć•3ô8728+çJ3ô':ý':.øI¡`3Ig-£

Try it online!

Explanation

• î]D£Èтн»“¿āp÷ŒRÃÙŽ^мηWX·ć•  # push a 63-digit base-255 compressed number
3ô                            # split in pieces of 3
  8728+                       # add 8728 to each
       çJ                     # convert to a string with the corresponding code points
         3ô                   # split in pieces of 3
           ':ý                # merge on ":"
              ':.ø            # surround with ":"
                  I¡          # split on input
                    `         # push as separate to stack, the tail on top
                     3Ig-£    # take the first 3-len(input) characters

The above method should work with any number in the range [8676 ... 8728], so if I can find a number there that can be generated in 3 bytes I could save a byte over the current solution.

\$\endgroup\$
1
  • \$\begingroup\$ ':ý':.ø could be õ.ø':ý to save a byte. In addition, in the new 05AB1E version, the 8728 can be ŽYw. \$\endgroup\$ Apr 30, 2020 at 11:46
2
\$\begingroup\$

PHP, 147 bytes

<?=($f=array_flip($y=str_split(⍣⋆⍤∘⍥○⍨≀∧⍩∨⊢⍡⊣▷⍢◁,3))[trim($argn,":")])>7?$y[$f+1].":"[$f%3>1]:$y[$f^1].":"[$f&1];

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ +1 just for array_flip! \$\endgroup\$
    – Adám
    Jun 21, 2017 at 23:38
  • \$\begingroup\$ @Adám array_flip is one or two bytes shorter as the alternative array_search and the multibyte in this case cost much bytes. It is not nice to be longer as C# \$\endgroup\$ Jun 21, 2017 at 23:43
  • 2
    \$\begingroup\$ removing the quotes from the symbols string runs as well, it's considered an undefined constant with same value \$\endgroup\$
    – Einacio
    Jun 22, 2017 at 2:53
2
+100
\$\begingroup\$

APL (Dyalog Unicode), 103 bytes

-17 bytes thanks to Adám

(⌷∘S,':'/⍨14∘<)7+(S←'⊢▷⋆∘○≀∧⍡⍢⍣⍤⍥⍨⍩⊣◁⋆∘○≀∨')⍳⊢/

Try it online!

APL (Dyalog Unicode), 118 bytes

Since the asker is an APL programmer...

{(':'/⍨14<X),⍨S⌷⍨X←7+⍸(S←'⊢▷⋆∘○≀∧⍡⍢⍣⍤⍥⍨⍩⊣◁⋆∘○≀∨')∘.=⊢/⍵}

Try it online!

Explanation

S←'⊢▷⋆∘○≀∧⍡⍢⍣⍤⍥⍨⍩⊣◁⋆∘○≀∨'        ⍝ S is the lookup table.
⍸()∘.=⊢/⍵                             ⍝ Find the input in this LUT.
X←7+                                  ⍝ Add the index by 7 and assign to X. 
S⌷⍨                                  ⍝ Index into the LUT.
,⍨                                   ⍝ Append:
':'/                                 ⍝ The colon 
(⍨14<X)                              ⍝ if X is larger than 14.
\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.