10
\$\begingroup\$

This challenge is a cut'n paste from Enlarge ASCII art, but reversed, using PetSCII based half-block chars:

string=" ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█"

So the goal is to reduce by 1/2 submited . For sample, from the string:

 OOOOOO  OOOOOO  OOOOOO  OOOOOOO      OOOOOO   OOOOOO  OO      OOOOOOO 
OO      OO    OO OO   OO OO          OO       OO    OO OO      OO      
OO      OO    OO OO   OO OOOOO       OO   OOO OO    OO OO      OOOOO   
OO      OO    OO OO   OO OO          OO    OO OO    OO OO      OO      
 OOOOOO  OOOOOO  OOOOOO  OOOOOOO      OOOOOO   OOOOOO  OOOOOOO OO      

you have to render:

 ▟▀▀▘▟▀▀▙▐▛▀▙▐▛▀▀  ▗▛▀▀ ▟▀▀▙▐▌  ▐▛▀▀ 
 █   █  █▐▌ █▐▛▀   ▐▌ ▜▌█  █▐▌  ▐▛▀  
 ▝▀▀▘▝▀▀▘▝▀▀▘▝▀▀▀   ▀▀▀ ▝▀▀▘▝▀▀▀▝▘   

(or even:

▗▛▀▀▗▛▀▜▖█▀▜▖█▀▀▘  ▟▀▀▘▗▛▀▜▖█   █▀▀▘ 
▐▌  ▐▌ ▐▌█ ▐▌█▀▘   █ ▝█▐▌ ▐▌█   █▀▘  
 ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀▘  ▝▀▀▘ ▀▀▀ ▀▀▀▘▀    

;-)

or where piping:

wget -O - https://codegolf.stackexchange.com/q/19123/9424 |
    sed -ne '/<pre><code>/,/<\/code><\/pre>/{//{/\//q};s/<pre><code>//;p}'
   ('l2v2l6v2'+  'e1l1v3l2'+
 'v3e1v7e1v7e1v7e1l2v6e1l4v5'+
'e1l6v4e1l8v3e1l7l3v2e1l9l3v1')
 .replace(/[lve]\d/g,function
   (c){return Array(-~c[1]).
      join({l:' ',v:'Love'
         ,e:'\n'}[c[0
             ]])})

could give:

▗▟█████▙▟█████▄
▜█████████████▛▘
 ▝▀███▙▛█████▀ 
    ▝▀▜██▀▘

Some samples:

asciiReduce sample

With (approx) same rules:

  • Input from STDIN or file
  • Each submited chars have to be represented, only whitespaces have to stay empty.
  • This is too, so the lowest score win. Score is computed as:
    • +1 by chars, to be counted in chars, not in bytes ie: s=' ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█' count 20 chars, not 52 !!
    • -10 for explanation;
    • +20 for use of external font tool or library.
\$\endgroup\$
  • \$\begingroup\$ So to clarify: the input image is divided into 2x2 squares and each maps onto one character? \$\endgroup\$ – Peter Taylor Jan 29 '14 at 8:25
  • 1
    \$\begingroup\$ -0.5 for adding strange bonuses (define explanation) - after rounding still an upvote. Also this is then code-challenge and not code-golf. \$\endgroup\$ – Howard Jan 29 '14 at 15:49
  • \$\begingroup\$ Most of these chars does not renders correctly in my browser. :( \$\endgroup\$ – Victor Stafusa Jan 30 '14 at 2:08
  • \$\begingroup\$ Under my linux, I use xterm -xrm 'XTerm*renderFont:false' & to open a console window able to display this properly. \$\endgroup\$ – F. Hauri Jan 30 '14 at 10:15
4
\$\begingroup\$

GolfScript (90 chars)

n/.,1&[""]*+.{,}%$-1=.1&+{1$,-´' '*+}+%2/{zip 2/{~+0\{32=!1$++}/" ▗▝▐▖▄▞▟▘▚▀▜▌▙▛█"3/=}%n}%

A lot of this goes to handling ragged arrays. Nasty test case:

xx
xxx
xxx
xx
x

contains a 3 different 2x2 grids with only one of the 4 cells containing any character at all.

To make things worse, the zip transposition to chop the columns into pairs gives the same output for ["xx" "xxx"]zip and ["xxx" "xx"]zip. I therefore begin by padding out to ensure that all lines are the same even length, and that there are an even number of lines.

Note that this program assumes that the interpreter will treat " ▗▖▄▝▐▞▟▘▚▌▙▀▜▛█" as a string of length 48, even though as per instructions in the question I'm counting it as 16 chars plus delimiters.

I've tested this to the best of my ability, but I can't find a monospace font which actually renders those characters correctly.

\$\endgroup\$
  • \$\begingroup\$ Your code seem fail on second test, with the heart... But nice! +1 as you'r the 1st! \$\endgroup\$ – F. Hauri Jan 29 '14 at 11:55
  • 1
    \$\begingroup\$ Hmm. I don't tend to use zip on ragged arrays, and I'm quite surprised by what it seems to do on e.g. ["##" "###"]. I'm going to have to rethink my approach. \$\endgroup\$ – Peter Taylor Jan 29 '14 at 12:54
  • \$\begingroup\$ Freemono, Unifont, Code2000, and Fixedsys Excelsior all render these characters correctly. \$\endgroup\$ – primo Jan 29 '14 at 13:26
  • \$\begingroup\$ @primo, Unifont is nowhere near monospaced on those characters. Fixedsys Excelsior isn't quite correct either, but it's close enough. \$\endgroup\$ – Peter Taylor Jan 29 '14 at 15:16
  • \$\begingroup\$ Yes! now you have it! Little remark: there is two empty lines at end of output. This don't break any rule! (Note: scoring is a little changed, you may save 10 points;-) \$\endgroup\$ – F. Hauri Jan 29 '14 at 15:45
1
\$\begingroup\$

Perl 6, 159 chars (192 bytes)

(|lines.map(*~' '),'')».comb(/../).rotor(2).map:{my@d='  'xx.max(*.elems);say [~] map {"█▛▜▀▙▌▚▘▟▞▐▝▄▖▗ ".comb[:2(.trans([' ',/./]=>~⑩))]},[Z~] .map:{|$_,|@d}}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Fixed my solution. \$\endgroup\$ – bb94 Apr 23 at 2:41
  • 1
    \$\begingroup\$ 143 chars \$\endgroup\$ – Jo King Apr 23 at 3:05
0
\$\begingroup\$

Bash (203 chars)

#!/bin/bash
r=" ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█";while IFS= read -r m;do IFS= read -r n;for((l=${#m}>${#n}?${#m}:${#n},i=0; i<l; i+=2)){
printf -ve %-2s "${n:i:2}" "${m:i:2}";e=${e//[^ ]/1};o+=${r:2#${e// /0}:1};};echo "$o";o=;done

or

r=" ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█"
while IFS= read -r m; do
    IFS= read -r n
    for ((l=${#m}>${#n}?${#m}:${#n},i=0; i<l; i+=2)) {
        printf -ve %-2s "${n:i:2}" "${m:i:2}"
        e=${e//[^ ]/1}
        o+=${r:2#${e// /0}:1}
    }
    echo "$o"
    o=
done
\$\endgroup\$
0
\$\begingroup\$

Perl (268 chars)

#!/usr/bin/perl -CS
use utf8;my $r=" ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█";while(@v=split"",<>){@w=split"",<>;foreach my $i(0..$#v/2){($a,$b,$c,$d)=qw|0 0 0 0|;$a=1if$w[$i*2]=~/\S/;$b=1if$w[$i*2+1]=~/\S/;$c=1if$v[$i*2]=~/\S/;$d=1if$v[$i*2+1]=~/\S/;print substr($r,ord pack("b8",$d.$c.$b.$a),1);};print "\n";};

or

#!/usr/bin/perl -CS
use utf8;
my $r = " ▝▘▀▗▐▚▜▖▞▌▛▄▟▙█";
while ( @v = split "", <> ) {
    @w = split "", <>;
    foreach my $i ( 0 .. $#v / 2 ) {
        ( $a, $b, $c, $d ) = qw|0 0 0 0|;
        $a = 1 if $w[ $i * 2 ] =~ /\S/;
        $b = 1 if $w[ $i * 2 + 1 ] =~ /\S/;
        $c = 1 if $v[ $i * 2 ] =~ /\S/;
        $d = 1 if $v[ $i * 2 + 1 ] =~ /\S/;
        print substr( $r, ord pack( "b8", $d . $c . $b . $a ), 1 );
    }
    print "\n";
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.