Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 15 characters in body
Source Link
hyperneutrino
  • 42.8k
  • 5
  • 72
  • 227

Jelly, 2421 bytes

iⱮṛ/;\BUz0ZUḊFŻ8¡s8z0ZḄḊJBUz0ZU8,yFŻ8¡s8z0ZḊḄ

Try It Online! Try It Online!

JBUz0ZU8,yFŻ8¡s8z0ZḊḄ Main Link
J Generate [1, 2, ...] as long as the encoding list
 B Convert to binary
 Uz0ZU Reverse, transpose padding with 0, transpose, reverse (*)
 8, Pair the encoding list with the padded binary list
 y Use this to translate the message into binary strings
 F Flatten
 Ż8¡ Prepend 0 8 times (in case the list is shorter than 8)
 s8 Slice into blocks of 8
 z0Z Transpose padding with 0, transpose (**)
 Ḋ Remove the block of 8 zeroes at the start
 Ḅ Convert from binary into numbers
(*) this is a common pattern used to left-pad everything to the same length
(**) this is a common pattern used to right-pad everything to the same length -
 because we prepended a block of 8 zeroes, there is at least one sublist
 of length 8, so everything will be padded to length 8

Jelly, 24 bytes

iⱮṛ/;\BUz0ZUḊFŻ8¡s8z0ZḄḊ

Try It Online!

Jelly, 21 bytes

JBUz0ZU8,yFŻ8¡s8z0ZḊḄ

Try It Online!

JBUz0ZU8,yFŻ8¡s8z0ZḊḄ Main Link
J Generate [1, 2, ...] as long as the encoding list
 B Convert to binary
 Uz0ZU Reverse, transpose padding with 0, transpose, reverse (*)
 8, Pair the encoding list with the padded binary list
 y Use this to translate the message into binary strings
 F Flatten
 Ż8¡ Prepend 0 8 times (in case the list is shorter than 8)
 s8 Slice into blocks of 8
 z0Z Transpose padding with 0, transpose (**)
 Ḋ Remove the block of 8 zeroes at the start
 Ḅ Convert from binary into numbers
(*) this is a common pattern used to left-pad everything to the same length
(**) this is a common pattern used to right-pad everything to the same length -
 because we prepended a block of 8 zeroes, there is at least one sublist
 of length 8, so everything will be padded to length 8
Source Link
hyperneutrino
  • 42.8k
  • 5
  • 72
  • 227

Jelly, 24 bytes

iⱮṛ/;\BUz0ZUḊFŻ8¡s8z0ZḄḊ

Try It Online!

AltStyle によって変換されたページ (->オリジナル) /