Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Update MATL Online URL
Source Link
Suever
  • 11.2k
  • 1
  • 24
  • 52

MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result

MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result

MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result
Commonmark migration
Source Link

#MATL, 12 bytes

MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result

#MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result

MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result
Source Link
Suever
  • 11.2k
  • 1
  • 24
  • 52

#MATL, 12 bytes

q:Q"@Z\l_)vs

Try it at MATL Online

Explanation

 % Implicitly grab input (N)
q % Subtract one
: % Create an array [1...(N-1)]
Q % Add one to create [2...N]
" % For each element
 @Z\ % Compute the divisors of this element (including itself)
 l_) % Grab the next to last element (the largest that isn't itself)
 v % Vertically concatenate the entire stack so far
 s % Sum the result

AltStyle によって変換されたページ (->オリジナル) /