Skip to main content
added 535 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 62 55 51 bytes

Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk

\(a,d,`*`=array)a[t(t(which(T*d,T)-1)%%dim(a)+1)]*d

Attempt This Online!


R, 49 bytes

\(a,d)array(a[t(t(which(!a*0,T)-1)%%dim(a)+1)],d)

Attempt This Online!

Works with arrays of finite numbers. In this case, we don't need to create a new array of TRUE elements to get the indices, as we can just multiply the elements by zero and take the logical NOT.

R, 62 55 51 bytes

Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk

\(a,d,`*`=array)a[t(t(which(T*d,T)-1)%%dim(a)+1)]*d

Attempt This Online!

R, 62 55 51 bytes

Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk

\(a,d,`*`=array)a[t(t(which(T*d,T)-1)%%dim(a)+1)]*d

Attempt This Online!


R, 49 bytes

\(a,d)array(a[t(t(which(!a*0,T)-1)%%dim(a)+1)],d)

Attempt This Online!

Works with arrays of finite numbers. In this case, we don't need to create a new array of TRUE elements to get the indices, as we can just multiply the elements by zero and take the logical NOT.

added 42 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 62 5555 51 bytes

Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk

\(a,d,`*`=array)array(a[t(t(which(array(T,d)T*d,T)-1)%%dim(a)+1)],d)]*d

Attempt This Online!Attempt This Online!

R, 62 55 bytes

Edit: -7 bytes thanks to Giuseppe

\(a,d)array(a[t(t(which(array(T,d),T)-1)%%dim(a)+1)],d)

Attempt This Online!

R, 62 55 51 bytes

Edit: -7 bytes thanks to Giuseppe, and -4 bytes thanks to pajonk

\(a,d,`*`=array)a[t(t(which(T*d,T)-1)%%dim(a)+1)]*d

Attempt This Online!

added 22 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 6262 55 bytes

Edit: -7 bytes thanks to Giuseppe

\(a,d){i=whicharray(b<-a[t(t(which(array(T,d),T);b[i]=a[t(t(i-1)%%dim(a)+1)];b}],d)

Attempt This Online!Attempt This Online!

R, 62 bytes

\(a,d){i=which(b<-array(T,d),T);b[i]=a[t(t(i-1)%%dim(a)+1)];b}

Attempt This Online!

R, 62 55 bytes

Edit: -7 bytes thanks to Giuseppe

\(a,d)array(a[t(t(which(array(T,d),T)-1)%%dim(a)+1)],d)

Attempt This Online!

Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading