Take that frown and turn it around

21

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:

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

Adám

Posted 2017-06-21T16:57:11.773

Reputation: 37 779

Answers

8

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)))

Arnauld

Posted 2017-06-21T16:57:11.773

Reputation: 111 334

8

Python 3, 105 bytes

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

Try it online!

xnor

Posted 2017-06-21T16:57:11.773

Reputation: 115 687

5

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.

Charlie

Posted 2017-06-21T16:57:11.773

Reputation: 11 448

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. – Matej – 2017-06-22T11:36:06.140

1@Matej Standard code golf rules allow submission of a function/lambda or a full program. – Adam Martin – 2017-06-22T11:48:15.053

3

Python 3, 140 137 116 bytes

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

Try it online!

Rod

Posted 2017-06-21T16:57:11.773

Reputation: 17 588

Fails for column 1 inputs – CalculatorFeline – 2017-06-21T18:24:10.000

Strange. It didn't work when I tried it earlier. Anyways, carry on. – CalculatorFeline – 2017-06-21T18:27:16.670

Your last character lost its : eyes. – xnor – 2017-06-21T19:43:36.627

3

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

Jonathan Allan

Posted 2017-06-21T16:57:11.773

Reputation: 67 804

That's some serious Jelly right there. Ugh. – Adám – 2017-06-21T23:54:51.830

bashes ordinals with mallet "...fit in there you smiles!" – Jonathan Allan – 2017-06-21T23:59:01.920

2

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!

Jörg Hülsermann

Posted 2017-06-21T16:57:11.773

Reputation: 13 026

+1 just for array_flip! – Adám – 2017-06-21T23:38:41.020

@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# – Jörg Hülsermann – 2017-06-21T23:43:42.323

1removing the quotes from the symbols string runs as well, it's considered an undefined constant with same value – Einacio – 2017-06-22T02:53:04.580

1

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.

Emigna

Posted 2017-06-21T16:57:11.773

Reputation: 50 798