telgif: inverse figlet

20

1

figlet is utility that converts plain text to an ascii-art representation for use in banners and the like. For example:

$ figlet "CODE GOLF"
  ____ ___  ____  _____    ____  ___  _     _____ 
 / ___/ _ \|  _ \| ____|  / ___|/ _ \| |   |  ___|
| |  | | | | | | |  _|   | |  _| | | | |   | |_   
| |__| |_| | |_| | |___  | |_| | |_| | |___|  _|  
 \____\___/|____/|_____|  \____|\___/|_____|_|    

$

Write a program or function that takes the ascii-art output from figlet and returns it to its original plain text.

It may be helpful to you to install figlet. I have version 2.2.5 which is what you get if you sudo apt-get install figlet on Ubuntu 14.04. This figlet actually has several "fonts". For the purposes of this context, we will just be dealing with the default standard font.

Input text will be no more that 80 characters wide, and will have been generated from plain text containing only the uppercase characters and space.

Your program may not call figlet or its source code in any way.

Example

Input:

    _    ____   ____ ____  _____ _____ ____ _   _ ___ 
   / \  | __ ) / ___|  _ \| ____|  ___/ ___| | | |_ _|
  / _ \ |  _ \| |   | | | |  _| | |_ | |  _| |_| || | 
 / ___ \| |_) | |___| |_| | |___|  _|| |_| |  _  || | 
/_/   \_\____/ \____|____/|_____|_|   \____|_| |_|___|

     _ _  ___     __  __ _   _  ___  ____   ___  ____  
    | | |/ / |   |  \/  | \ | |/ _ \|  _ \ / _ \|  _ \ 
 _  | | ' /| |   | |\/| |  \| | | | | |_) | | | | |_) |
| |_| | . \| |___| |  | | |\  | |_| |  __/| |_| |  _ < 
 \___/|_|\_\_____|_|  |_|_| \_|\___/|_|    \__\_\_| \_\

 ____ _____ _   ___     ____        ____  ____   _______
/ ___|_   _| | | \ \   / /\ \      / /\ \/ /\ \ / /__  /
\___ \ | | | | | |\ \ / /  \ \ /\ / /  \  /  \ V /  / / 
 ___) || | | |_| | \ V /    \ V  V /   /  \   | |  / /_ 
|____/ |_|  \___/   \_/      \_/\_/   /_/\_\  |_| /____|

Output:

ABCDEFGHI
JKLMNOPQR
STUVWXYZ

Input:

 ____ _____  _    ____   __        ___    ____  ____  
/ ___|_   _|/ \  |  _ \  \ \      / / \  |  _ \/ ___| 
\___ \ | | / _ \ | |_) |  \ \ /\ / / _ \ | |_) \___ \ 
 ___) || |/ ___ \|  _ <    \ V  V / ___ \|  _ < ___) |
|____/ |_/_/   \_\_| \_\    \_/\_/_/   \_\_| \_\____/ 

Output:

STAR WARS

Note a previous edit of this question allowed inputs containing upper and lower case letters plus numerals. It was pointed out that this caused several points of ambiguity with certain adjacent character combinations. It became obvious that I needed to rigorously find a set of characters with no such collisions so that the contest is actually doable. At first I tried all lowercase letters plus numerals with this shell one-liner:

for t in {0..9}{a..z} {a..z}{a..z} {a..z}{0..9} {0..9}{0..9} ; do figlet $t | tr '\n' ':'; echo ; done | sort | uniq -d | tr ':' '\n'

This yielded {j1, jl} and {i1, il} as ambiguous pairs. So instead with all uppercase letters (as suggested by @AlexA.), there are no ambiguous pairs:

for t in {A-Z} ; do figlet $t | tr '\n' ':'; echo ; done | sort | uniq -d | tr ':' '\n'

Digital Trauma

Posted 2015-07-29T21:52:50.140

Reputation: 64 644

5I'd suggest a 'you may not call figlet' clause, because otherwise surely the shortest program will iterate over all possible strings, calling figlet on them, and then comparing for equality. – orlp – 2015-07-30T00:24:47.680

1The source code of figlet can be found in the following git repo: git://git.debian.org/git/collab-maint/figlet.git (download with git clone). – Doorknob – 2015-07-30T03:14:40.150

4Note: this challenge is very difficult to code, let alone code golf. – Lynn – 2015-07-30T09:27:44.747

41 and l are not identical, but V1 and Vl are. – Lynn – 2015-07-30T09:39:57.153

1Much more feasible! – Not that Charles – 2015-07-30T18:16:54.703

@AlexA. - done :) I think its cleaner now - deleting obsolete comments... – Digital Trauma – 2015-07-30T18:17:26.133

XOX and XDX are still really hard to discern... maybe that's a good kind of challenge, though? – Lynn – 2015-07-30T19:38:48.970

@Mauris hard, but not impossible :) – Digital Trauma – 2015-07-30T19:41:21.223

2

For people who do not have a system that can run figlet, there are various online versions. Search for "figlet online". For example, this one looks fairly straightforward and ad free: http://www.network-science.de/ascii/. Make sure that you choose the "standard" font.

– Reto Koradi – 2015-07-30T20:07:59.960

@RetoKoradi Thanks! I checked the output and with the standard font, it does seem to match. – Digital Trauma – 2015-07-30T20:15:36.317

Answers

3

CJam, 147 bytes, slightly broken

qN/6/{z{:i:+165%91%' +}%"e 3 VG rr A>Q V) rP r4 />/ F> [> C >> 9$ j8 fQrQ rG rN rD VV $>$ ;$ 859 98 ff = BB"S/eeWf%$W%{~@@/\a*}/{`''#},'@f+'@/S*N}%

It passes CODE GOLF and A-Z but not STAR WARS (which it reads as SAR WARS). I give up, but maybe someone is inspired.

Lynn

Posted 2015-07-29T21:52:50.140

Reputation: 55 648

1If your solution doesn't work, you probably shouldn't post it... – Alex A. – 2015-07-30T21:04:14.667