Skip to main content
3 of 4
added 521 characters in body
Doorknob
  • 71.7k
  • 20
  • 143
  • 385

zsh, 86 bytes

function { (for a in {1..$1};do for b in {1..$1};do echo $((a*b));done;done)|sort -nu}

Explanation / ungolfed:

function {             # declare an anonymous function
  (                    # begin subshell
    for a in {1..$1}   # loop through every pair of multiplicands
    do
      for b in {1..$1}
      do
        echo $((a*b))  # calculate a * b, output to stdout
      done
    done
  ) | sort -nu         # pipe output of subshell to `sort -nu', sorting
                       # numerically (-n) and removing duplicates (-u for uniq)
}

This doesn't work in Bash because

  1. Bash doesn't have anonymous functions.

  2. Bash does not expand {1..$1}—it just interprets it literally (so, a=5; echo {1..$a} outputs {1..5} instead of 1 2 3 4 5).

Doorknob
  • 71.7k
  • 20
  • 143
  • 385