Instantly share code, notes, and snippets.

Embed
What would you like to do?
y/01/_*/,print for map{sprintf("%011b\n",$_)}(32,32,80,136,260,1539,260,136,80,32,32)
# 41558682057254037406452518895026208 = bitmap of 0=_,1=*, packed as 11-bit lines
# 11-bit chunks: 32 32 80 136 260 1539 260 136 80 32 32
# %011b gives:
# 00000100000
# 00000100000
# 00001010000
# 00010001000
# 00100000100
# 11000000011
# 00100000100
# 00010001000
# 00001010000
# 00000100000
# 00000100000
# which can be turned into _s and *s with the transliteration operator, y///
# bitmap-packing code
;
use bigint;
my $encoded = '';
my $cs = 11; # do 11-bit chunks representing each line
for (my $i=0; $i < $cs*11; $i+=$cs) {
# mask on only bits that are set and in this current 11-bit chunk
my $mask = 0;
for (my $j=0; $j < $cs; $j++) {
my $bit = 1 << $i + $j;
$mask |= $bit;
}
my $chunk = 41558682057254037406452518895026208 & $mask;
$encoded = sprintf("%i", $chunk >> $i) . ',' . $encoded;
}
warn $encoded;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment