273.org 1.5 KB

Converting degrees

  • Input Description

You will be given two lines of text as input. On the first line, you will receive a number followed by two letters, the first representing the unit that the number is currently in, the second representing the unit it needs to be converted to.

    Examples of valid units are: d for degrees of a circle r for radians
  • Output Description

You must output the given input value, in the unit specified. It must be followed by the unit letter. You may round to a whole number, or to a few decimal places. Challenge Input

    3.1416rd 90dr
  • Challenge Output
  • 180d 1.57r
  • Bonus

Also support these units:

c for Celsius f for Fahrenheit k for Kelvin

    If the two units given are incompatible, give an error message as output.
  • Bonus Input
    212fc 70cf 100cr 315.15kc
  • Bonus Output
    100c 158f No candidate for conversion 42c
  • Notes

See here for a wikipedia page with temperature conversion formulas. See here for a random web link about converting between degrees and radians.

Apparently Emacs defines float-pi to be defined as pi! Very cool!


  float-pi
3.141592653589793

  (defun 273/rad-to-deg (x)
    "Let's convert radians to degrees"
    (* x (/ 180 float-pi)))
273/rad-to-deg

  (defun  273/deg-to-rad (x)
    "convert degrees to radians"
    (* x (/ float-pi 180)))
273/deg-to-rad