Perl - convert ASCII art to use x operator


I would like to convert ASCII art to something that takes less bytes. I have string like this:

my $string = '                ██   ████   █';

And I would convert this to something like this:

print "█" x 1."█" x 1."█" x 1"█" x 1"█" x 1;

So I would write this in one line and convert to using x operator. How can achieve this?

Filip Grela

Posted 2018-04-30T20:56:16.340

Reputation: 11

Question was closed 2018-04-30T22:21:20.510


Welcome to PPCG! I have added the code-golf tag since questions here require a winning criteria. Generally questions here allow any language to compete (you can always say you are keen to see Perl solutions), so I'd suggest that (an alternative would be to fit this to the tips category but I think it fits better as a normal golf question). EDIT: I see Shaggy also added tips now - let's see where we go :)

– Jonathan Allan – 2018-04-30T21:11:58.223

Don't you mean print " " x 16."█" x 2." " x 3."█" x 4." " x 3."█" x 1;? – Adám – 2018-04-30T21:33:53.367

@JonathanAllan even if it was intended as a challenge, it's horribly underspecified. – Nissa – 2018-04-30T21:42:27.240

@StephenLeppik I don't think it was and agree. It could probably be made into one though! – Jonathan Allan – 2018-04-30T21:50:52.817

@JonathanAllan Isn't it just asking for run-length encoding? – Adám – 2018-04-30T22:40:46.173

@Adám uh, probably. – Jonathan Allan – 2018-04-30T22:56:09.957

XY problem? How can you be sure that RLE is the shortest way? – user202729 – 2018-05-01T04:33:01.763

This was first posted on StackOverflow – wastl – 2018-05-01T06:58:24.833

No answers