Skip to main content
Clarified comments
Source Link
user81655
  • 11.2k
  • 1
  • 25
  • 50

JavaScript (ES6), 92 9190 bytes

n=>eval(`for(r=[],a=n+1;a=n;a;a--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                 // use eval to remove need for return keyword
  for(r=[],a=n+1;a=n;a;a--a;)     // iterate for each number a
    for(b=n;b;)           // iterate for each number b
      ~r.indexOf(x=a*b--) // check if it is already in the list, x = value
      ||r.push(x);        // add the result
  r.sort((a,b)=>a-b)      // sort the results by ascending value
                          // implicit: return r
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],a=n+1;a=n;a;a--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

JavaScript (ES6), 92 91 bytes

n=>eval(`for(r=[],a=n+1;--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                 // use eval to remove need for return keyword
  for(r=[],a=n+1;--a;)    // iterate for each number a
    for(b=n;b;)           // iterate for each number b
      ~r.indexOf(x=a*b--) // check if it is already in the list, x = value
      ||r.push(x);        // add the result
  r.sort((a,b)=>a-b)      // sort the results by ascending value
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],a=n+1;--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

JavaScript (ES6), 92 90 bytes

n=>eval(`for(r=[],a=n;a;a--)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                 // use eval to remove need for return keyword
  for(r=[],a=n;a;a--)     // iterate for each number a
    for(b=n;b;)           // iterate for each number b
      ~r.indexOf(x=a*b--) // check if it is already in the list, x = value
      ||r.push(x);        // add the result
  r.sort((a,b)=>a-b)      // sort the results by ascending value
                          // implicit: return r
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],a=n;a;a--)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

deleted 35 characters in body
Source Link
user81655
  • 11.2k
  • 1
  • 25
  • 50

JavaScript (ES6), 9292 91 bytes

n=>eval(`for(r=[],i=n*n;i;a=n+1;--a;)for(b=n;b;)~r.indexOf(x=(x=a*b--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                             // use eval to remove need for return keyword
  for(r=[],i=n*n;i;a=n+1;--a;)    // iterate for each number a
    for(b=n;b;)           // iterate n^2 times,for reach =number resultsb
      ~r.indexOf(x=(x=a*b--i%n+1)*(i/n+1|0)) // i%n getscheck theif firstit number,is i/nalready getsin the secondlist, x = value
      ||r.push(x);                    // add the result if it is not there already
  r.sort((a,b)=>a-b)                  // sort the results by ascending value
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],i=n*n;i;a=n+1;--a;)for(b=n;b;)~r.indexOf(x=(x=a*b--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

JavaScript (ES6), 92 bytes

n=>eval(`for(r=[],i=n*n;i;)~r.indexOf(x=(--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                             // use eval to remove need for return keyword
  for(r=[],i=n*n;i;)                  // iterate n^2 times, r = results
    ~r.indexOf(x=(--i%n+1)*(i/n+1|0)) // i%n gets the first number, i/n gets the second
      ||r.push(x);                    // add the result if it is not there already
  r.sort((a,b)=>a-b)                  // sort the results by ascending value
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],i=n*n;i;)~r.indexOf(x=(--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

JavaScript (ES6), 92 91 bytes

n=>eval(`for(r=[],a=n+1;--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                 // use eval to remove need for return keyword
  for(r=[],a=n+1;--a;)    // iterate for each number a
    for(b=n;b;)           // iterate for each number b
      ~r.indexOf(x=a*b--) // check if it is already in the list, x = value
      ||r.push(x);        // add the result
  r.sort((a,b)=>a-b)      // sort the results by ascending value
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],a=n+1;--a;)for(b=n;b;)~r.indexOf(x=a*b--)||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>

Source Link
user81655
  • 11.2k
  • 1
  • 25
  • 50

JavaScript (ES6), 92 bytes

n=>eval(`for(r=[],i=n*n;i;)~r.indexOf(x=(--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

Explanation

n=>eval(`                             // use eval to remove need for return keyword
  for(r=[],i=n*n;i;)                  // iterate n^2 times, r = results
    ~r.indexOf(x=(--i%n+1)*(i/n+1|0)) // i%n gets the first number, i/n gets the second
      ||r.push(x);                    // add the result if it is not there already
  r.sort((a,b)=>a-b)                  // sort the results by ascending value
`)

Test

N = <input type="number" oninput="result.innerHTML=(

n=>eval(`for(r=[],i=n*n;i;)~r.indexOf(x=(--i%n+1)*(i/n+1|0))||r.push(x);r.sort((a,b)=>a-b)`)

)(+this.value)" /><pre id="result"></pre>