13
0
The Four color theorem States that no more than four colors are required to color the regions of a map.
The challenge
Given a list of State borders assign each state ID a color so that no two adjacent states have the same color. The output Should be a CSS stylesheet assigning the color to the state's 2 letter ID code. Here is a SVG map which the stylesheet could be applied to. http://upload.wikimedia.org/wikipedia/commons/3/32/Blank_US_Map.svg
The rules
- Shortest code wins
- any state border list can be used
- only 4 colors can be used.
- the state list can be hardcoded
Advice: Use the CSS fill: property to change the color, For example #AL{fill:green}
Here is a list of state borders
AL-FL
AL-GA
AL-MS
AL-TN
AR-LA
AR-MO
AR-MS
AR-OK
AR-TN
AR-TX
AZ-CA
AZ-CO
AZ-NM
AZ-NV
AZ-UT
CA-NV
CA-OR
CO-KS
CO-NE
CO-NM
CO-OK
CO-UT
CO-WY
CT-MA
CT-NY
CT-RI
DC-MD
DC-VA
DE-MD
DE-NJ
DE-PA
FL-GA
GA-NC
GA-SC
GA-TN
IA-MN
IA-MO
IA-NE
IA-SD
IA-WI
ID-MT
ID-NV
ID-OR
ID-UT
ID-WA
ID-WY
IL-IA
IL-IN
IL-KY
IL-MO
IL-WI
IN-KY
IN-MI
IN-OH
KS-MO
KS-NE
KS-OK
KY-MO
KY-OH
KY-TN
KY-VA
KY-WV
LA-MS
LA-TX
MA-NH
MA-NY
MA-RI
MA-VT
MD-PA
MD-VA
MD-WV
ME-NH
MI-OH
MI-WI
MN-ND
MN-SD
MN-WI
MO-NE
MO-OK
MO-TN
MS-TN
MT-ND
MT-SD
MT-WY
NC-SC
NC-TN
NC-VA
ND-SD
NE-SD
NE-WY
NH-VT
NJ-NY
NJ-PA
NM-OK
NM-TX
NM-UT
NV-OR
NV-UT
NY-PA
NY-VT
OH-PA
OH-WV
OK-TX
OR-WA
PA-WV
SD-WY
TN-VA
UT-WY
VA-WV
Can we hardcode the list of state borders? – NinjaBearMonkey – 2014-10-25T22:59:44.580
@hsl yes, it is ok to hardcode state borders. – kyle k – 2014-10-26T03:26:25.317
@steveverrill if you can think of a better method of changing colors that would be great. I added an example showing how to use CSS. – kyle k – 2014-10-26T03:37:29.913
Wouldn't this require reproducing the proof the Four Color Theorem itself? Since you have to handle every possible case? – barrycarter – 2014-10-26T05:19:27.777
1Wouldn't this Theorem prove wrong if a state's border is touching more than 3 other states ? – Optimizer – 2014-10-26T06:11:24.913
My mathematical pedantry forces me to point out that your explanation of the 4 colour theorem isn't right, one colour is enough if you don't put constrains on the colouring! – None – 2014-10-26T06:51:32.177
Oh wow, I was just thinking of this as a challenge! – Beta Decay – 2014-10-26T07:43:22.723
Ok the CSS is clear, you have my upvote now. I deleted my previous comment about hardcoding as it wasnt your intention. I guess you mean that if it's read in the state data doesn't count in your byte count but if it's hardcoded it does? Allowing hardcoding data on problems like this is a slippery slope towards hardcoding solutions. Anyway, the existing answer uses 60 bytes to parse the data, while hardcoded data would need 6 bits for each of the 109 borders just to hold a numeric value for one state (without even considering the other state or the letter codes) so I don't think its worth it. – Level River St – 2014-10-26T09:06:56.313
@Optimizer TN borders 7 other states and yet the US can still be 4-colored. Just because two states border TN doesn't mean they border each other. – barrycarter – 2014-10-26T17:21:46.183