Skip to main content
deleted 151 characters in body
Source Link
Doorknob
  • 71.7k
  • 20
  • 143
  • 385

zsh, 8686 56 bytes

thanks to @Dennis for saving 30(!) bytes

function { (for a in {1..$1};do for;for b in {1..$1};do echo;echo $((a*b));done;done$[a*b])|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]   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 Bash doesn't expand {1..$1}—it just interprets it literally (so, a=5; echo {1..$a} outputs {1..5} instead of 1 2 3 4 5).

  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).

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).

zsh, 86 56 bytes

thanks to @Dennis for saving 30(!) bytes

(for a in {1..$1};for b in {1..$1};echo $[a*b])|sort -nu

Explanation / ungolfed:

(                      # begin subshell
  for a in {1..$1}     # loop through every pair of multiplicands
    for b in {1..$1}
      echo $[a*b]      # calculate a * b, output to stdout
) | 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 Bash doesn't expand {1..$1}—it just interprets it literally (so, a=5; echo {1..$a} outputs {1..5} instead of 1 2 3 4 5).

added 521 characters in body
Source Link
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).

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)
}

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).

added 521 characters in body
Source Link
Doorknob
  • 71.7k
  • 20
  • 143
  • 385
 

zsh, 8786 bytes

function { (for a in {1..$1};do for b in {1..$1};do echo $a\*$b|bc;done;done)|sort -nu}
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)
}

zsh, 87 bytes

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

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)
}
Source Link
Doorknob
  • 71.7k
  • 20
  • 143
  • 385
Loading