23
0
Given a string as input, output the US state whose capital it is if it is a state capital, the capital of the state if it is a state, or Arstotzka
if it is neither.
Examples:
Austin -> Texas
Alaska -> Juneau
The Nineteenth Byte -> Arstotzka
All the capitals and their respective states:
Baton Rouge, Louisiana
Indianapolis, Indiana
Columbus, Ohio
Montgomery, Alabama
Helena, Montana
Denver, Colorado
Boise, Idaho
Austin, Texas
Boston, Massachusetts
Albany, New York
Tallahassee, Florida
Santa Fe, New Mexico
Nashville, Tennessee
Trenton, New Jersey
Jefferson, Missouri
Richmond, Virginia
Pierre, South Dakota
Harrisburg, Pennsylvania
Augusta, Maine
Providence, Rhode Island
Dover, Delaware
Concord, New Hampshire
Montpelier, Vermont
Hartford, Connecticut
Topeka, Kansas
Saint Paul, Minnesota
Juneau, Alaska
Lincoln, Nebraska
Raleigh, North Carolina
Madison, Wisconsin
Olympia, Washington
Phoenix, Arizona
Lansing, Michigan
Honolulu, Hawaii
Jackson, Mississippi
Springfield, Illinois
Columbia, South Carolina
Annapolis, Maryland
Cheyenne, Wyoming
Salt Lake City, Utah
Atlanta, Georgia
Bismarck, North Dakota
Frankfort, Kentucky
Salem, Oregon
Little Rock, Arkansas
Des Moines, Iowa
Sacramento, California
Oklahoma City, Oklahoma
Charleston, West Virginia
Carson City, Nevada
Rules
- No built-ins or libraries/modules that provide a mapping from states to capitals or capitals to states, or lists of capitals and/or states (for example, Mathematica's
CityData
built-in) - Standard loopholes apply
- This is code-golf, so shortest answer in bytes wins!
Leaderboard
The Stack Snippet at the bottom of this post generates the leaderboard from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
## Language Name, N bytes
where N
is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
## Ruby, <s>104</s> <s>101</s> 96 bytes
If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:
## Perl, 43 + 2 (-p flag) = 45 bytes
You can also make the language name a link which will then show up in the snippet:
## [><>](http://esolangs.org/wiki/Fish), 121 bytes
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 64254; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 45941; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>
4Related – Sp3000 – 2015-11-19T00:01:28.273
4Please provide a full list of states and their capitals in their proper spelling in plain text. – orlp – 2015-11-19T00:05:14.577
any specification about case? also, should "United States" return "Washington, D.C"? – cat – 2015-11-19T00:10:50.697
if the input is Arstotzka, should it be treated like any other junk input? – cat – 2015-11-19T00:11:59.847
2@sysreq The spelling and case must exactly match the list provided. As "United States" is neither a US state nor a US state capital, it should return "Arstotzka". – Mego – 2015-11-19T00:12:15.893
1@sysreq "Arstotzka" is neither a US state nor a US state capital, so it should return "Arstotzka". – Mego – 2015-11-19T00:14:04.727
Would you consider allowing us to subtract the length of the dictionary (in whichever format we choose to encode it) from our score? That seems to happen a lot in kolmogorov-complexity challenges... – cat – 2015-11-19T01:20:24.650
6@sysreq That doesn't sound like a very good idea to me. – SuperJedi224 – 2015-11-19T01:32:33.910
Waiting for a mathematica builtin answer – Faraz Masroor – 2015-11-19T02:04:04.763
4@FarazMasroor Builtins are banned – a spaghetto – 2015-11-19T02:51:52.410
1Your example outputs "Anchorage" for Alaska, but the capital is Juneau. You should probably fix that. – Darrel Hoffman – 2015-11-19T16:01:45.020
2@DarrelHoffman Thanks, that one slipped by me. I blame Fallout. – Mego – 2015-11-19T16:03:46.530
1Too late now, I guess, since it would invalidate existing answers, but the capital of Missouri is Jefferson City, not Jefferson. – msh210 – 2015-11-19T19:05:37.570
1@msh210 - I believe that list comes from the Animaniacs song? (Based on the somewhat random order) They probably shortened it to fit the meter. A small error on their part I suppose; certainly it's more accurate than the countries of the world song... – Darrel Hoffman – 2015-11-19T21:08:31.007
@msh210 I pulled the list from this related question. Blame Timmy.
– Mego – 2015-11-20T01:57:35.463Out of curiosity, why Arstotzka? – caird coinheringaahing – 2017-11-04T19:17:17.153
1
@cairdcoinheringaahing https://en.wikipedia.org/wiki/Papers,_Please
– Mego – 2017-11-04T20:26:49.357