Skip to main content
Commonmark migration
Source Link

#MATL, 22 26 bytes

MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

A few extra bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

#MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

A few extra bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

A few extra bytes :-( due to a bug in the G function (paste input; now corrected for next release)

Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display
added 1 character in body
Source Link
Luis Mendo
  • 107k
  • 10
  • 142
  • 385

#MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

Lost aA few extra bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

#MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

Lost a few bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

#MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

A few extra bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display
added 6 characters in body
Source Link
Luis Mendo
  • 107k
  • 10
  • 142
  • 385

#MATL, 2622 26 bytes

1tiXIX"i:XK"tI_QJ*0hXK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!Try it online!

Lost a few bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  I_QJ*0hPI:)       % takeflip lastarray Nand elementstake offirst thatN arrayelements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

#MATL, 26 bytes

1tiXIX"i:XK"tI_QJ*0h)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

Lost a few bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  I_QJ*0h)   % take last N elements of that array
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display

#MATL, 22 26 bytes

1tiXIX"i:XK"tPI:)sh]K)

This uses current release (10.2.1) of the language/compiler.

Try it online!

Lost a few bytes :-( due to a bug in the G function (paste input; now corrected for next release)

###Explanation

1tiXIX"      % input N. Copy to clipboard I. Build row array of N ones
i:XK         % input X. Build row array [1,2,...X]. Copy to clipboard I
"            % for loop: repeat X times. Consumes array [1,2,...X]
  t          % duplicate (initially array of N ones)
  PI:)       % flip array and take first N elements
  sh         % compute sum and append to array
]            % end
K)           % take the first X elements of array. Implicitly display
added 558 characters in body
Source Link
Luis Mendo
  • 107k
  • 10
  • 142
  • 385
Loading
Source Link
Luis Mendo
  • 107k
  • 10
  • 142
  • 385
Loading