Skip to main content
Commonmark migration
Source Link

#Matlab, 93 91 bytes

Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.


For the record, this answer was written many hours after the challenge was created.

#Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.


For the record, this answer was written many hours after the challenge was created.

Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.


For the record, this answer was written many hours after the challenge was created.

added 92 characters in body
Source Link
Stewie Griffin
  • 46.8k
  • 16
  • 140
  • 304

#Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.


For the record, this answer was written many hours after the challenge was created.

#Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.

#Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.


For the record, this answer was written many hours after the challenge was created.

Source Link
Stewie Griffin
  • 46.8k
  • 16
  • 140
  • 304

#Matlab, 93 91 bytes

function l=f(l,m) n=numel(l)-1;i=0;while n&m;i=mod(i,n)+1;m=m-1;l(i:i+1)=sort(l(i:i+1));end 

Saves 11 bytes by omitting if l(i)>l(i+1);l(i:i+1)=l([i+1,i]), and instead just sort the two elements every time. Works for lists of length 1. Could save a byte or two using Octave's m-- operator, but that's not much.

Saves two more bytes by setting n=numel(l)-1;, because then I can just do while n instead of while n>1, and i=mod(i,n)+1 instead of i=mod(i,n-1)+1.