43
6
The aim of this task is to identify, clean up, and mark out all the faces in any given 'image'.
What's in a face?
A face will be a ZxZ square where Z is an odd integer greater than 1. The top left and right corners and the centre will be 'O' characters, and the bottom line will be a '\' and a '/' surrounding enough '_' characters to fill the rest of the line. Examples:
a 3x3 face:
O O
O
\_/
a 5x5 face:
O O
O
\___/
a 7x7 face:
O O
O
\_____/
etc.
Input
Input will be on STDIN and will consist of a number of equal length strings of characters.
Output
Output should be the input with all recognizable faces cleared (i.e. all characters except the eyes, nose and mouth shoud be removed from within the face's bounds) and boxed (surrounded by +, -, and | characters). Where two or more faces overlap both should be cleared and boxed but priority should be given to the larger face (it should be placed on top); if both faces are the same size, the priority is left to the discretion of the implementer. If the input has no faces, output should be the same as input.
Some examples
Input:
*******
*******
**O*O**
***O***
**\_/**
*******
*******
Output:
*******
*+---+*
*|O O|*
*| O |*
*|\_/|*
*+---+*
*******
Input (incomplete face):
*******
*******
**O*O**
*******
**\_/**
*******
*******
Output:
*******
*******
**O*O**
*******
**\_/**
*******
*******
Input (nested faces):
*******
*O***O*
**O*O**
***O***
**\_/**
*\___/*
*******
Output:
+-----+
|O O|
| |
| O |
| |
|\___/|
+-----+
Input (multiple faces):
~{$FJ*TBNFU*YBVEXGY%
FOCO$&N|>ZX}X_PZ<>}+
X$OOPN ^%£)LBU{JJKY%
@\_/$£!SXJ*)KM>>?VKH
SDY%£ILO(+{O:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJO$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@\___/GER%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
+---+*TBNFU*YBVEXGY%
|O O|&N|>ZX}X_PZ<>}+
| O |N ^%£)LBU{JJKY%
|\_/|£+-----+M>>?VKH
+---+I|O O|HO(UR$W
XVBFTE| |LO*(&P:
>?LKPO| O |&L:}~{&
~@?}{)| |@~}P>OU
:@<L::|\___/|ER%^*BI
@{PO{_+-----+YT*&G&^
Input (near boundary):
~{$FJ*TBNFU*YBVEXGY%
OCO$&N|>ZX}X_PZ<>}+^
$OOPN ^%£)LBU{JJKY%{
\_/$£!SXJ*)KM>>?VKHU
SDY%£ILO(+{8:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJ^$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@BJYT*GER%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
---+J*TBNFU*YBVEXGY%
O O|&N|>ZX}X_PZ<>}+^
O |N ^%£)LBU{JJKY%{
\_/|£!SXJ*)KM>>?VKHU
---+£ILO(+{8:HO(UR$W
XVBFTER^&INLNLO*(&P:
>?LKPO)UJ^$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@BJYT*GER%^*BI
@{PO{_):<>KNUYT*&G&^
Input (overlapping faces):
~{$FJ*TBNFU*YBVEXGY%
FXC£$&N|>ZX}X_PZ<>}+
X$*OPN O%£)LBO{JJKY%
@:U%$£!SXJ*)KM>>?VKH
SDY%£OLO(+{P:HO(UR$W
XVBFTER^&IOLNLO*(&P:
>?L\___/JR$£^&L:}~{&
~@?}{)JKOINLM@~}P>OU
:@<L::@\_____/R%^*BI
@{PO{_):<>KNUYT*&G&^
Output:
~{$FJ*TBNFU*YBVEXGY%
FX+---+-------+Z<>}+
X$|O |O O|JJKY%
@:| | |>?VKH
SD| O| |(UR$W
XV| | O |*(&P:
>?|\__| |:}~{&
~@+---| |}P>OU
:@<L::|\_____/|%^*BI
@{PO{_+-------+*&G&^
I find the 3x3 face realistic and the 7x7 face derp. Just my opinion. Sad that I haven't got time to gain bountiez... :) – tomsmeding – 2014-03-23T21:36:15.970
2@tomsmeding If you find the 3x3 face realistic I'd hate to see the people you associate with. :-\ – Gareth – 2014-03-23T21:45:20.120
I say "realistic" relative to the realisticness of the 5x5 and the 7x7 faces. Lol though. – tomsmeding – 2014-03-24T06:16:53.337
What about conjoined faces (e.g. where an O doubles as a left eye and right eye)? Should those be treated as overlapping? – Joey Adams – 2011-07-08T21:01:06.913
@Joey Adams: that happens in the last example. – Lowjacker – 2011-07-08T21:44:50.967
@Joey Adams @Lowjacker Yes, just like the last example. – Gareth – 2011-07-08T22:28:35.157