Skip to main content
added 101 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

R, 117 144 137 133 129129 123 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array.

Thanks to Alex for the tip on the replacing sep with s and removing the function name.

Dropped the array completely and used a series of reps to build each line.

Although soundly beaten by Miff, his solution made me realise I could drop the s=' ' altogether.

function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}}

And the test

> (function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 133 129 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array.

Thanks to Alex for the tip on the replacing sep with s and removing the function name.

Dropped the array completely and used a series of reps to build each line.

function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}}

And the test

> (function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 133 129 123 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array.

Thanks to Alex for the tip on the replacing sep with s and removing the function name.

Dropped the array completely and used a series of reps to build each line.

Although soundly beaten by Miff, his solution made me realise I could drop the s=' ' altogether.

function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T);if(d==n)b=d}}

And the test

> (function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 
added 87 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

R, 117 144 137 133133 129 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array. Thanks

Thanks to Alex for the tip on the replacing sep with s and removing the function name.

Dropped the array completely and used a series of reps to build each line.

function(i){a=array(0,c(s<-sums=sum(i),s));i=cumsum(i);b=1;for;b=0;for(n in 1:s){d=i[i>=n][1];a[b:dd=i[i>=n][1];cat(c(rep(0,b:d]=1;cat),rep(a[n1,]d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d+1b=d}}

And the test

> (function(i){a=array(0,c(s<-sums=sum(i),s));i=cumsum(i);b=1;for;b=0;for(n in 1:s){d=i[i>=n][1];a[b:dd=i[i>=n][1];cat(c(rep(0,b:d]=1;cat),rep(a[n1,]d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d+1b=d}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 133 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array. Thanks to Alex for the tip on the replacing sep with s and removing the function name.

function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,s=' ');if(d==n)b=d+1}}

And the test

> (function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,s=' ');if(d==n)b=d+1}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 133 129 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array.

Thanks to Alex for the tip on the replacing sep with s and removing the function name.

Dropped the array completely and used a series of reps to build each line.

function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}}

And the test

> (function(i){s=sum(i);i=cumsum(i);b=0;for(n in 1:s){d=i[i>=n][1];cat(c(rep(0,b),rep(1,d-b),rep(0,s-d)),fill=T,s=' ');if(d==n)b=d}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 
added 229 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48

R, 117 144 137137 133 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array. Thanks to Alex for the tip on the replacing sep with s and removing the function name.

f=functionfunction(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,sep='s=' ');if(d==n)b=d+1}}

And the test

> f(function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,s=' ');if(d==n)b=d+1}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array.

f=function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,sep=' ');if(d==n)b=d+1}}

And the test

> f(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 

R, 117 144 137 133 bytes

Reasonably verbose at the moment. Should be able to shave a few more out. Gained a number of bytes formatting it correctly, but saved some swapping out the matrix for an array. Thanks to Alex for the tip on the replacing sep with s and removing the function name.

function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,s=' ');if(d==n)b=d+1}}

And the test

> (function(i){a=array(0,c(s<-sum(i),s));i=cumsum(i);b=1;for(n in 1:s){d=i[i>=n][1];a[b:d,b:d]=1;cat(a[n,],fill=T,s=' ');if(d==n)b=d+1}})(c(5,1,1,3,1))
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0 1
> 
added 4 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48
Loading
deleted 430 characters in body
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48
Loading
Source Link
MickyT
  • 12.2k
  • 2
  • 26
  • 48
Loading