Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Challenge: Reading Banner Text

by Limbic~Region (Chancellor)
on Aug 26, 2010 at 14:31 UTC ( #857468=perlquestion: print w/replies, xml ) Need Help??

Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

A couple of nights ago, I had a strange dream. A competing organization was forced to share data with us. In an effort to make the data worthless to us, it had been processed through the banner (Unix) command. While being perfectly readable by a human, it wouldn't work in our system. I was called in to save the day with Perl but woke up prior to completing the parser.

Your challenge is to write a program to convert a file of banner text back into regular text. To ensure all competitors have an even playing field, you can generate your input using the following program:

#!/usr/bin/perl use strict; use warnings; use Text::Banner; my $text = $ARGV[0] || "Just another Perl hacker,"; my $b = Text::Banner->new; my @line = split /\n/, $text; for (@line) { $_ = substr($_, 0, 10); $b->set($_); $b->fill('#'); print $b->get, "\n"; }

The above program can truncate text which wouldn't be right in waking life but it didn't seem to be a problem in my dream. I personally do not have a solution but I did have a couple of ideas.

Cheers - L~R

Replies are listed 'Best First'.
Re: Challenge: Reading Banner Text
by roboticus (Chancellor) on Aug 26, 2010 at 15:04 UTC

    I think I'd read the text file of the banner and create a bitmap with a white pixel for every space, then use a black pixel for any other character. Feed it to an OCR module and profit!

    Alternatively, I'd read chunks separated by blank lines. I'd then use a hash with the key some form of the chunk (the chunk itself, a digest of it, ...). If it's a chunk you've never seen before, prompt the user for the appropriate character and emit that character. If you have seen it before, just emit the character. For banner text, I think it's better than the previous suggestion, and would make short work of it.


      That might be a good start, but it needs more work because with small enough width there might not be an empty line between two adjacent characters. Eg.

      The company knows this and will use a small enough width.

Re: Challenge: Reading Banner Text
by moritz (Cardinal) on Aug 26, 2010 at 15:16 UTC

    I've taken one of the two approaches, and put it in code. It works, but currently only for lower-case letters (and not terribly reliable); I guess I'm doing a stupid mistake somewhere, and my code is much more complicated than it needs to be. Anyway, here's the code:

    $ perl | perl st anotherl hacke

    I'll try to debug and improve it a bit, pending sufficient round tuits.

    Thanks for the challenge, always fun to attack them!

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Challenge: Reading Banner Text
by ambrus (Abbot) on Aug 26, 2010 at 15:46 UTC
Re: Challenge: Reading Banner Text
by Utilitarian (Vicar) on Aug 26, 2010 at 16:33 UTC
    Currently does the following, going to allow for spaces after I've had food
    ~/ $ banner Just another Perl hacker | ./ JustanotherPerlhacker
    Need a better letter boundary ;)

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: Challenge: Reading Banner Text
by TomDLux (Vicar) on Aug 26, 2010 at 17:27 UTC

    My preference was to generate each character, one by one, split the seven lines and use them as a 7-dimensional hash key leading to the resultant character. I would simply got through all 255 characters of ASCII. Of course, if they can use Unicode, you have a problem.

    Then read the file, 7 lines at a time, get 8 character wide substrings from each line, and look up the corresponding character.

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: Challenge: Reading Banner Text
by JavaFan (Canon) on Aug 26, 2010 at 16:03 UTC
    cpan[1]> install Text::Banner + Warning: Cannot install Text::Banner, don't know what it is. Try the command i /Text::Banner/ to find objects with matching identifiers. cpan[2]>
      Hrm yes, see this CPAN rating for Text::Banner which says:

      It doesn't install using cpan, and the directory structure seems messed up, so you have to download it and install it "by hand" (make / make install doesn't work either) from the tar file instead.

      I saw a couple of other choices: Text::FIGlet and banner from ppt. I probably should have chose one of them. I don't have capability at work, so I copy/pasted (I will beg forgiveness later). If you have any luck with the other options, feel free to create a suitable replacement input routine that will make a level playing field and I will update the root node with a pointer here.

      Cheers - L~R

Re: Challenge: Reading Banner Text
by MidLifeXis (Monsignor) on Aug 26, 2010 at 15:22 UTC

    Fixed font, or is the font able to change? Same question for characters from other character sets that look similar. See, I could work for your competitor :-b Update: Bah. Read before coffee == bad idea.


      Perhaps I am missing something but the program used to generate input should make it a level playing field for all?

      Cheers - L~R

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://857468]
Approved by moritz
Front-paged by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2022-05-21 03:01 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.