Skip to main content
Bounty Ended with 100 reputation awarded by Adám
added 12 characters in body
Source Link
Kamila Szewczyk
  • 12.6k
  • 1
  • 31
  • 61

APL (Dyalog Unicode), 1211 bytes

-1 thanks to Adam

⎕(+-|⍨)¨1+⍳31+⍳3

Try it online!Try it online!

Explanation:

⎕(+-|⍨)¨1+⍳31+⍳3
        1+⍳3    ⍝ 2 3 4
⎕               ⍝ read n
  +-|⍨          ⍝ {⍺ + ⍵ - ⍵ | ⍺}

Let's look at how {⍺ + ⍵ - ⍵ | ⍺} is transformed to +-|⍨:

        {⍺ + ⍵ - ⍵ | ⍺}
       {⍺} + {⍵ - ⍵ | ⍺}
         ⊣ + ({⍵} - {⍵ | ⍺})
         ⊣ + (⊢ - ({⍵} | {⍺}))
         ⊣ + (⊢ - (⊢ | ⊣))
        (⊣ + ⊢ - (⊢ | ⊣))
          (+ - (⊢ | ⊣))
          (+ - (⊣ |⍨ ⊢))
          (+ - (|⍨))
          (+-|⍨)

APL (Dyalog Unicode), 12 bytes

⎕(+-|⍨)¨1+⍳3

Try it online!

Explanation:

⎕(+-|⍨)¨1+⍳3
        1+⍳3    ⍝ 2 3 4
⎕               ⍝ read n
  +-|⍨          ⍝ {⍺ + ⍵ - ⍵ | ⍺}

Let's look at how {⍺ + ⍵ - ⍵ | ⍺} is transformed to +-|⍨:

        {⍺ + ⍵ - ⍵ | ⍺}
       {⍺} + {⍵ - ⍵ | ⍺}
         ⊣ + ({⍵} - {⍵ | ⍺})
         ⊣ + (⊢ - ({⍵} | {⍺}))
         ⊣ + (⊢ - (⊢ | ⊣))
        (⊣ + ⊢ - (⊢ | ⊣))
          (+ - (⊢ | ⊣))
          (+ - (⊣ |⍨ ⊢))
          (+ - (|⍨))
          (+-|⍨)

APL (Dyalog Unicode), 11 bytes

-1 thanks to Adam

⎕(+-|⍨)1+⍳3

Try it online!

Explanation:

⎕(+-|⍨)1+⍳3
       1+⍳3    ⍝ 2 3 4
⎕              ⍝ read n
  +-|⍨          ⍝ {⍺ + ⍵ - ⍵ | ⍺}

Let's look at how {⍺ + ⍵ - ⍵ | ⍺} is transformed to +-|⍨:

        {⍺ + ⍵ - ⍵ | ⍺}
       {⍺} + {⍵ - ⍵ | ⍺}
         ⊣ + ({⍵} - {⍵ | ⍺})
         ⊣ + (⊢ - ({⍵} | {⍺}))
         ⊣ + (⊢ - (⊢ | ⊣))
        (⊣ + ⊢ - (⊢ | ⊣))
          (+ - (⊢ | ⊣))
          (+ - (⊣ |⍨ ⊢))
          (+ - (|⍨))
          (+-|⍨)
added 450 characters in body
Source Link
Kamila Szewczyk
  • 12.6k
  • 1
  • 31
  • 61

APL (Dyalog Unicode), 12 bytes

⎕(+-|⍨)¨1+⍳3

Try it online!

Alternatively, with xAPL - 11 bytesExplanation:

  
⎕(+-|⍨)¨2⍫4¨1+⍳3
        1+⍳3    ⍝ 2 3 4
⎕               ⍝ read n
  +-|⍨          ⍝ {⍺ + ⍵ - ⍵ | ⍺}

Let's look at how {⍺ + ⍵ - ⍵ | ⍺} is transformed to +-|⍨:

        {⍺ + ⍵ - ⍵ | ⍺}
       {⍺} + {⍵ - ⍵ | ⍺}
         ⊣ + ({⍵} - {⍵ | ⍺})
         ⊣ + (⊢ - ({⍵} | {⍺}))
         ⊣ + (⊢ - (⊢ | ⊣))
        (⊣ + ⊢ - (⊢ | ⊣))
          (+ - (⊢ | ⊣))
          (+ - (⊣ |⍨ ⊢))
          (+ - (|⍨))
          (+-|⍨)

Try it online!

APL (Dyalog Unicode), 12 bytes

⎕(+-|⍨)¨1+⍳3

Try it online!

Alternatively, with xAPL - 11 bytes:

 
⎕(+-|⍨)¨2⍫4

Try it online!

APL (Dyalog Unicode), 12 bytes

⎕(+-|⍨)¨1+⍳3

Try it online!

Explanation:

 
⎕(+-|⍨)¨1+⍳3
        1+⍳3    ⍝ 2 3 4
⎕               ⍝ read n
  +-|⍨          ⍝ {⍺ + ⍵ - ⍵ | ⍺}

Let's look at how {⍺ + ⍵ - ⍵ | ⍺} is transformed to +-|⍨:

        {⍺ + ⍵ - ⍵ | ⍺}
       {⍺} + {⍵ - ⍵ | ⍺}
         ⊣ + ({⍵} - {⍵ | ⍺})
         ⊣ + (⊢ - ({⍵} | {⍺}))
         ⊣ + (⊢ - (⊢ | ⊣))
        (⊣ + ⊢ - (⊢ | ⊣))
          (+ - (⊢ | ⊣))
          (+ - (⊣ |⍨ ⊢))
          (+ - (|⍨))
          (+-|⍨)
Source Link
Kamila Szewczyk
  • 12.6k
  • 1
  • 31
  • 61

APL (Dyalog Unicode), 12 bytes

⎕(+-|⍨)¨1+⍳3

Try it online!

Alternatively, with xAPL - 11 bytes:

⎕(+-|⍨)¨2⍫4

Try it online!