This is a byte sized challenge where you have to convert an input temperature in one of the three units (Celsius, Kelvin and Fahrenheit) to the other two.
Input
You would be provided with a temperature as a number followed by a unit (separated by space). The temperature can be an integer or a floating point number (23 vs 23.0 or 23.678).
You can submit a function or a full program that reads the space separated string from STDIN/ARGV/function argument or the closest equivalent and prints the output to STDOUT or closest equivalent.
Output
Your output should be the temperature converted to the other two formats, separated by a newline and followed by the corresponding unit character on each line (optionally separated by a space). The order of the two units does not matter.
Output precision
- The converted number should be accurate to at least 4 decimal places without rounding.
- Trailing zeroes or decimal places are optional as long as first 4 decimal places (without rounding) are precise. You can also skip the 4 zeroes and/or the decimal point in case the actual answer has 4 zeroes after the decimal point.
- There should not be any leading zeroes
- Any number format is acceptable as long as it fulfills the above three requirements.
Unit representation
Unit of temperature can only be one of the following:
C
for CelsiusK
for KelvinF
for Fahrenheit
Examples
Input:
23 C
Output:
73.4 F
296.15 K
Input:
86.987 F
Output:
303.6983 K
30.5483 C
Input:
56.99999999 K
Output:
-216.1500 C
-357.0700 F
This is code-golf so shortest entry in bytes wins! Happy Golfing!
Leaderboard
<script>site = 'meta.codegolf',postID = 5314,isAnswer = true,QUESTION_ID = 50740</script><script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)<\\/code><\/pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>
23C\n73.4F\n296.15K
? or must the input format be supressed? \$\endgroup\$ – Level River St May 25 '15 at 13:482/3
=>0.666666666666
is accurate to the 4th digits? (I'd say YES). Or should it be0.6667
? \$\endgroup\$ – edc65 May 25 '15 at 13:520.666666666666
is correct. I am enforcing a no-rounding based precision. so0.6666
is the alternative. \$\endgroup\$ – Optimizer May 25 '15 at 13:54