Skip to main content
added 638 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Octave, 25 bytes

@(n)~mod(n,t=1:n)*t'==2*n 

Try it online!

Explanation

@(n)~mod(n,t=1:n)*t'==2*n @(n) % Define anonymous function with input n 1:n % Row vector [1,2,...,n] t= % Store in variable t mod(n, ) % n modulo [1,2,...,n], element-wise. Gives 0 for divisors ~ % Logical negate. Gives 1 for divisors t' % t transposed. Gives column vector [1;2;...;n] * % Matrix multiply 2*n % Input times 2 == % Equal? This is the output value 

Octave, 25 bytes

@(n)~mod(n,t=1:n)*t'==2*n 

Try it online!

Octave, 25 bytes

@(n)~mod(n,t=1:n)*t'==2*n 

Try it online!

Explanation

@(n)~mod(n,t=1:n)*t'==2*n @(n) % Define anonymous function with input n 1:n % Row vector [1,2,...,n] t= % Store in variable t mod(n, ) % n modulo [1,2,...,n], element-wise. Gives 0 for divisors ~ % Logical negate. Gives 1 for divisors t' % t transposed. Gives column vector [1;2;...;n] * % Matrix multiply 2*n % Input times 2 == % Equal? This is the output value 
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Octave, 25 bytes

@(n)~mod(n,t=1:n)*t'==2*n 

Try it online!