Skip to content

Instantly share code, notes, and snippets.

@revmischa
Last active December 27, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revmischa/7257619 to your computer and use it in GitHub Desktop.
Save revmischa/7257619 to your computer and use it in GitHub Desktop.
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