Skip to main content
added 593 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 71 bytes

function(s)intToUtf8(2^(7:0)%*%matrix((y=utf8ToInt(s))[-1:-2]==y[2],8))

Try it online!

Surprisingly golfy!

First, converts the string to ascii code-points with utf8ToInt, saving it as y. Removing the first two characters with negative indexing is shorter than using tail.

The array y[-1:-2]==y[2] is equivalent to the bits when %*% (matrix multiplication) is applied, but first we reshape that array into a matrix with nrow=8, converting from a linear array to byte groupings. Fortuitously, we can then convert to the ascii code points using matrix multiplication with the appropriate powers of 2, 2^(7:0), and then we convert the code points back to a string with intToUtf8.

R, 71 bytes

function(s)intToUtf8(2^(7:0)%*%matrix((y=utf8ToInt(s))[-1:-2]==y[2],8))

Try it online!

Surprisingly golfy!

R, 71 bytes

function(s)intToUtf8(2^(7:0)%*%matrix((y=utf8ToInt(s))[-1:-2]==y[2],8))

Try it online!

Surprisingly golfy!

First, converts the string to ascii code-points with utf8ToInt, saving it as y. Removing the first two characters with negative indexing is shorter than using tail.

The array y[-1:-2]==y[2] is equivalent to the bits when %*% (matrix multiplication) is applied, but first we reshape that array into a matrix with nrow=8, converting from a linear array to byte groupings. Fortuitously, we can then convert to the ascii code points using matrix multiplication with the appropriate powers of 2, 2^(7:0), and then we convert the code points back to a string with intToUtf8.

Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 71 bytes

function(s)intToUtf8(2^(7:0)%*%matrix((y=utf8ToInt(s))[-1:-2]==y[2],8))

Try it online!

Surprisingly golfy!