Overview
The cover of a book will be provided in the following ASCII format:
______
| |
| |
| |
| |
------
The input can be in any reasonable format (eg. a list of strings, a nested list of characters, etc.)
Inside the "borders" of the cover, other printable ascii characters might appear, which contribute to the "popularity index" (the definition of which has been completely made up for this challenge).
Popularity Index
Let the popularity index of a book be the number of unique characters that appear on the book cover (this does not include space characters or the edges of the cover). A book may have no unique characters on the cover (the cover is blank), in which case the popularity index is 0.
Examples
______
|\/ /|
|/\/ |
| /\/|
|/ /\|
------
Two unique characters (/
and \
) so the popularity index is 2.
______
| / /|
|/ / |
| / /|
|/ / |
------
One unique character (/
), so the popularity index is 1
______
| |
| |
| |
| |
------
No unique characters, the popularity index is 0
______
|\^$@|
|/\/ |
| 456|
|/ /\|
------
8 unique characters, so the popularity index is 8.
______
|\^$@|
|987 |
| 456|
|/hi!|
------
14 unique characters, so the popularity index is 14.
______
|////|
|////|
|////|
|////|
------
One unique character (/
), so the popularity index is 1.
Damaged Books
The edges of the book might also be damaged:
Top Left Right Bottom
_~____ ______ ______ ______
| | | | | | | |
| | | | | | | |
| | or { | or | } or | |
| | | | | | | |
------ ------ ------ ---~--
The book may have several of these "scratches". The scratches at the top and bottom will always be represented by a ~
, while the scratches on the left and right will always be represented by a {
and }
respectively. Each scratch will decrease the popularity index by 1.
As a result, it is possible for a book to have a negative popularity index.
Task
Given an ASCII representation of a book cover in the format described above, determine the "popularity index" of the book
Assumptions
You can assume that the characters
|
,_
, and-
will not appear elsewhere on the book cover (only on the edges). However, the scratch characters ({
,}
, and~
) may appear on the book cover in which case they should be treated as any other unique character on the cover.All characters appearing on the cover will be printable ascii
Note that spaces do not count as a unique character. As the examples above show, a "blank" cover is one that only contains spaces.
The book will always be the same size (height and width are fixed). Hence, the popularity index will never exceed 16.
Scoring
This is code-golf. Happy golfing!
More Examples
______
|{. }|
|/. /|
|/. /}
|/. /|
------
4 unique characters ({
, }
, .
and /
) and one scratch (}
on the right) so the popularity index is 3.
______
{ |
| .. |
| }
{ |
--~~--
One unique character (.
) and 5 scratches so the popularity index is -4.
Test Cases
______
| |
| |
| |
| |
------ -> 0
______
|\/ /|
|/\/ |
| /\/|
|/ /\|
------ -> 2
______
| / /|
|/ / |
| / /|
|/ / |
------ -> 1
______
|\^$@|
|/\/ |
| 456|
|/ /\|
------ -> 8
______
|!!!!|
|+ +|
| ** |
|<**>|
------ -> 5
______
|\^$@|
|987 |
| 456|
|/hi!|
------ -> 14
______
|THIS|
| is |
| a. |
|BOOK|
------ -> 11
______
|////|
|////|
|////|
|////|
------ -> 1
______
|abcd|
|efgh|
|ijkl|
|mnop|
------ -> 16
______
|{. }|
|/. /|
|/. /}
|/. /|
------ -> 3
______
{ |
| .. |
| }
{ |
--~~-- -> -4
~~~~~~
{ }
{ }
{ }
{ }
~~~~~~ -> -20
______
|~~~~|
|. |
{....}
|. |
------ -> 0
______
|{~~}|
| |
| |
| |
------ -> 3
__~~__
|{~~}|
| |
| |
{ |
-----~ -> -1