ṃ - Base Decompression
Tags: array , number , base
This atom is dyadic, which means it takes two arguments.
x into base
len(y) and then index into
This is a good way to encode a list of repetitive values that don't form an easily compressible pattern. For example, to represent the string
"abcabbacbbcabcbbacbacbcbacb", there is no good pattern to it, but if you index into
0 for the last element instead of
3, so it can be converted into the appropriate base), you obtain the list
[1, 2, 0, 1, 2, 2, 1, 0, 2, 2, 0, 1, 2, 0, 2, 2, 1, 0, 2, 1, 0, 2, 0, 2, 1, 0, 2], which is
4418814364301 in base 3, which can be compressed into
“¤²5÷Ṫ2’ṃ“abc” decodes as
"abcabbacbbcabcbbacbacbcbacb", which saves 14 bytes, even including the trailing
¤ to combine it into a single nilad. Note that the index of the first value must not be zero when you are compressing, because base decoding does not produce leading zeroes.
You can generate these compressed forms with this code (it automatically base-250-compresses the integer because it's almost always quite large, but it is worth checking if the integer has a shorter representation and if this even saves bytes over the original representation).
This atom should work roughly the same way as or very similarly in concept to the following code snippets (some edge case exceptions may exist):