Skip to main content
Commonmark migration
Source Link

#Matlab, 83, 77, 71 Bytes function a=x(a) if~nnz(a-a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

Matlab, 83, 77, 71 Bytes

function a=x(a)
if~nnz(a-a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened (twice!) thanks to stewie-griffin.

#Matlab, 83, 77, 71 Bytes function a=x(a) if~nnz(a-a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened (twice!) thanks to stewie-griffin.

Matlab, 83, 77, 71 Bytes

function a=x(a)
if~nnz(a-a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened (twice!) thanks to stewie-griffin.

added 14 characters in body
Source Link

#Matlab, 83, 7777, 71 Bytes function a=x(a) if(~nnzif~nnz(a(a~=a-a(1))));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened (twice!) thanks to stewie-griffin.

#Matlab, 83, 77 Bytes function a=x(a) if(~nnz(a(a~=a(1))));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened thanks to stewie-griffin.

#Matlab, 83, 77, 71 Bytes function a=x(a) if~nnz(a-a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened (twice!) thanks to stewie-griffin.

added 64 characters in body
Source Link

#Matlab, 8383, 77 Bytes function a=x(a) if(sum~nnz(a)/length(a)==aa~=a(1))));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened thanks to stewie-griffin.

#Matlab, 83 Bytes function a=x(a) if(sum(a)/length(a)==a(1));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

#Matlab, 83, 77 Bytes function a=x(a) if(~nnz(a(a~=a(1))));a=[a,1];else[~,I]=min(a);a(I)=a(I)+1;end

I'm relatively new to code golf so please be kind! I tried to use anonymous functions but googling says you can't use if/else statements and matlab doesn't have ternary operators, so this is the best i felt I could do.

Edit: Corrected and shortened thanks to stewie-griffin.

Source Link
Loading