16
5
New Bonus! (See below)
The cartography team of U.S. Republican presidential hopeful Ben Carson is having some trouble with their maps (image via Washington Post):
The problem is they don't have the Right Tool For The Job™. They need the most compact and reliable program possible, so they never have to worry about making maps again. That's why they hired you. You need to take this map and output it again with the desired coloring:
By Theshibboleth [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/)], via Wikimedia Commons
If you don't know where all the states are (because you are not an American...or you are an American), here is a map with all the names (Washington D.C. is not required for this challenge):
"Map of USA with state names 2". Licensed under CC BY-SA 3.0 via Wikimedia Commons - https://commons.wikimedia.org/wiki/File:Map_of_USA_with_state_names_2.svg#/media/File:Map_of_USA_with_state_names_2.svg
For example if the input is Ohio, Indiana, Illinois;New York, New Jersey, Florida
, you output:
The blank map image is available in SVG and PNG formats. For your convenience, here is a list of all 50 states in alphabetical order
This is a code-golf and graphical-output challenge. Output must be as a SVG or image file. Simply displaying the output on the screen is not enough. Input must be taken from STDIN or by reading a text file. I am flexible with how you format the input, although it should contain the full names of each state, with red (Republican) states listed first and blue (Democratic) states second. Any two distinct shades of red and blue are acceptable for the coloring. Of course, you can have the blank map image in the same folder as your program with whatever file name you want.
Accuracy Criteria
If your output is a raster file, it must be at least 800px by 495px, and the lines should not deviate from the result of scaling up the SVG to the same size by more than 1.5 pixels. If your output is a vector file, the lines should not deviate from the SVG by more than 1.5 pixels when both are scaled to 800px by 495px.
Bonus!
Ben is trying to cut down dependence on foreign libraries, and is now offering a -50% bonus to anyone who uses only a raster graphics version of the map as input and creates their own algorithm for region detection. Ultimately, it is my judgment that determines whether your approach counts as "writing your own" algorithm.
Good Luck!
the example shows some aliasing around the lines that hasn't been filled in. is that acceptable? – Sparr – 2015-11-19T17:25:49.897
@Sparr I made the example with an image editor, so I consider it to be "perfect", so if you miss anything that it misses it's alright. – geokavel – 2015-11-19T17:49:11.103
Just to be sure: are we allowed to modified the blank SVG file? Does its size count in our score? What do you mean by "simply displaying the output on the screen is not enough"? – Blackhole – 2015-11-19T20:55:06.373
@Blackhole No, you can't modify the blank SVG file, but it doesn't count as part of your score as long as you load it externally. – geokavel – 2015-11-19T21:32:25.053
@Blackhole What I mean is, you have to output a file. – geokavel – 2015-11-19T21:32:56.443
When you say "I am flexible with how you format the input", does that mean that a really strange formatting like
Ohio0Indiana0Illinois1New York0New Jersey0Florida
is allowed? – Blackhole – 2015-11-19T22:16:17.013@Blackhole Yeah, I am ok with that. – geokavel – 2015-11-19T22:22:02.680
how flexible? can my input just be a list of 50 ternary digits, in a specific order (alphabetical states, perhaps)? – Sparr – 2015-11-21T18:38:26.360
@Sparr "I am flexible with how you format the input, although it should contain the full names of each state." It has to be human-readable names of each state, and it has to work even if they're not in alphabetical order. – geokavel – 2015-11-21T18:42:42.200
For the record, a semi-related xkcd exists.
– Joe – 2016-09-04T02:46:48.150