Sort the unique numbers in a multiplication table
Python 2, 61 51 bytes
lambda n:sorted({~(i%n)*~(i/n)for i in range(n*n)})
Thanks to xnor for shortening some syntax.
Pyth, 8 bytes
S{*M^SQ2
Try it online.
Explanation: SQ
takes the evaluated list input (Q
) and makes a list [1, 2, ..., Q]
. ^SQ2
takes the Cartesian product of that list with itself - all possible product combinations. *M
multiplies all these pairs together to form all possible results in the multiplication table and S{
makes it unique and sorts it.
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!