Mirror, Mirror, on the wall. Who's the fairest of them all?

-1

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

  • If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
  • If #000000 appears in the input, return "Saved by Grumpy"
  • If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
  • If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
  • If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
  • If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
  • If #54C563 or #555555 appears in the input, return "Saved by Dopey"
  • If #65B9AA or #666666 appears in the input, return "Saved by Doc"
  • If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
  • If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
  • If an F variant appears in the input, return "Press F to pay respects to Snow White"
    • An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
  • If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

  • If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
    • Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
    • Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!

Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
2FE84E Return of the Jedi

Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
7217F8 Return of the King

Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal

Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110

We take the reflection from the mirror, getting:

011100100001011111110100

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000

We take the reflection from the mirror, getting:

000111111110100001001110

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111

We take the reflection from the mirror, getting:

1111010011001100101111

We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

Rules:

  • No standard loopholes
  • Input/output taken via standard input/output methods.
  • The output must be exactly equal to the "fairest" answer

Scoring:

This is code golf, so shortest program wins.

Here's the sandbox link

Avi

Posted 2019-10-18T18:45:04.377

Reputation: 279

4I'll be honest, 3 downvotes without any explanation whatsoever is a real downer. I left this in the sandbox for two weeks so that people could give feedback and spent hours clarifying the examples. If you didn't do your job of giving feedback, how am I supposed to improve my question? – Avi – 2019-10-18T21:00:21.080

2

I was not aware that it was my personal "job" to go through every single sandbox post in existence, but okay. There's a chat; I usually go to it to get feedback, because with no positive or negative feedback, it's really a toss-up how main reception will go, and I'm slightly more experienced so I can usually gauge how my challenges will go, but even then, I still go to chat for final feedback before posting.

– HyperNeutrino – 2019-10-18T22:13:03.897

5I didn't downvote, but my eyes glaze over looking at this challenge and I can't motivate myself to read it. It's not just that it's long, but that by the time I'm hit with a bunch of specifics, I don't really know what the overall idea is or why this would be interesting to golf. And my initial impression is that I wouldn't enjoy coding or golfing it because I'd need to implement a long, rigid algorithm with finicky details that requires encoding a big lookup table. – xnor – 2019-10-18T22:29:31.827

Shouldn't #A98AC7 be #01B207 so that it's consistent with the other patterns? Or did you change it on purpose? – Arnauld – 2019-10-18T22:48:34.260

@Arnauld In decimal, #A98AC7 is 11111111 – Avi – 2019-10-18T23:41:59.717

@Avi That's my point. We have 8 1's here, while the other values expends to 7 repeated digits in base 10. Just wanted to be sure that was on purpose. – Arnauld – 2019-10-18T23:45:16.190

@Arnauld I started with 8 1's and then brought it down to 7 digits for everything else, because they were too large to fit in 6 hex digits. The idea was the "max" of a digit repeated, converted to hex, as well as that digit 6 times in hex itself. – Avi – 2019-10-18T23:46:23.847

Answers

3

C# (Visual C# Interactive Compiler), 557 bytes

a=>b=>{var k=a.Select(l=>l==0xFF0800?"Return to Sleeping Death":$"{l:X}".All(x=>x>69|x<49)?"Press F to pay respects to Snow White":"Saved by "+"Grumpy,Happy,Sleepy,Bashful,Sneezy,Dopey,Doc,the Seven Dwarfs,Love's first kiss,	".Split(',')[l==0xFFFAFA?8:l==11111111?0:l%1118481<1?l/1118481:l%1111111<1?l/1111111:9]);int j=a.Last(),i=0,e=24;for(;e-->0;i|=j%2,j>>=1)i*=2;var m=k.Where(o=>o[9]!=9);var t=a.SkipLast(1).Select(o=>Convert.ToString(o^i,2).Sum(y=>y-48)).ToList();return(m.Any()?m:m=b.SkipLast(1).Where((x,y)=>t.Min()==t[y])).ToList()[~-m.Count()/2];}

Try it online!

Embodiment of Ignorance

Posted 2019-10-18T18:45:04.377

Reputation: 7 014

2

JavaScript (Node.js), 433 bytes

Takes input as a list of tuples [color, string].

a=>(h=a=>a[a.length-1>>1])(a.flatMap(([c])=>(s=c-0xFFFAFA?"Grumpy/Happy/Sleepy/Bashful/Sneezy/Dopey/Doc/the Seven Dwarfs".split`/`[(d=c-11111111?c/1118481:1)%1?c/1111111:d]:"Love's first kiss")?"Saved by "+s:c-0xFF0800?(g=n=>n?n%16%15||g(n>>4):0)(C=c)?[]:"Press F to pay respects to Snow White":"Return to Sleeping Death"))||h(a.map(m=([c,s])=>[(d=g(c,i=24))>m?d:m=d,s],a.pop(g=n=>i--&&(n^C>>i)%2+g(n/2))).flatMap(([d,s])=>d-m?[]:s))

Try it online!

Arnauld

Posted 2019-10-18T18:45:04.377

Reputation: 111 334

Very impressive - I especially liked the computation for correct hex indices :) – Avi – 2019-10-19T03:14:13.553