20
\$\begingroup\$

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'
\$\endgroup\$
  • 5
    \$\begingroup\$ I'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. \$\endgroup\$ – orlp Jul 30 '15 at 0:24
  • 1
    \$\begingroup\$ The 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). \$\endgroup\$ – Doorknob Jul 30 '15 at 3:14
  • 4
    \$\begingroup\$ Note: this challenge is very difficult to code, let alone code golf. \$\endgroup\$ – Lynn Jul 30 '15 at 9:27
  • 4
    \$\begingroup\$ 1 and l are not identical, but V1 and Vl are. \$\endgroup\$ – Lynn Jul 30 '15 at 9:39
  • 2
    \$\begingroup\$ 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: network-science.de/ascii. Make sure that you choose the "standard" font. \$\endgroup\$ – Reto Koradi Jul 30 '15 at 20:07
3
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ If your solution doesn't work, you probably shouldn't post it... \$\endgroup\$ – Alex A. Jul 30 '15 at 21:04

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.