Prior to the discovery of fingerprints and DNA testing, the British police used an anthropometric system to identify repeat offenders. Certain parts of the bodies of criminals were measured and stored in records -- these parts of the body were assumed to not change in size after adulthood. This system was known as bertillonnage.
The diagram below shows a filing system used by the police to access these records quickly.
Diagram 1: A filing system with numbered drawers.
Note: if you cannot see the image, try the imgur mirror or compile it yourself.
The filing cabinet consists of 81 numbered drawers. Each drawer contains cards, and each card has measurements of particular parts of a criminal's body:
- The length of their head (
H
) - The breadth of their head (
B
) - The width of their right ear (
E
) - The length of their index finger (
F
)
Each measurement is classified as either small, medium or large.
For example, drawer 56 contains cards with the following characteristics: small H, large B, medium E, and small F. This can be notated using the letters S
, M
, and L
in place of small, medium, and large:
SH,LB,ME,SF
Note that the size letter goes first, then what the measurement is. In addition, an exclamation point !
may be placed in front to cause a negative:
!SH,LB,!ME,SF
This indicates cards that have the following characteristics: not small H, large B, not medium E, and small F. There are four drawers that contain cards with these characteristics -- 58, 60, 61, and 63.
Your task is to write a program, that, when given a string notating some characteristics, outputs all of the drawers that contain cards with those characteristics. If there are no drawers that contain cards with the given characteristics, output 0
.
Here are some sample inputs and outputs.
- Input:
SH,LB,ME,SF
Output:56
- Input:
!SH,LB,!ME,SF
Output:58,60,61,63
- Input:
SB,!MF,!LF
Output:1,2,3,4,5,6,7,8,9
- Input:
MH,!MH
Output:0
This is code golf, so the shortest entry wins. Ask questions in the comments if the specification is not clear.