24
7
Introduction
Everyone's heard of sine (sin), cosine (cos), tangent (tan), cotangent (cot), secant (sec), and cosecant (csc). Nearly every angle has them.
Far less known, or remembered, are the exsecant (exsec), excosecant (excsc), versine (versin), and coversine (cvs). Nearly every angle has those as well. There are some that are even less known, but we'll just stick to these.
I've created a visualization of these for angle θ, which is 45°.
The Challenge
Create a program that takes an input of an angle n
, in degrees, and will output:
the sine of angle
n
the cosine of angle
n
the tangent of angle
n
the secant of angle
n
at least one of the following. Every additional item from this list will earn a bonus -5%, for a maximum of -25%.
exsecant of angle
n
cosecant of angle
n
excosecant of angle
n
versine of angle
n
coversine of angle
n
cotangent of angle
n
If your score is a decimal after applying a bonus, round up to the nearest whole number.
Input
You may accept your input through STDIN or through a function call. A single argument, n
, will be passed.
n
will always be a whole integer that is greater than 0, but less than or equal to 90.
Output
Here is an example of the output for sine of 45°. All output items must be in this format. The order of the items does not matter.
sine: 0.70710678118
All items must have exactly 4 numbers after the decimal (precision to the ten-thousandths). Below are a few examples of rounding.
0 -> 0.0000
1 -> 1.0000
0.2588190451 -> 0.2588
5.67128181962 -> 5.6713
10 -> 10.0000
12.4661204396 -> 12.4661
Any nonexistent/undefined results should default to 0.
Example
myprogram(60)
sine: 0.8660
cosine: 0.5000
tangent: 1.7321
secant: 2.0000
exsecant: 1.0000
cosecant: 1.1547
excosecant: 0.1547
versine: 0.5000
coversine: 0.1340
cotangent: 0.5774
Scoreboard
For your score to appear on the board, it should be in this format:
# Language, Score
Or if you earned a bonus:
# Language, Score (Bytes - Bonus%)
Strikethroughs shouldn't cause a problem.
function getURL(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 getAnswers(){$.ajax({url:getURL(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){var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),useData(answers)}})}function getOwnerName(e){return e.owner.display_name}function useData(e){var s=[];e.forEach(function(e){var a=e.body.replace(/<s>.*<\/s>/,"").replace(/<strike>.*<\/strike>/,"");console.log(a),VALID_HEAD.test(a)&&s.push({user:getOwnerName(e),language:a.match(VALID_HEAD)[1],score:+a.match(VALID_HEAD)[2],link:e.share_link})}),s.sort(function(e,s){var a=e.score,r=s.score;return a-r}),s.forEach(function(e,s){var a=$("#score-template").html();a=a.replace("{{RANK}}",s+1+"").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SCORE}}",e.score),a=$(a),$("#scores").append(a)})}var QUESTION_ID=58283,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],answer_ids,answers_hash,answer_page=1;getAnswers();var VALID_HEAD=/<h\d>([^\n,]*)[, ]*(\d+).*<\/h\d>/;
body{text-align:left!important}table thead{font-weight:700}table td{padding:10px 0 0 30px}#scores-cont{padding:10px;width:600px}#scores tr td:first-of-type{padding-left:0}
<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="scores-cont"><h2>Scores</h2><table class="score-table"><thead> <tr><td></td><td>User</td><td>Language</td><td>Score</td></tr></thead> <tbody id="scores"></tbody></table></div><table style="display: none"> <tbody id="score-template"><tr><td>{{RANK}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SCORE}}</td></tr></tbody></table>
Does the order of the output matter? – Jakube – 2015-09-19T09:07:46.313
12Pedantry ahead: "Every angle has them" - not true; odd multiples of 90 degrees don't have a tangent, for example. (It seems extremely bizarre to me that you require nonexisting values to give an output of zero. Would you really use a program that deliberately gave such misleading answers?) Also, I'd be interested to know why you regard the cosecant and cotangent as being more obscure than the secant; in my A-level maths classes we learned about those three at the same time. – Hammerite – 2015-09-19T10:54:08.267
Is capitalization fixed lowercase? I'd like output 'Sine, Cosine ...' – edc65 – 2015-09-19T14:05:47.063
Hard to understand Full program vs input through a function call – edc65 – 2015-09-19T14:09:52.443
1Is the angle input really
greater than 0
, so 0 is not allowed? – edc65 – 2015-09-19T14:37:46.237I am probably misreading, but I need some clarifications. As you say
a program than can output ...
, that means that I may or may not print those items. All I need to print is one of theat least
at point 5. If I'm wrong, please clarify... – edc65 – 2015-09-19T15:07:24.203I've modified the question. To answer your question, you must output sine, cosine, tangent, secant, and at least one item from the list at #5. Every additional item from the list at #5 constitutes a bonus -5%. @edc65 – Zach Gates – 2015-09-19T15:14:59.707
I'm assuming builtins are allowed? – ASCIIThenANSI – 2015-09-22T19:28:21.457
Yes they are. @ASCIIThenANSI – Zach Gates – 2015-09-22T19:34:44.873
It looks like there are a lot of answers who do not convert to radians (input is supposed to be in degrees, right?) or handle the 90° case as prescribed (I cannot say I agree with returning 0, but still). – xebtl – 2015-09-23T05:59:31.680