Skip to main content
2 of 3
added 450 characters in body
Kamila Szewczyk
  • 12.6k
  • 1
  • 31
  • 61

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 +-|⍨:

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