23
1
Do you remember my mat properly grouped by colors?
Yesterday I was looking at it and realized that some letters fit inside others. Example: a letter P
fits in the place where the letter R
goes. So here's a simple challenge: given two letters, return a truthy value if any one of the letters fits inside the other (directly or rotated, but not flipped), or a falsey value if they don't. That is, if the input is [P,R]
or [R,P]
, you must return truthy because in both cases one letter fits inside the other. If you get [L,U]
you must return falsey as neither fit inside the other.
Rules
- The input must be two alphanumeric characters in the range [0-9A-Z], as there are also numbers in the mat, in any form you need (two separate chars as two inputs, a list with two chars, a string with the 2 chars, whatever).
- The output must be consistent (the truthy and falsey values must be always the same).
Following is the table of fittings (note that a letter always fits in its proper place, just in case you get something like
[Y,Y]
as input):char fits inside chars -------------------------------------------------------- C G,O F B,E,P,R G O I 0,1,7,B,D,E,F,H,K,L,M,N,O,P,R,T,V,W,X,Z L E M W P R S O V A W M 0 O 1 B,E,L 3 O 6 9,O 8 O 9 6,O
I solemnly swear that I have tested every fitting in my kid's mat. (Dries his sweat from his forehead.)
This is code-golf, so may the shortest code for each language win!
Some test cases
input output
-------------
[C,G] truthy (C fits inside G)
[G,C] truthy (C fits inside G)
[F,R] truthy (F fits inside R)
[M,W] truthy (both fit inside the other)
[O,S] truthy (S fits inside O)
[T,T] truthy (T fits in its place)
[E,V] falsey (no fit found)
[P,L] falsey
Sandbox post. Please, forgive me if you spot more fittings that I missed. Many thanks to Οurous for helping me with the fittings list.
1[tag:kolmogorov-complexity]. – user202729 – 2017-12-20T08:23:01.850
1
1
doesn't fit inF
? – user202729 – 2017-12-20T08:44:08.293@user202729 no, because you need to flip the
1
to fit it in theF
but that's not allowed in my mat. :-) – Charlie – 2017-12-20T08:48:05.617Ah, it's rotation. – Khuldraeseth na'Barya – 2017-12-20T08:51:42.547
4Illustration ASCII-art graph (of course fit-in is transitive) – user202729 – 2017-12-20T08:58:45.500
@Rod yes, and the result would be truthy as a letter always fits in its proper place. I have edited the question. – Charlie – 2017-12-20T10:03:08.280
i think we'd all really appreciate test cases :p – Brian H. – 2017-12-20T11:13:10.527
@BrianH. sorry for that, I added some test cases. Feel free to ask for more. – Charlie – 2017-12-20T11:34:55.760
Do C and O not fit inside Q in your font? – Zgarb – 2017-12-20T11:53:31.733
@Zgarb probably. I completely forgot about the
Q
, but I cannot change the challenge now. – Charlie – 2017-12-20T11:55:29.663@Charlie Only two answers so far, wouldn't be too much disruption? – Οurous – 2017-12-20T11:59:54.873
1
@Οurous it was in this other question when it already had two answers... Besides, the challenge already has many cases to test, more cases won't add anything to it (I think the most creative part is that the two inputs are interchangeable as you have to check both fittings).
– Charlie – 2017-12-20T12:04:26.277Why does
I
fit inside0
? – DonielF – 2018-01-02T15:21:21.527