Skip to main content
3 of 4
deleted 8 characters in body
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

APL, 18 16 bytes

{y[⍋y←∪,∘.×⍨⍳⍵]}

This is an unnamed monadic function. The output is in ascending order.

Explanation:

             ⍳⍵}    ⍝ Get the integers from 1 to the input
         ∘.×⍨       ⍝ Compute the outer product of this with itself
        ,           ⍝ Flatten into an array
       ∪            ⍝ Select unique elements
     y←             ⍝ Assign to y
 {y[⍋               ⍝ Sort ascending

Fixed an issue and saved 2 bytes thanks to Thomas Kwa!

Alex A.
  • 24.7k
  • 5
  • 38
  • 119