13
So in 1st grade math, you learn the names of polygons. Three sides is a triangle, 4 is a square, and 5 is a pentagon. However, in 1st grade honors, you go a bit further.
Your challenge
There is a naming system for polygons above a few sides, so arbitrarily large polygons have a name.
Your task is to write a program or a function that accepts the name of a polygon as input and outputs the number of sides it has.
The names of polygons are defined as in the left column of this wikipedia article with a few exceptions.
Three sided polygons will be called a triangle instead of a trigon and 4 sided polygons will be a square instead of a tetragon (assume that all the polygons are regular). Otherwise, the names in the article will be used.
Rules
- Input will be a string value.
- The program should print the result to STDOUT (or it should return an integer).
- Only polygons between 3 and 99 will be inputted.
- Your program must satisfy all test cases.
- No standard loopholes.
- The program doesn't need to do anything for invalid/out of range inputs.
- Scoring is in bytes. Since this is code-golf, shortest program wins.
Test cases
3 triangle
4 square
5 pentagon
10 decagon
11 hendecagon
12 dodecagon
13 triskaidecagon
20 icosagon
21 icosikaihenagon
22 icosikaidigon
34 triacontakaitetragon
35 triacontakaipentagon
36 triacontakaihexagon
47 tetracontakaiheptagon
48 tetracontakaioctagon
49 tetracontakaienneagon
64 hexacontakaitetragon
80 octacontagon
81 octacontakaihenagon
99 enneacontakaienneagon
Leaderboards
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
var QUESTION_ID=75229,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<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="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><div id="language-list"> <h2>Winners 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><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>
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 leaderboard snippet:
# [><>](http://esolangs.org/wiki/Fish), 121 bytes
10Related – FryAmTheEggman – 2016-03-09T21:45:33.130
1Not all tetragons are squares. – Dennis – 2016-03-10T00:39:39.670
@Dennis But all regular tetragons are. – Daniel M. – 2016-03-10T00:41:04.953
Note that the question that FryAmTheEggman points out goes in the opposite direction: This question goes from name to number of sides, while the prior one goes from number of sides to name. – isaacg – 2016-03-10T08:42:41.473
Close-voters: These questions are not the same. – Daniel M. – 2016-03-10T11:17:17.963
@DanielM. They may not be the same, but to me, simply reversing the task doesn't sufficiently differentiate it. – Mego – 2016-03-11T03:59:45.510
What was wrong with quadrilateral? – Neil – 2016-03-12T14:52:33.203
@Neil When you see "Triangle, __________, Pentagon, Hexagon", what's the first word that comes to mind? – Daniel M. – 2016-03-12T14:54:53.800
I'm pretty sure it was quadrilateral, otherwise I wouldn't have bothered mentioning it. – Neil – 2016-03-12T15:11:39.387
@Neil Maybe, but there are already answers, so it wouldn't be fair to change it now – Daniel M. – 2016-03-12T15:16:10.483
Now that I look at the answers, I see they look for the
q
anyway, so they'd probably accept quadrilateral. – Neil – 2016-03-12T15:24:03.540You know, a lot of these answers don't accept any names not shown in the test cases (for instance, the Cinnamon Gum answer does not accept nonagon as a valid input). Is that okay? – R. Kap – 2016-04-03T18:29:13.313
@R.Kap Catering to the test cases is a standard loophole, so they should be able to accept them all. – Daniel M. – 2016-04-03T19:21:41.307
@DanielM. Well then , since most of the current answers don't accept all shape names with sides from 0-99, they are invalid candidates. – R. Kap – 2016-04-03T20:52:05.883
@R.Kap Looking at the Wikipedia article, ennagon is the correct thing, and it wouldn't be good to change the challenge after there are answers. – Daniel M. – 2016-04-03T20:54:41.277
Wow, never heard of an enneagon before. I had always thought a nine-sided polygon is a nonagon, but apparently that's not the only possible name for it. Well, you live and you learn. – R. Kap – 2016-04-03T21:00:11.697