Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Temperature-conversion/00-META.yaml
Normal file
2
Task/Temperature-conversion/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Temperature_conversion
|
||||
32
Task/Temperature-conversion/00-TASK.txt
Normal file
32
Task/Temperature-conversion/00-TASK.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones:
|
||||
[[wp:Kelvin|Kelvin]], [[wp:Degree Celsius|Celsius]], [[wp:Fahrenheit|Fahrenheit]], and [[wp:Degree Rankine|Rankine]].
|
||||
|
||||
The Celsius and Kelvin scales have the same magnitude, but different null points.
|
||||
|
||||
: 0 degrees Celsius corresponds to 273.15 kelvin.
|
||||
: 0 kelvin is absolute zero.
|
||||
|
||||
The Fahrenheit and Rankine scales also have the same magnitude, but different null points.
|
||||
|
||||
: 0 degrees Fahrenheit corresponds to 459.67 degrees Rankine.
|
||||
: 0 degrees Rankine is absolute zero.
|
||||
|
||||
The Celsius/Kelvin and Fahrenheit/Rankine scales have a ratio of 5 : 9.
|
||||
|
||||
|
||||
;Task
|
||||
Write code that accepts a value of kelvin, converts it to values of the three other scales, and prints the result.
|
||||
|
||||
|
||||
;Example:
|
||||
<pre>
|
||||
K 21.00
|
||||
|
||||
C -252.15
|
||||
|
||||
F -421.87
|
||||
|
||||
R 37.80
|
||||
</pre>
|
||||
<br><br>
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
V k = 21.0
|
||||
print(‘K ’k)
|
||||
print(‘C ’(k - 273.15))
|
||||
print(‘F ’(k * 1.8 - 459.67))
|
||||
print(‘R ’(k * 1.8))
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
* Temperature conversion 10/09/2015
|
||||
TEMPERAT CSECT
|
||||
USING TEMPERAT,R15
|
||||
LA R4,1 i=1
|
||||
LA R5,TT @tt(1)
|
||||
LA R6,IDE @ide(1)
|
||||
LOOPI CH R4,=AL2((T-TT)/8) do i=1 to hbound(tt)
|
||||
BH ELOOPI
|
||||
ZAP T,0(8,R5) t=tt(i)
|
||||
CVD R4,DW store to packed decimal
|
||||
UNPK PG(1),DW+7(1) unpack
|
||||
OI PG,X'F0' zap sign
|
||||
MVI PG+1,C' '
|
||||
MVC PG+2(12),0(R6) ide(i)
|
||||
XPRNT PG,14 output i
|
||||
MVC PG(12),=C'Kelvin: '
|
||||
MVC ZN,EDMASKN load mask
|
||||
EDMK ZN,T+5 t (PL3)
|
||||
BCTR R1,0 sign location
|
||||
MVC 0(1,R1),ZN+L'ZN-1 put sign
|
||||
MVC PG+12(L'ZN-1),ZN value
|
||||
MVC PG+19(2),=C' K' unit
|
||||
XPRNT PG,21 output Kelvin
|
||||
MVC PG(12),=C'Celsius: '
|
||||
ZAP DW,T t
|
||||
SP DW,=P'273.15' t-273.15
|
||||
MVC ZN,EDMASKN load mask
|
||||
EDMK ZN,DW+5 (PL3)
|
||||
BCTR R1,0 sign location
|
||||
MVC 0(1,R1),ZN+L'ZN-1 put sign
|
||||
MVC PG+12(L'ZN-1),ZN value
|
||||
MVC PG+19(2),=C' C' unit
|
||||
XPRNT PG,21 output Celsius
|
||||
MVC PG(12),=C'Fahrenheit: '
|
||||
ZAP DW,T t
|
||||
MP DW,=P'18' *18
|
||||
DP DW,=PL3'10' /10
|
||||
ZAP DW,DW(5)
|
||||
SP DW,=P'459.67' t*1.8-459.67
|
||||
MVC ZN,EDMASKN load mask
|
||||
EDMK ZN,DW+5 (PL3)
|
||||
BCTR R1,0 sign location
|
||||
MVC 0(1,R1),ZN+L'ZN-1 put sign
|
||||
MVC PG+12(L'ZN-1),ZN value
|
||||
MVC PG+19(2),=C' F' unit
|
||||
XPRNT PG,21 output Fahrenheit
|
||||
MVC PG(12),=C'Rankine: '
|
||||
ZAP DW,T t
|
||||
MP DW,=P'18' *18
|
||||
DP DW,=PL3'10' /10
|
||||
ZAP DW,DW(5) t*1.8
|
||||
MVC ZN,EDMASKN load mask
|
||||
EDMK ZN,DW+5 (PL3)
|
||||
BCTR R1,0 sign location
|
||||
MVC 0(1,R1),ZN+L'ZN-1 put sign
|
||||
MVC PG+12(L'ZN-1),ZN value
|
||||
MVC PG+19(2),=C' R' unit
|
||||
XPRNT PG,21 output Rankine
|
||||
LA R4,1(R4) i=i+1
|
||||
LA R5,8(R5) @tt(i)
|
||||
LA R6,12(R6) @ide(i)
|
||||
B LOOPI
|
||||
ELOOPI XR R15,R15
|
||||
BR R14
|
||||
IDE DC CL12'absolute',CL12'ice melts',CL12'water boils'
|
||||
TT DC PL8'0.00',PL8'273.15',PL8'373.15'
|
||||
T DS PL8
|
||||
PG DS CL24
|
||||
ZN DS ZL8 5num
|
||||
DW DS D PL8 15num
|
||||
EDMASKN DC X'402021204B202060' CL8 5num
|
||||
YREGS
|
||||
END TEMPERAT
|
||||
32
Task/Temperature-conversion/8th/temperature-conversion.8th
Normal file
32
Task/Temperature-conversion/8th/temperature-conversion.8th
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
: KtoC \ n -- n
|
||||
273.15 n:-
|
||||
;
|
||||
|
||||
: KtoF \ n -- n
|
||||
1.8 n:* 459.67 n:-
|
||||
;
|
||||
|
||||
: KtoR \ n -- n
|
||||
1.8 n:*
|
||||
;
|
||||
|
||||
: KtoCFR \ n --
|
||||
dup dup dup
|
||||
. " degrees Kelvin" . cr
|
||||
KtoC
|
||||
. " degrees Celcius" . cr
|
||||
KtoF
|
||||
. " degrees Fahrenheit" . cr
|
||||
KtoR
|
||||
. " degrees Rankine" . cr
|
||||
;
|
||||
|
||||
: app:main \
|
||||
argc 0 n:=
|
||||
if
|
||||
"Syntax" . cr " temp.8th number" . cr
|
||||
else
|
||||
0 args >n KtoCFR
|
||||
then
|
||||
bye
|
||||
;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
BEGIN
|
||||
REAL kelvin;
|
||||
read (kelvin);
|
||||
FORMAT f = $g(8,2), " K = ", g(8,2)xgl$;
|
||||
printf ((f, kelvin, kelvin - 273.15, "C"));
|
||||
printf ((f, kelvin, 9.0 * kelvin / 5.0, "R"));
|
||||
printf ((f, kelvin, 9.0 * kelvin / 5.0 - 459.67, "F"))
|
||||
END
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
BEGIN
|
||||
DECIMAL K, C, F, R;
|
||||
WRITE( "Temperature in Kelvin:" );
|
||||
READ( K );
|
||||
C := K - 273.15;
|
||||
F := K * 1.8 - 459.67;
|
||||
R := K * 1.8;
|
||||
WRITE( K, " Kelvin is equivalent to" );
|
||||
WRITE( C, " degrees Celsius" );
|
||||
WRITE( F, " degrees Fahrenheit" );
|
||||
WRITE( R, " degrees Rankine" );
|
||||
END
|
||||
|
|
@ -0,0 +1 @@
|
|||
CONVERT←{⍵,(⍵-273.15),(R-459.67),(R←⍵×9÷5)}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
CONVERT 21
|
||||
21 ¯252.15 ¯421.87 37.8
|
||||
19
Task/Temperature-conversion/AWK/temperature-conversion-1.awk
Normal file
19
Task/Temperature-conversion/AWK/temperature-conversion-1.awk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# syntax: AWK -f TEMPERATURE_CONVERSION.AWK
|
||||
BEGIN {
|
||||
while (1) {
|
||||
printf("\nKelvin degrees? ")
|
||||
getline K
|
||||
if (K ~ /^$/) {
|
||||
break
|
||||
}
|
||||
if (K < 0) {
|
||||
print("K must be >= 0")
|
||||
continue
|
||||
}
|
||||
printf("K = %.2f\n",K)
|
||||
printf("C = %.2f\n",K - 273.15)
|
||||
printf("F = %.2f\n",K * 1.8 - 459.67)
|
||||
printf("R = %.2f\n",K * 1.8)
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
19
Task/Temperature-conversion/AWK/temperature-conversion-2.awk
Normal file
19
Task/Temperature-conversion/AWK/temperature-conversion-2.awk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# usage: gawk -f temperature_conversion.awk input.txt -
|
||||
|
||||
BEGIN { print("# Temperature conversion\n") }
|
||||
BEGINFILE { print "# reading", FILENAME
|
||||
if( FILENAME=="-" ) print "# Please enter temperature values in K:\n"
|
||||
}
|
||||
|
||||
!NF { exit }
|
||||
|
||||
{ print "Input:" $0 }
|
||||
$1<0 { print("K must be >= 0\n"); next }
|
||||
{ K = 0+$1
|
||||
printf("K = %8.2f Kelvin degrees\n",K)
|
||||
printf("C = %8.2f\n", K - 273.15)
|
||||
printf("F = %8.2f\n", K * 1.8 - 459.67)
|
||||
printf("R = %8.2f\n\n",K * 1.8)
|
||||
}
|
||||
|
||||
END { print("# Bye.") }
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
|
||||
|
||||
PROC K2C(REAL POINTER k,c)
|
||||
REAL tmp
|
||||
|
||||
ValR("273.15",tmp)
|
||||
RealSub(k,tmp,c)
|
||||
RETURN
|
||||
|
||||
PROC K2F(REAL POINTER k,f)
|
||||
REAL tmp1,tmp2,tmp3
|
||||
|
||||
ValR("1.8",tmp1)
|
||||
ValR("459.67",tmp2)
|
||||
RealMult(k,tmp1,tmp3)
|
||||
RealSub(tmp3,tmp2,f)
|
||||
RETURN
|
||||
|
||||
PROC K2R(REAL POINTER k,f)
|
||||
REAL tmp
|
||||
|
||||
ValR("1.8",tmp)
|
||||
RealMult(k,tmp,f)
|
||||
RETURN
|
||||
|
||||
PROC Test(CHAR ARRAY text REAL POINTER k)
|
||||
REAL res
|
||||
|
||||
PrintE(text)
|
||||
Print(" Kelvin: ") PrintRE(k)
|
||||
|
||||
K2C(k,res)
|
||||
Print(" Celsius: ") PrintRE(res)
|
||||
|
||||
K2F(k,res)
|
||||
Print(" Fahrenheit: ") PrintRE(res)
|
||||
|
||||
K2R(k,res)
|
||||
Print(" Rankine: ") PrintRE(res)
|
||||
|
||||
PutE()
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
REAL k
|
||||
|
||||
Put(125) PutE() ;clear screen
|
||||
|
||||
ValR("0",k) Test("Absolute zero",k)
|
||||
ValR("273.15",k) Test("Ice melts",k)
|
||||
ValR("373.15",k) Test("Water boils",k)
|
||||
RETURN
|
||||
14
Task/Temperature-conversion/Ada/temperature-conversion.ada
Normal file
14
Task/Temperature-conversion/Ada/temperature-conversion.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
with Ada.Float_Text_IO, Ada.Text_IO; use Ada.Float_Text_IO, Ada.Text_IO;
|
||||
|
||||
procedure Temperatur_Conversion is
|
||||
K: Float;
|
||||
function C return Float is (K - 273.15);
|
||||
function F return Float is (K * 1.8 - 459.67);
|
||||
function R return Float is (K * 1.8);
|
||||
begin
|
||||
Get(K); New_Line; -- Format
|
||||
Put("K: "); Put(K, Fore => 4, Aft => 2, Exp => 0); New_Line;-- K: dddd.dd
|
||||
Put("C: "); Put(C, Fore => 4, Aft => 2, Exp => 0); New_Line;-- C: dddd.dd
|
||||
Put("F: "); Put(F, Fore => 4, Aft => 2, Exp => 0); New_Line;-- F: dddd.dd
|
||||
Put("R: "); Put(R, Fore => 4, Aft => 2, Exp => 0); New_Line;-- R: dddd.dd
|
||||
end;
|
||||
20
Task/Temperature-conversion/Aime/temperature-conversion.aime
Normal file
20
Task/Temperature-conversion/Aime/temperature-conversion.aime
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
void
|
||||
show(integer symbol, real temperature)
|
||||
{
|
||||
o_form("%c /d2p2w8/\n", symbol, temperature);
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
real k;
|
||||
|
||||
k = atof(argv(1));
|
||||
|
||||
show('K', k);
|
||||
show('C', k - 273.15);
|
||||
show('F', k * 1.8 - 459.67);
|
||||
show('R', k * 1.8);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* MISTRAL - a flavour of Hopper */
|
||||
|
||||
#include <mistral.h>
|
||||
|
||||
INICIAR:
|
||||
TAMAÑO DE MEMORIA 20
|
||||
temperatura=0
|
||||
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
|
||||
TOMAR("KELVIN : ",temperatura, NL)
|
||||
CON( "CELSIUS : ", temperatura ), CALCULAR( Conversión Kelvin a Celsius ), NUEVA LÍNEA
|
||||
CON( "FAHRENHEIT : ", temperatura ), CALCULAR( Conversión Kelvin a Fahrenheit ), NUEVA LÍNEA
|
||||
CON( "RANKINE : ", temperatura ), CALCULAR( Conversión Kelvin a Rankine ), NUEVA LÍNEA
|
||||
IMPRIMIR CON SALTO
|
||||
FINALIZAR
|
||||
|
||||
SUBRUTINAS
|
||||
|
||||
FUNCIÓN(Conversión Kelvin a Celsius, k)
|
||||
REDONDEAR(RESTAR(k, 273.15), 2)
|
||||
RETORNAR
|
||||
|
||||
FUNCIÓN( Conversión Kelvin a Fahrenheit, k)
|
||||
REDONDEAR( {k} MULTIPLICADO POR(1.8) MENOS( 459.67), 2)
|
||||
RETORNAR
|
||||
|
||||
FUNCIÓN( Conversión Kelvin a Rankine, k)
|
||||
RETORNAR ( {k} POR (1.8), REDONDEADO AL DECIMAL(2) )
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/* MISTRAL - a flavour of Hopper */
|
||||
|
||||
#include <mistral.h>
|
||||
|
||||
INICIAR:
|
||||
temperatura=0
|
||||
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
|
||||
IMPRIMIR("KELVIN : ",temperatura, NL)
|
||||
IMPRIMIR("CELSIUS : ",temperatura, MENOS '273.15', NL)
|
||||
IMPRIMIR("FAHRENHEIT : ",temperatura, POR '1.8' MENOS '459.67', NL)
|
||||
IMPRIMIR("RANKINE : ",temperatura, POR '1.8', NL)
|
||||
FINALIZAR
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#include <mistral.h>
|
||||
|
||||
INICIAR:
|
||||
TAMAÑO DE MEMORIA 15
|
||||
temperatura=0
|
||||
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
|
||||
IMPRIMIR("KELVIN : ", temperatura, NL,\
|
||||
"CELSIUS : ", {temperatura} MENOS '273.15', NL,\
|
||||
"FAHRENHEIT : ", {temperatura} POR '1.8' MENOS '459.67', NL,\
|
||||
"RANKINE : ", {temperatura} POR '1.8', NL)
|
||||
FINALIZAR
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#include <mistral.h>
|
||||
|
||||
INICIAR:
|
||||
TAMAÑO DE MEMORIA 20
|
||||
temperatura=0, rankine=0
|
||||
RECIBIR PARÁMETRO NUMÉRICO(2), GUARDAR EN (temperatura);
|
||||
IMPRIMIR("KELVIN : ", temperatura, NL,\
|
||||
"CELSIUS : ", {temperatura} MENOS '273.15', NL,\
|
||||
"FAHRENHEIT : ", {temperatura} POR '1.8' ---RESPALDE EN 'rankine'--- MENOS '459.67', NL,\
|
||||
"RANKINE : ", rankine, NL)
|
||||
FINALIZAR
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
use framework "Foundation" -- Yosemite onwards, for the toLowerCase() function
|
||||
|
||||
-- KELVIN TO OTHER SCALE -----------------------------------------------------
|
||||
|
||||
-- kelvinAs :: ScaleName -> Num -> Num
|
||||
on kelvinAs(strOtherScale, n)
|
||||
heatBabel(n, "Kelvin", strOtherScale)
|
||||
end kelvinAs
|
||||
|
||||
-- MORE GENERAL CONVERSION ---------------------------------------------------
|
||||
|
||||
-- heatBabel :: n -> ScaleName -> ScaleName -> Num
|
||||
on heatBabel(n, strFromScale, strToScale)
|
||||
set ratio to 9 / 5
|
||||
set cels to 273.15
|
||||
set fahr to 459.67
|
||||
|
||||
script reading
|
||||
on |λ|(x, strFrom)
|
||||
if strFrom = "k" then
|
||||
x as real
|
||||
else if strFrom = "c" then
|
||||
x + cels
|
||||
else if strFrom = "f" then
|
||||
(fahr + x) * ratio
|
||||
else
|
||||
x / ratio
|
||||
end if
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
script writing
|
||||
on |λ|(x, strTo)
|
||||
if strTo = "k" then
|
||||
x
|
||||
else if strTo = "c" then
|
||||
x - cels
|
||||
else if strTo = "f" then
|
||||
(x * ratio) - fahr
|
||||
else
|
||||
x * ratio
|
||||
end if
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
writing's |λ|(reading's |λ|(n, ¬
|
||||
toLower(text 1 of strFromScale)), ¬
|
||||
toLower(text 1 of strToScale))
|
||||
end heatBabel
|
||||
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on kelvinTranslations(n)
|
||||
script translations
|
||||
on |λ|(x)
|
||||
{x, kelvinAs(x, n)}
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
map(translations, {"K", "C", "F", "R"})
|
||||
end kelvinTranslations
|
||||
|
||||
on run
|
||||
script tabbed
|
||||
on |λ|(x)
|
||||
intercalate(tab, x)
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
intercalate(linefeed, map(tabbed, kelvinTranslations(21)))
|
||||
end run
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- intercalate :: Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
set strJoined to lstText as text
|
||||
set my text item delimiters to dlm
|
||||
return strJoined
|
||||
end intercalate
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- toLower :: String -> String
|
||||
on toLower(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toLower
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
on convertFromKelvin(kelvinValue)
|
||||
return ("K" & tab & (kelvinValue as real)) & ¬
|
||||
(linefeed & "C" & tab & (kelvinValue - 273.15)) & ¬
|
||||
(linefeed & "F" & tab & ((kelvinValue - 273.15) * 9 / 5 + 32)) & ¬
|
||||
(linefeed & "R" & tab & (kelvinValue * 9 / 5))
|
||||
end convertFromKelvin
|
||||
|
||||
convertFromKelvin(21)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
on convertFromKelvin(kelvinValue)
|
||||
set kelvinMeasurement to kelvinValue as degrees Kelvin
|
||||
|
||||
set celsiusValue to kelvinMeasurement as degrees Celsius as number
|
||||
set fahrenheitValue to kelvinMeasurement as degrees Fahrenheit as number
|
||||
set rankineValue to kelvinValue * 9 / 5
|
||||
|
||||
return ("K" & tab & (kelvinValue as real)) & ¬
|
||||
(linefeed & "C" & tab & celsiusValue) & ¬
|
||||
(linefeed & "F" & tab & fahrenheitValue) & ¬
|
||||
(linefeed & "R" & tab & rankineValue)
|
||||
end convertFromKelvin
|
||||
|
||||
convertFromKelvin(21)
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
use AppleScript version "2.5" -- macOS 10.12 (Sierra) or later
|
||||
use framework "Foundation"
|
||||
|
||||
on convertFromKelvin(kelvinValue)
|
||||
set |⌘| to current application
|
||||
|
||||
-- Set up an NSMeasurement object representing the given number of Kelvin units.
|
||||
set kelvinUnit to |⌘|'s class "NSUnitTemperature"'s kelvin()
|
||||
set kelvinMeasurement to |⌘|'s class "NSMeasurement"'s alloc()'s initWithDoubleValue:(kelvinValue) unit:(kelvinUnit)
|
||||
|
||||
-- Get value of the same measurement in each of the other "units" in turn.
|
||||
set celsiusUnit to |⌘|'s class "NSUnitTemperature"'s celsius()
|
||||
set celsiusMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(celsiusUnit)
|
||||
set celsiusValue to celsiusMeasurement's doubleValue()
|
||||
|
||||
set fahrenheitUnit to |⌘|'s class "NSUnitTemperature"'s fahrenheit()
|
||||
set fahrenheitMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(fahrenheitUnit)
|
||||
set fahrenheitValue to fahrenheitMeasurement's doubleValue()
|
||||
|
||||
-- There's no predefined unit for Rankine (as at macOS 10.14 Mojave), but custom units are easy to define.
|
||||
-- A unit's linear 'converter' must contain the unit's size and zero offset relative to those of its class's "base unit"
|
||||
-- which for temperatures is the 'kelvin' unit.
|
||||
set rankineConverter to |⌘|'s class "NSUnitConverterLinear"'s alloc()'s initWithCoefficient:(5 / 9) |constant|:(0)
|
||||
set rankineUnit to |⌘|'s class "NSUnitTemperature"'s alloc()'s initWithSymbol:("°R") converter:(rankineConverter)
|
||||
set rankineMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(rankineUnit)
|
||||
set rankineValue to rankineMeasurement's doubleValue()
|
||||
|
||||
return ("K" & tab & (kelvinValue as real)) & ¬
|
||||
(linefeed & "C" & tab & celsiusValue) & ¬
|
||||
(linefeed & "F" & tab & fahrenheitValue) & ¬
|
||||
(linefeed & "R" & tab & rankineValue)
|
||||
end convertFromKelvin
|
||||
|
||||
convertFromKelvin(21)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
convertKelvins: function [k][
|
||||
#[
|
||||
celcius: k - 273.15
|
||||
fahrenheit: (k * 9/5.0)-459.67
|
||||
rankine: k * 9/5.0
|
||||
]
|
||||
]
|
||||
|
||||
print convertKelvins 100
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
MsgBox, % "Kelvin:`t`t 21.00 K`n"
|
||||
. "Celsius:`t`t" kelvinToCelsius(21) " C`n"
|
||||
. "Fahrenheit:`t" kelvinToFahrenheit(21) " F`n"
|
||||
. "Rankine:`t`t" kelvinToRankine(21) " R`n"
|
||||
|
||||
kelvinToCelsius(k)
|
||||
{
|
||||
return, round(k - 273.15, 2)
|
||||
}
|
||||
kelvinToFahrenheit(k)
|
||||
{
|
||||
return, round(k * 1.8 - 459.67, 2)
|
||||
}
|
||||
kelvinToRankine(k)
|
||||
{
|
||||
return, round(k * 1.8, 2)
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
; ### USAGE - TESTING PURPOSES ONLY
|
||||
|
||||
Local Const $_KELVIN = 21
|
||||
ConsoleWrite("Kelvin: " & $_KELVIN & @CRLF)
|
||||
ConsoleWrite("Kelvin: " & Kelvin(21, "C") & @CRLF)
|
||||
ConsoleWrite("Kelvin: " & Kelvin(21, "F") & @CRLF)
|
||||
ConsoleWrite("Kelvin: " & Kelvin(21, "R") & @CRLF)
|
||||
|
||||
; ### KELVIN TEMPERATURE CONVERSIONS
|
||||
|
||||
Func Kelvin($degrees, $conversion)
|
||||
Select
|
||||
Case $conversion = "C"
|
||||
Return Round($degrees - 273.15, 2)
|
||||
Case $conversion = "F"
|
||||
Return Round(($degrees * 1.8) - 459.67, 2)
|
||||
Case $conversion = "R"
|
||||
Return Round($degrees * 1.8, 2)
|
||||
EndSelect
|
||||
EndFunc ;==> Kelvin
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
10 REM TRANSLATION OF AWK VERSION
|
||||
20 INPUT "KELVIN DEGREES",K
|
||||
30 IF K <= 0 THEN END: REM A VALUE OF ZERO OR LESS WILL END PROGRAM
|
||||
40 LET C = K - 273.15
|
||||
50 LET F = K * 1.8 - 459.67
|
||||
60 LET R = K * 1.8
|
||||
70 PRINT K; " KELVIN IS EQUIVALENT TO"
|
||||
80 PRINT C; " DEGREES CELSIUS"
|
||||
90 PRINT F; " DEGREES FAHRENHEIT"
|
||||
100 PRINT R; " DEGREES RANKINE"
|
||||
110 GOTO 20
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
do
|
||||
print "Kelvin degrees (>=0): ";
|
||||
input K
|
||||
until K>=0
|
||||
|
||||
print "K = " + string(K)
|
||||
print "C = " + string(K - 273.15)
|
||||
print "F = " + string(K * 1.8 - 459.67)
|
||||
print "R = " + string(K * 1.8)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
REPEAT
|
||||
INPUT "Kelvin degrees (>=0): " K
|
||||
UNTIL K>=0
|
||||
@%=&20208
|
||||
PRINT '"K = " K
|
||||
PRINT "C = " K - 273.15
|
||||
PRINT "F = " K * 1.8 - 459.67
|
||||
PRINT "R = " K * 1.8
|
||||
END
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
0000>0p~>"."-:!#v_2-::0\`\9`+!#v_$1>/\:3`#v_\>\:3 \`#v_v
|
||||
1#<<^0 /2++g001!<1 \+g00\+*+55\< ^+55\-1< ^*+55\+1<v_
|
||||
"K"\-+**"!Y]"9:\"C"\--\**"^CIT"/5*9:\"F"\/5*9:\"R"\0\0<v
|
||||
v/+55\+*86%+55: /+55\+*86%+55: \0/+55+5*-\1*2 p00:`\0:,<
|
||||
>"."\>:55+% 68*v >:#,_$55+,\:!#@_^
|
||||
$_^#!:/+55\+< ^\" :"_<g00*95
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
( ( rational2fixedpoint
|
||||
= minus fixedpointnumber number decimals
|
||||
. !arg:(#?number.~<0:~/#?decimals)
|
||||
& ( !number:0&"0.0"
|
||||
| ( !number:>0&
|
||||
| -1*!number:?number&"-"
|
||||
)
|
||||
: ?minus
|
||||
& !number+1/2*10^(-1*!decimals):?number
|
||||
& !minus div$(!number.1) ".":?fixedpointnumber
|
||||
& whl
|
||||
' ( !decimals+-1:~<0:?decimals
|
||||
& !fixedpointnumber
|
||||
div$(mod$(!number.1)*10:?number.1)
|
||||
: ?fixedpointnumber
|
||||
)
|
||||
& str$!fixedpointnumber
|
||||
)
|
||||
)
|
||||
& ( fixedpoint2rational
|
||||
= integerpart fractionalpart decimals
|
||||
. @( !arg
|
||||
: #?integerpart
|
||||
( "." ?fractionalpart
|
||||
| &0:?fractionalpart
|
||||
)
|
||||
)
|
||||
& @(!fractionalpart:? #?fractionalpart [?decimals)
|
||||
& !integerpart
|
||||
+ (!integerpart:<0&-1|1)
|
||||
* 10^(-1*!decimals)
|
||||
* !fractionalpart
|
||||
)
|
||||
& whl
|
||||
' ( put$"Enter Kelvin temperature:"
|
||||
& fixedpoint2rational$(get'(,STR)):?kelvin
|
||||
& !kelvin+-27315/100:?celcius
|
||||
& (degree=.str$(chu$(x2d$b0) !arg))
|
||||
& out$(rational2fixedpoint$(!kelvin.2) K)
|
||||
& out$(rational2fixedpoint$(!celcius.2) degree$C)
|
||||
& out$(rational2fixedpoint$(!celcius*9/5+32.2) degree$F)
|
||||
& out$(rational2fixedpoint$(!kelvin*9/5.2) degree$Ra)
|
||||
& out$(rational2fixedpoint$(!celcius*4/5.2) degree$Ré)
|
||||
)
|
||||
& done!
|
||||
)
|
||||
54
Task/Temperature-conversion/C++/temperature-conversion.cpp
Normal file
54
Task/Temperature-conversion/C++/temperature-conversion.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
using namespace std;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class converter
|
||||
{
|
||||
public:
|
||||
converter() : KTC( 273.15f ), KTDel( 3.0f / 2.0f ), KTF( 9.0f / 5.0f ), KTNew( 33.0f / 100.0f ),
|
||||
KTRank( 9.0f / 5.0f ), KTRe( 4.0f / 5.0f ), KTRom( 21.0f / 40.0f ) {}
|
||||
|
||||
void convert( float kelvin )
|
||||
{
|
||||
float cel = kelvin - KTC,
|
||||
del = ( 373.15f - kelvin ) * KTDel,
|
||||
fah = kelvin * KTF - 459.67f,
|
||||
net = cel * KTNew,
|
||||
rnk = kelvin * KTRank,
|
||||
rea = cel * KTRe,
|
||||
rom = cel * KTRom + 7.5f;
|
||||
|
||||
cout << endl << left
|
||||
<< "TEMPERATURES:" << endl
|
||||
<< "===============" << endl << setw( 13 )
|
||||
<< "CELSIUS:" << cel << endl << setw( 13 )
|
||||
<< "DELISLE:" << del << endl << setw( 13 )
|
||||
<< "FAHRENHEIT:" << fah << endl << setw( 13 )
|
||||
<< "KELVIN:" << kelvin << endl << setw( 13 )
|
||||
<< "NEWTON:" << net << endl << setw( 13 )
|
||||
<< "RANKINE:" << rnk << endl << setw( 13 )
|
||||
<< "REAUMUR:" << rea << endl << setw( 13 )
|
||||
<< "ROMER:" << rom << endl << endl << endl;
|
||||
}
|
||||
private:
|
||||
const float KTRank, KTC, KTF, KTRe, KTDel, KTNew, KTRom;
|
||||
};
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
converter con;
|
||||
float k;
|
||||
while( true )
|
||||
{
|
||||
cout << "Enter the temperature in Kelvin to convert: ";
|
||||
cin >> k;
|
||||
con.convert( k );
|
||||
system( "pause" );
|
||||
system( "cls" );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
|
||||
namespace TemperatureConversion
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static Func<double, double> ConvertKelvinToFahrenheit = x => (x * 1.8) - 459.67;
|
||||
static Func<double, double> ConvertKelvinToRankine = x => x * 1.8;
|
||||
static Func<double, double> ConvertKelvinToCelsius = x => x = 273.13;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.Write("Enter a Kelvin Temperature: ");
|
||||
string inputVal = Console.ReadLine();
|
||||
double kelvinTemp = 0f;
|
||||
|
||||
if (double.TryParse(inputVal, out kelvinTemp))
|
||||
{
|
||||
Console.WriteLine(string.Format("Kelvin: {0}", kelvinTemp));
|
||||
Console.WriteLine(string.Format("Fahrenheit: {0}", ConvertKelvinToFahrenheit(kelvinTemp)));
|
||||
Console.WriteLine(string.Format("Rankine: {0}", ConvertKelvinToRankine(kelvinTemp)));
|
||||
Console.WriteLine(string.Format("Celsius: {0}", ConvertKelvinToCelsius(kelvinTemp)));
|
||||
Console.ReadKey();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid input value: " + inputVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Task/Temperature-conversion/C/temperature-conversion.c
Normal file
29
Task/Temperature-conversion/C/temperature-conversion.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
double kelvinToCelsius(double k){
|
||||
return k - 273.15;
|
||||
}
|
||||
|
||||
double kelvinToFahrenheit(double k){
|
||||
return k * 1.8 - 459.67;
|
||||
}
|
||||
|
||||
double kelvinToRankine(double k){
|
||||
return k * 1.8;
|
||||
}
|
||||
void convertKelvin(double kelvin) {
|
||||
printf("K %.2f\n", kelvin);
|
||||
printf("C %.2f\n", kelvinToCelsius(kelvin));
|
||||
printf("F %.2f\n", kelvinToFahrenheit(kelvin));
|
||||
printf("R %.2f", kelvinToRankine(kelvin));
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
if (argc > 1) {
|
||||
double kelvin = atof(argv[1]);
|
||||
convertKelvin(kelvin);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
38
Task/Temperature-conversion/CLU/temperature-conversion.clu
Normal file
38
Task/Temperature-conversion/CLU/temperature-conversion.clu
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
kelvin = proc (k: real) returns (real)
|
||||
return(k)
|
||||
end kelvin
|
||||
|
||||
celsius = proc (k: real) returns (real)
|
||||
return(k - 273.15)
|
||||
end celsius
|
||||
|
||||
rankine = proc (k: real) returns (real)
|
||||
return(k * 9./5.)
|
||||
end rankine
|
||||
|
||||
fahrenheit = proc (k: real) returns (real)
|
||||
return(rankine(k) - 459.67)
|
||||
end fahrenheit
|
||||
|
||||
conv = struct[letter: char, func: proctype (real) returns (real)]
|
||||
|
||||
convs = sequence[conv]$[
|
||||
conv${letter: 'K', func: kelvin},
|
||||
conv${letter: 'C', func: celsius},
|
||||
conv${letter: 'F', func: fahrenheit},
|
||||
conv${letter: 'R', func: rankine}
|
||||
]
|
||||
|
||||
start_up = proc ()
|
||||
pi: stream := stream$primary_input()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
stream$puts(po, "Enter temperature in Kelvin: ")
|
||||
k: real := real$parse(stream$getl(pi))
|
||||
|
||||
for c: conv in sequence[conv]$elements(convs) do
|
||||
stream$putc(po, c.letter)
|
||||
stream$puts(po, " ")
|
||||
stream$putl(po, f_form(c.func(k), 6, 2))
|
||||
end
|
||||
end start_up
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. temp-conversion.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
78 Kelvin-Rankine-Ratio VALUE 0.5556. *> 5 / 9 to 4 d.p.
|
||||
78 Kelvin-Celsius-Diff VALUE 273.15.
|
||||
78 Rankine-Fahrenheit-Diff VALUE 459.67.
|
||||
|
||||
01 temp-kelvin PIC S9(8)V99.
|
||||
01 temp-rankine PIC S9(8)V99.
|
||||
|
||||
01 kelvin PIC -(7)9.99.
|
||||
01 celsius PIC -(7)9.99.
|
||||
01 rankine PIC -(7)9.99.
|
||||
01 fahrenheit PIC -(7)9.99.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY "Enter a temperature in Kelvin to convert: " NO ADVANCING
|
||||
ACCEPT temp-kelvin
|
||||
|
||||
MOVE temp-kelvin TO kelvin
|
||||
DISPLAY "K " kelvin
|
||||
|
||||
SUBTRACT Kelvin-Celsius-Diff FROM temp-kelvin GIVING celsius
|
||||
DISPLAY "C " celsius
|
||||
|
||||
DIVIDE temp-kelvin BY Kelvin-Rankine-Ratio
|
||||
GIVING temp-rankine, rankine
|
||||
SUBTRACT Rankine-Fahrenheit-Diff FROM temp-rankine GIVING fahrenheit
|
||||
|
||||
DISPLAY "F " fahrenheit
|
||||
DISPLAY "R " rankine
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
shared void run() {
|
||||
|
||||
void printKelvinConversions(Float kelvin) {
|
||||
value celsius = kelvin - 273.15;
|
||||
value rankine = kelvin * 9.0 / 5.0;
|
||||
value fahrenheit = rankine - 459.67;
|
||||
|
||||
print("Kelvin: ``formatFloat(kelvin, 2, 2)``
|
||||
Celsius: ``formatFloat(celsius, 2, 2)``
|
||||
Fahrenheit: ``formatFloat(fahrenheit, 2, 2)``
|
||||
Rankine: ``formatFloat(rankine, 2, 2)``");
|
||||
}
|
||||
|
||||
printKelvinConversions(21.0);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(defn to-celsius [k]
|
||||
(- k 273.15))
|
||||
(defn to-fahrenheit [k]
|
||||
(- (* k 1.8) 459.67))
|
||||
(defn to-rankine [k]
|
||||
(* k 1.8))
|
||||
|
||||
(defn temperature-conversion [k]
|
||||
(if (number? k)
|
||||
(format "Celsius: %.2f Fahrenheit: %.2f Rankine: %.2f"
|
||||
(to-celsius k) (to-fahrenheit k) (to-rankine k))
|
||||
(format "Error: Non-numeric value entered.")))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(defun to-celsius (k)
|
||||
(- k 273.15))
|
||||
(defun to-fahrenheit (k)
|
||||
(- (* k 1.8) 459.67))
|
||||
(defun to-rankine (k)
|
||||
(* k 1.8))
|
||||
|
||||
(defun temperature-conversion ()
|
||||
(let ((k (read)))
|
||||
(if (numberp k)
|
||||
(format t "Celsius: ~d~%Fahrenheit: ~d~%Rankine: ~d~%"
|
||||
(to-celsius k) (to-fahrenheit k) (to-rankine k))
|
||||
(format t "Error: Non-numeric value entered."))))
|
||||
33
Task/Temperature-conversion/D/temperature-conversion.d
Normal file
33
Task/Temperature-conversion/D/temperature-conversion.d
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
double kelvinToCelsius(in double k) pure nothrow @safe {
|
||||
return k - 273.15;
|
||||
}
|
||||
|
||||
double kelvinToFahrenheit(in double k) pure nothrow @safe {
|
||||
return k * 1.8 - 459.67;
|
||||
}
|
||||
|
||||
double kelvinToRankine(in double k) pure nothrow @safe {
|
||||
return k * 1.8;
|
||||
}
|
||||
|
||||
unittest {
|
||||
import std.math: approxEqual;
|
||||
assert(approxEqual(kelvinToCelsius(21.0), -252.15));
|
||||
assert(approxEqual(kelvinToFahrenheit(21.0), -421.87));
|
||||
assert(approxEqual(kelvinToRankine(21.0), 37.8));
|
||||
}
|
||||
|
||||
void main(string[] args) {
|
||||
import std.stdio, std.conv, std.string;
|
||||
|
||||
if (args.length == 2 && isNumeric(args[1])) {
|
||||
immutable kelvin = to!double(args[1]);
|
||||
if (kelvin >= 0) {
|
||||
writefln("K %2.2f", kelvin);
|
||||
writefln("C %2.2f", kelvinToCelsius(kelvin));
|
||||
writefln("F %2.2f", kelvinToFahrenheit(kelvin));
|
||||
writefln("R %2.2f", kelvinToRankine(kelvin));
|
||||
} else
|
||||
writefln("%2.2f K is below absolute zero", kelvin);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
program Temperature;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
type
|
||||
TTemp = class
|
||||
private
|
||||
fCelsius, fFahrenheit, fRankine: double;
|
||||
public
|
||||
constructor Create(aKelvin: double);
|
||||
property AsCelsius: double read fCelsius;
|
||||
property AsFahrenheit: double read fFahrenheit;
|
||||
property AsRankine: double read fRankine;
|
||||
end;
|
||||
|
||||
{ TTemp }
|
||||
|
||||
constructor TTemp.Create(aKelvin: double);
|
||||
begin
|
||||
fCelsius := aKelvin - 273.15;
|
||||
fRankine := aKelvin * 9 / 5;
|
||||
fFahrenheit := fRankine - 459.67;
|
||||
end;
|
||||
|
||||
var
|
||||
kelvin: double;
|
||||
temp: TTemp;
|
||||
|
||||
begin
|
||||
write('Kelvin: ');
|
||||
readln(kelvin);
|
||||
temp := TTemp.Create(kelvin);
|
||||
writeln(Format('Celsius: %.2f', [temp.AsCelsius]));
|
||||
writeln(Format('Fahrenheit: %.2f', [temp.AsFahrenheit]));
|
||||
writeln(Format('Rankine: %.2f', [temp.AsRankine]));
|
||||
temp.Free;
|
||||
readln;
|
||||
end.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
k = number input
|
||||
print k & " °K"
|
||||
print k - 273.15 & " °C"
|
||||
print k * 1.8 - 459.67 & " °F"
|
||||
print k * 1.8 & " °R"
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import extensions;
|
||||
|
||||
convertKelvinToFahrenheit(x)
|
||||
= x * 1.8r - 459.6r;
|
||||
|
||||
convertKelvinToRankine(x)
|
||||
= x * 1.8r;
|
||||
|
||||
convertKelvinToCelsius(x)
|
||||
= x - 273.15r;
|
||||
|
||||
public program()
|
||||
{
|
||||
console.print("Enter a Kelvin Temperature: ");
|
||||
var inputVal := console.readLine();
|
||||
real kelvinTemp := 0.0r;
|
||||
try
|
||||
{
|
||||
kelvinTemp := realConvertor.convert(inputVal)
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
console.printLine("Invalid input value: ", inputVal);
|
||||
|
||||
AbortException.raise()
|
||||
};
|
||||
|
||||
console.printLine("Kelvin: ", kelvinTemp);
|
||||
console.printLine("Fahrenheit: ", convertKelvinToFahrenheit(kelvinTemp));
|
||||
console.printLine("Rankine: ", convertKelvinToRankine(kelvinTemp));
|
||||
console.printLine("Celsius: ", convertKelvinToCelsius(kelvinTemp));
|
||||
console.readChar()
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
defmodule Temperature do
|
||||
def conversion(t) do
|
||||
IO.puts "K : #{f(t)}"
|
||||
IO.puts "\nC : #{f(t - 273.15)}"
|
||||
IO.puts "\nF : #{f(t * 1.8 - 459.67)}"
|
||||
IO.puts "\nR : #{f(t * 1.8)}"
|
||||
end
|
||||
|
||||
defp f(a) do
|
||||
Float.round(a, 2)
|
||||
end
|
||||
|
||||
def task, do: conversion(21.0)
|
||||
end
|
||||
|
||||
Temperature.task
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
% Implemented by Arjun Sunel
|
||||
-module(temp_conv).
|
||||
-export([main/0]).
|
||||
|
||||
main() ->
|
||||
conversion(21).
|
||||
|
||||
conversion(T) ->
|
||||
io:format("\nK : ~p\n\n",[f(T)]),
|
||||
io:format("C : ~p \n\n",[f(T - 273.15)]),
|
||||
io:format("F : ~p\n\n",[f(T * 1.8 - 459.67)]),
|
||||
io:format("R : ~p\n\n",[f(T * 1.8)]).
|
||||
|
||||
f(A) ->
|
||||
(round(A*100))/100 .
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
include std/console.e
|
||||
|
||||
atom K
|
||||
while 1 do
|
||||
K = prompt_number("Enter temperature in Kelvin >=0: ",{0,4294967296})
|
||||
printf(1,"K = %5.2f\nC = %5.2f\nF = %5.2f\nR = %5.2f\n\n",{K,K-273.15,K*1.8-459.67,K*1.8})
|
||||
end while
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
A1 : Kelvin
|
||||
B1 : Celsius
|
||||
C1 : Fahrenheit
|
||||
D1 : Rankine
|
||||
Name A2 : K
|
||||
B2 : =K-273.15
|
||||
C2 : =K*1.8-459.67
|
||||
D2 : =K*1.8
|
||||
Input in A1
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
FROMKELVIN
|
||||
=LAMBDA(toUnit,
|
||||
LAMBDA(n,
|
||||
LET(
|
||||
REM, "Valid units :: C, F, R, K",
|
||||
|
||||
CONVERT(
|
||||
n, "K",
|
||||
IF("R" = toUnit,
|
||||
"Rank",
|
||||
toUnit
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
ENUMFROMTHENTO
|
||||
=LAMBDA(a,
|
||||
LAMBDA(b,
|
||||
LAMBDA(z,
|
||||
LET(
|
||||
d, b - a,
|
||||
|
||||
SEQUENCE(
|
||||
1 + FLOOR.MATH((z - a)/d),
|
||||
1, a, d
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# convert from Kelvin
|
||||
நிரல்பாகம் கெல்வின்_இருந்து_மாற்று( k )
|
||||
பதிப்பி "Kelvin: ",k,"Celsius: ",round(k-273.15)," Fahrenheit: ",(round(k*1.8 - 459.67))," Rankine: ",(round(k*1.8))
|
||||
முடி
|
||||
|
||||
கெல்வின்_இருந்து_மாற்று( 0 ) #absolute zero
|
||||
கெல்வின்_இருந்து_மாற்று( 273 ) #freezing pt of water
|
||||
கெல்வின்_இருந்து_மாற்று( 30 + 273 ) #room temperature in Summer
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Define units of measure
|
||||
[<Measure>] type k
|
||||
[<Measure>] type f
|
||||
[<Measure>] type c
|
||||
[<Measure>] type r
|
||||
|
||||
// Define conversion functions
|
||||
let kelvinToCelsius (t : float<k>) = ((float t) - 273.15) * 1.0<c>
|
||||
let kelvinToFahrenheit (t : float<k>) = (((float t) * 1.8) - 459.67) * 1.0<f>
|
||||
let kelvinToRankine (t : float<k>) = ((float t) * 1.8) * 1.0<r>
|
||||
|
||||
// Example code
|
||||
let K = 21.0<k>
|
||||
printfn "%A Kelvin is %A Celsius" K (kelvinToCelsius K)
|
||||
printfn "%A Kelvin is %A Fahrenheit" K (kelvinToFahrenheit K)
|
||||
printfn "%A Kelvin is %A Rankine" K (kelvinToRankine K)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
01.10 ASK "TEMPERATURE IN KELVIN", K
|
||||
01.20 TYPE "K ", %6.02, K, !
|
||||
01.30 TYPE "C ", %6.02, K - 273.15, !
|
||||
01.40 TYPE "F ", %6.02, K * 1.8 - 459.67, !
|
||||
01.50 TYPE "R ", %6.02, K * 1.8, !
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
USING: combinators formatting kernel math ;
|
||||
IN: rosetta-code.temperature
|
||||
|
||||
: k>c ( kelvin -- celsius ) 273.15 - ;
|
||||
: k>r ( kelvin -- rankine ) 9/5 * ;
|
||||
: k>f ( kelvin -- fahrenheit ) k>r 459.67 - ;
|
||||
|
||||
: convert ( kelvin -- )
|
||||
{ [ ] [ k>c ] [ k>f ] [ k>r ] } cleave
|
||||
"K %.2f\nC %.2f\nF %.2f\nR %.2f\n" printf ;
|
||||
|
||||
21 convert
|
||||
13
Task/Temperature-conversion/Forth/temperature-conversion.fth
Normal file
13
Task/Temperature-conversion/Forth/temperature-conversion.fth
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
: k>°C ( F: kelvin -- celsius ) 273.15e0 f- ;
|
||||
: k>°R ( F: kelvin -- rankine ) 1.8e0 f* ;
|
||||
: °R>°F ( F: rankine -- fahrenheit ) 459.67e0 f- ;
|
||||
: k>°F ( F: kelvin -- fahrenheit ) k>°R °R>°F ;
|
||||
: main
|
||||
argc 1 > if 1 arg >float
|
||||
fdup f. ." K" cr
|
||||
fdup k>°C f. ." °C" cr
|
||||
fdup k>°F f. ." °F" cr
|
||||
fdup k>°R f. ." °R" cr
|
||||
then ;
|
||||
|
||||
main bye
|
||||
26
Task/Temperature-conversion/Fortran/temperature-conversion.f
Normal file
26
Task/Temperature-conversion/Fortran/temperature-conversion.f
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Program Temperature
|
||||
implicit none
|
||||
|
||||
real :: kel, cel, fah, ran
|
||||
|
||||
write(*,*) "Input Kelvin temperature to convert"
|
||||
read(*,*) kel
|
||||
|
||||
call temp_convert(kel, cel, fah, ran)
|
||||
write(*, "((a10), f10.3)") "Kelvin", kel
|
||||
write(*, "((a10), f10.3)") "Celsius", cel
|
||||
write(*, "((a10), f10.3)") "Fahrenheit", fah
|
||||
write(*, "((a10), f10.3)") "Rankine", ran
|
||||
|
||||
contains
|
||||
|
||||
subroutine temp_convert(kelvin, celsius, fahrenheit, rankine)
|
||||
real, intent(in) :: kelvin
|
||||
real, intent(out) :: celsius, fahrenheit, rankine
|
||||
|
||||
celsius = kelvin - 273.15
|
||||
fahrenheit = kelvin * 1.8 - 459.67
|
||||
rankine = kelvin * 1.8
|
||||
|
||||
end subroutine
|
||||
end program
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub convKelvin(temp As Double)
|
||||
Dim f As String = "####.##"
|
||||
Print Using f; temp;
|
||||
Print " degrees Kelvin"
|
||||
Print Using f; temp - 273.15;
|
||||
Print " degrees Celsius"
|
||||
Print Using f; (temp - 273.15) * 1.8 + 32.0;
|
||||
Print " degrees Fahreneit"
|
||||
Print Using f; (temp - 273.15) * 1.8 + 32.0 + 459.67;
|
||||
Print " degrees Rankine"
|
||||
End Sub
|
||||
|
||||
convKelvin(0.0)
|
||||
Print
|
||||
convKelvin(21.0)
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
Public Sub Form_Open()
|
||||
Dim fKelvin As Float
|
||||
|
||||
fKelvin = InputBox("Enter a Kelvin value", "Kelvin converter")
|
||||
|
||||
Print "Kelvin =\t" & Format(Str(fKelvin), "#.00")
|
||||
Print "Celsius =\t" & Format(Str(fKelvin - 273.15), "#.00")
|
||||
Print "Fahrenheit =\t" & Format(Str(fKelvin * 1.8 - 459.67), "#.00")
|
||||
Print "Rankine =\t" & Format(Str(fKelvin * 1.8), "#.00")
|
||||
|
||||
End
|
||||
27
Task/Temperature-conversion/Go/temperature-conversion.go
Normal file
27
Task/Temperature-conversion/Go/temperature-conversion.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Println("Usage: k <Kelvin>")
|
||||
return
|
||||
}
|
||||
k, err := strconv.ParseFloat(os.Args[1], 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if k < 0 {
|
||||
fmt.Println("Kelvin must be >= 0.")
|
||||
return
|
||||
}
|
||||
fmt.Printf("K %.2f\n", k)
|
||||
fmt.Printf("C %.2f\n", k-273.15)
|
||||
fmt.Printf("F %.2f\n", k*9/5-459.67)
|
||||
fmt.Printf("R %.2f\n", k*9/5)
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
class Convert{
|
||||
static void main(String[] args){
|
||||
def c=21.0;
|
||||
println("K "+c)
|
||||
println("C "+k_to_c(c));
|
||||
println("F "+k_to_f(k_to_c(c)));
|
||||
println("R "+k_to_r(c));
|
||||
}
|
||||
static def k_to_c(def k=21.0){return k-273.15;}
|
||||
static def k_to_f(def k=21.0){return ((k*9)/5)+32;}
|
||||
static def k_to_r(def k=21.0){return k*1.8;}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import System.Exit (die)
|
||||
import Control.Monad (mapM_)
|
||||
|
||||
main = do
|
||||
putStrLn "Please enter temperature in kelvin: "
|
||||
input <- getLine
|
||||
let kelvin = read input
|
||||
if kelvin < 0.0
|
||||
then die "Temp cannot be negative"
|
||||
else mapM_ putStrLn $ convert kelvin
|
||||
|
||||
convert :: Double -> [String]
|
||||
convert n = zipWith (++) labels nums
|
||||
where labels = ["kelvin: ", "celcius: ", "farenheit: ", "rankine: "]
|
||||
conversions = [id, subtract 273, subtract 459.67 . (1.8 *), (*1.8)]
|
||||
nums = (show . ($n)) <$> conversions
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
import System.Exit (die)
|
||||
import Control.Monad (mapM_)
|
||||
import Control.Error.Safe (tryAssert, tryRead)
|
||||
import Control.Monad.Trans (liftIO)
|
||||
import Control.Monad.Trans.Except
|
||||
|
||||
main = putStrLn "Please enter temperature in kelvin: " >>
|
||||
runExceptT getTemp >>=
|
||||
\case Right x -> mapM_ putStrLn $ convert x
|
||||
Left err -> die err
|
||||
|
||||
convert :: Double -> [String]
|
||||
convert n = zipWith (++) labels nums
|
||||
where labels = ["kelvin: ", "celcius: ", "farenheit: ", "rankine: "]
|
||||
conversions = [id, subtract 273, subtract 459.67 . (1.8 *), (1.8 *)]
|
||||
nums = (show . ($ n)) <$> conversions
|
||||
|
||||
getTemp :: ExceptT String IO Double
|
||||
getTemp = do
|
||||
t <- liftIO getLine >>= tryRead "Could not read temp"
|
||||
tryAssert "Temp cannot be negative" (t>=0)
|
||||
return t
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
100 INPUT PROMPT "Kelvin degrees: ":K
|
||||
110 PRINT K;TAB(10);"Kelvin is equivalent to"
|
||||
120 PRINT K-273.15;TAB(10);"Degrees Celsius"
|
||||
130 PRINT K*1.8-459.67;TAB(10);"Degrees Fahrenheit"
|
||||
140 PRINT K*1.8;TAB(10);"Degrees Rankine"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
procedure main(A)
|
||||
k := A[1] | 21.00
|
||||
write("K ",k)
|
||||
write("C ",k-273.15)
|
||||
write("R ",r := k*(9.0/5.0))
|
||||
write("F ",r - 459.67)
|
||||
end
|
||||
11
Task/Temperature-conversion/J/temperature-conversion-1.j
Normal file
11
Task/Temperature-conversion/J/temperature-conversion-1.j
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
NB. Temp conversions are all linear polynomials
|
||||
K2K =: 0 1 NB. K = (1 *k) + 0
|
||||
K2C =: _273 1 NB. C = (1 *k) - 273
|
||||
K2F =: _459.67 1.8 NB. F = (1.8*k) - 459.67
|
||||
K2R =: 0 1.8 NB. R = (1.8*k) + 0
|
||||
|
||||
NB. Do all conversions at once (eval
|
||||
NB. polynomials in parallel). This is the
|
||||
NB. numeric matrix J programs would manipulate
|
||||
NB. directly.
|
||||
k2KCFR =: (K2K , K2C , K2F ,: K2R) p./ ]
|
||||
22
Task/Temperature-conversion/J/temperature-conversion-2.j
Normal file
22
Task/Temperature-conversion/J/temperature-conversion-2.j
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
NB. Format matrix for printing & tag each
|
||||
NB. temp with scale, for human legibility
|
||||
fmt =: [: (;:inv"1) 0 _1 |: 'KCFR' ;"0 1"_1 '0.2' 8!:0 ]
|
||||
kcfr =: fmt@k2KCFR
|
||||
|
||||
kcfr 21
|
||||
K 21.00
|
||||
C -252.00
|
||||
F -421.87
|
||||
R 37.80
|
||||
|
||||
kcfr 0 NB. Absolute zero
|
||||
K 0.00
|
||||
C -273.00
|
||||
F -459.67
|
||||
R 0.00
|
||||
|
||||
kcfr 21 100 300 NB. List of temps works fine
|
||||
K 21.00 100.00 300.00
|
||||
C -252.00 -173.00 27.00
|
||||
F -421.87 -279.67 80.33
|
||||
R 37.80 180.00 540.00
|
||||
31
Task/Temperature-conversion/Java/temperature-conversion.java
Normal file
31
Task/Temperature-conversion/Java/temperature-conversion.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
public class TemperatureConversion {
|
||||
public static void main(String args[]) {
|
||||
if (args.length == 1) {
|
||||
try {
|
||||
double kelvin = Double.parseDouble(args[0]);
|
||||
if (kelvin >= 0) {
|
||||
System.out.printf("K %2.2f\n", kelvin);
|
||||
System.out.printf("C %2.2f\n", kelvinToCelsius(kelvin));
|
||||
System.out.printf("F %2.2f\n", kelvinToFahrenheit(kelvin));
|
||||
System.out.printf("R %2.2f\n", kelvinToRankine(kelvin));
|
||||
} else {
|
||||
System.out.printf("%2.2f K is below absolute zero", kelvin);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static double kelvinToCelsius(double k) {
|
||||
return k - 273.15;
|
||||
}
|
||||
|
||||
public static double kelvinToFahrenheit(double k) {
|
||||
return k * 1.8 - 459.67;
|
||||
}
|
||||
|
||||
public static double kelvinToRankine(double k) {
|
||||
return k * 1.8;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
var k2c = k => k - 273.15
|
||||
var k2r = k => k * 1.8
|
||||
var k2f = k => k2r(k) - 459.67
|
||||
|
||||
Number.prototype.toMaxDecimal = function (d) {
|
||||
return +this.toFixed(d) + ''
|
||||
}
|
||||
|
||||
function kCnv(k) {
|
||||
document.write( k,'K° = ', k2c(k).toMaxDecimal(2),'C° = ', k2r(k).toMaxDecimal(2),'R° = ', k2f(k).toMaxDecimal(2),'F°<br>' )
|
||||
}
|
||||
|
||||
kCnv(21)
|
||||
kCnv(295)
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
let kelvinTranslations = k => ['K', 'C', 'F', 'R']
|
||||
.map(x => [x, heatBabel(k, 'K', x)]);
|
||||
|
||||
// heatBabel :: Num -> ScaleName -> ScaleName -> Num
|
||||
let heatBabel = (n, strFromScale, strToScale) => {
|
||||
let ratio = 9 / 5,
|
||||
cels = 273.15,
|
||||
fahr = 459.67,
|
||||
id = x => x,
|
||||
readK = {
|
||||
k: id,
|
||||
c: x => cels + x,
|
||||
f: x => (fahr + x) * ratio,
|
||||
r: x => x / ratio
|
||||
},
|
||||
writeK = {
|
||||
k: id,
|
||||
c: x => x - cels,
|
||||
f: x => (x * ratio) - fahr,
|
||||
r: x => ratio * x
|
||||
};
|
||||
|
||||
return writeK[strToScale.charAt(0).toLowerCase()](
|
||||
readK[strFromScale.charAt(0).toLowerCase()](n)
|
||||
).toFixed(2);
|
||||
};
|
||||
|
||||
|
||||
// TEST
|
||||
return kelvinTranslations(21)
|
||||
.map(([s, n]) => s + (' ' + n)
|
||||
.slice(-10))
|
||||
.join('\n');
|
||||
|
||||
})();
|
||||
37
Task/Temperature-conversion/Jq/temperature-conversion-1.jq
Normal file
37
Task/Temperature-conversion/Jq/temperature-conversion-1.jq
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# round(keep) takes as input any jq (i.e. JSON) number and emits a string.
|
||||
# "keep" is the desired maximum number of numerals after the decimal point,
|
||||
# e.g. 9.999|round(2) => 10.00
|
||||
def round(keep):
|
||||
tostring
|
||||
| (index("e") | if . then . else index("E") end) as $e
|
||||
| if $e then (.[0:$e] | round(keep)) + .[$e+1:]
|
||||
else index(".") as $ix
|
||||
| if $ix == null then .
|
||||
else .[0:$ix + 1] as $head
|
||||
| .[$ix+1:$ix+keep+2] as $tail
|
||||
| if ($tail|length) <= keep then $head + $tail
|
||||
else ($tail | .[length-1:] | tonumber) as $last
|
||||
| if $last < 5 then $head + $tail[0:$tail|length - 1]
|
||||
else (($head + $tail) | length) as $length
|
||||
| ($head[0:-1] + $tail)
|
||||
| (tonumber + (if $head[0:1]=="-" then -5 else 5 end))
|
||||
| tostring
|
||||
| .[0: ($ix+1+length-$length)] + "." + .[length-keep-1:-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
def k2c: . - 273.15;
|
||||
def k2f: . * 1.8 - 459.67;
|
||||
def k2r: . * 1.8;
|
||||
|
||||
# produce a stream
|
||||
def cfr:
|
||||
if . >= 0
|
||||
then "Kelvin: \(.)", "Celsius: \(k2c|round(2))",
|
||||
"Fahrenheit: \(k2f|round(2))", "Rankine: \(k2r|round(2))"
|
||||
else error("cfr: \(.) is an invalid temperature in degrees Kelvin")
|
||||
end;
|
||||
|
||||
cfr
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
$ jq -M -r -f Temperature_conversion.jq
|
||||
21
|
||||
Kelvin: 21
|
||||
Celsius: -252.15
|
||||
Fahrenheit: -421.87
|
||||
Rankine: 37.80
|
||||
|
||||
-1
|
||||
jq: error: cfr: -1 is an invalid temperature in degrees Kelvin
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
cfr(k) = print("Kelvin: $k, ",
|
||||
"Celsius: $(round(k-273.15,2)), ",
|
||||
"Fahrenheit: $(round(k*1.8-459.67,2)), ",
|
||||
"Rankine: $(round(k*1.8,2))")
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// version 1.1.2
|
||||
|
||||
class Kelvin(val degrees: Double) {
|
||||
fun toCelsius() = degrees - 273.15
|
||||
|
||||
fun toFahreneit() = (degrees - 273.15) * 1.8 + 32.0
|
||||
|
||||
fun toRankine() = (degrees - 273.15) * 1.8 + 32.0 + 459.67
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print("Enter the temperature in degrees Kelvin : ")
|
||||
val degrees = readLine()!!.toDouble()
|
||||
val k = Kelvin(degrees)
|
||||
val f = "% 1.2f"
|
||||
println()
|
||||
println("K ${f.format(k.degrees)}\n")
|
||||
println("C ${f.format(k.toCelsius())}\n")
|
||||
println("F ${f.format(k.toFahreneit())}\n")
|
||||
println("R ${f.format(k.toRankine())}")
|
||||
}
|
||||
12
Task/Temperature-conversion/LIL/temperature-conversion.lil
Normal file
12
Task/Temperature-conversion/LIL/temperature-conversion.lil
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Temperature conversion, in LIL
|
||||
func kToc k {expr $k - 273.15}
|
||||
func kTor k {expr $k / 5.0 * 9.0}
|
||||
func kTof k {expr [kTor $k] - 469.67}
|
||||
|
||||
write "Enter kelvin temperatures or just enter to quit: "
|
||||
for {set k [readline]} {![streq $k {}]} {set k [readline]} {
|
||||
print "Kelvin: $k"
|
||||
print "Celsius: [kToc $k]"
|
||||
print "Fahrenheit: [kTof $k]"
|
||||
print "Rankine: [kTor $k]"
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{def to-celsius {lambda {:k} {- :k 273.15}}}
|
||||
-> to-celsius
|
||||
|
||||
{def to-farenheit {lambda {:k} {- {* :k 1.8} 459.67}}}
|
||||
-> to-farenheit
|
||||
|
||||
{def to-rankine {lambda {:k} {* :k 1.8}}}
|
||||
-> to-rankine
|
||||
|
||||
{def format {lambda {:n} {/ {round {* :n 100}} 100}}}
|
||||
-> format
|
||||
|
||||
{def kelvinConversion
|
||||
{lambda {:k}
|
||||
kelvin is equivalent to:{br}
|
||||
{format {to-celsius :k}} celsius{br}
|
||||
{format {to-farenheit :k}} farenheit{br}
|
||||
{format {to-rankine :k}} rankine}}
|
||||
-> kelvinConversion
|
||||
|
||||
{kelvinConversion 21}
|
||||
->
|
||||
kelvin is equivalent to:
|
||||
-252.15 celsius
|
||||
-421.87 farenheit
|
||||
37.8 rankine
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
define tempconverter(temp, kind) => {
|
||||
|
||||
local(
|
||||
_temp = decimal(#temp),
|
||||
convertratio = 1.8,
|
||||
k_c = 273.15,
|
||||
r_f = 459.67,
|
||||
k,c,r,f
|
||||
)
|
||||
|
||||
match(#kind) => {
|
||||
case('k')
|
||||
#k = #_temp
|
||||
#c = -#k_c + #k
|
||||
#r = #k * #convertratio
|
||||
#f = -#r_f + #r
|
||||
case('c')
|
||||
#c = #_temp
|
||||
#k = #k_c + #c
|
||||
#r = #k * #convertratio
|
||||
#f = -#r_f + #r
|
||||
case('r')
|
||||
#r = #_temp
|
||||
#f = -#r_f + #r
|
||||
#k = #r / #convertratio
|
||||
#c = -#k_c + #k
|
||||
case('f')
|
||||
#f = #_temp
|
||||
#r = #r_f + #f
|
||||
#k = #r / #convertratio
|
||||
#c = -#k_c + #k
|
||||
case
|
||||
return 'Something wrong'
|
||||
}
|
||||
|
||||
return ('K = ' + #k -> asstring(-precision = 2) +
|
||||
' C = ' + #c -> asstring(-precision = 2) +
|
||||
' R = ' + #r -> asstring(-precision = 2) +
|
||||
' F = ' + #f -> asstring(-precision = 2)
|
||||
)
|
||||
}
|
||||
|
||||
tempconverter(21, 'k')
|
||||
'<br />'
|
||||
tempconverter(21, 'c')
|
||||
'<br />'
|
||||
tempconverter(-41, 'c')
|
||||
'<br />'
|
||||
tempconverter(37.80, 'r')
|
||||
'<br />'
|
||||
tempconverter(69.80, 'f')
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Do
|
||||
Input "Kelvin degrees (>=0): ";K
|
||||
Loop Until (K >= 0)
|
||||
|
||||
Print "K = ";K
|
||||
Print "C = ";(K - 273.15)
|
||||
Print "F = ";(K * 1.8 - 459.67)
|
||||
Print "R = ";(K * 1.8)
|
||||
End
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
function convertDegrees k
|
||||
put k/5 * 9 into r
|
||||
put k - 273.15 into c
|
||||
put r - 459.67 into f
|
||||
return k,r,c,f
|
||||
end convertDegrees
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
put convertDegrees(21.00) into tTemp
|
||||
put item 1 of tTemp into temperature["Kelvin"]
|
||||
put item 2 of tTemp into temperature["Rankine"]
|
||||
put item 3 of tTemp into temperature["Celsius"]
|
||||
put item 4 of tTemp into temperature["Fahrenheit"]
|
||||
combine temperature using comma and colon
|
||||
put temperature
|
||||
|
||||
-- Celsius:-252.15,Fahrenheit:-421.87,Kelvin:21.00,Rankine:37.8
|
||||
13
Task/Temperature-conversion/Lua/temperature-conversion.lua
Normal file
13
Task/Temperature-conversion/Lua/temperature-conversion.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function convert_temp(k)
|
||||
local c = k - 273.15
|
||||
local r = k * 1.8
|
||||
local f = r - 459.67
|
||||
return k, c, r, f
|
||||
end
|
||||
|
||||
print(string.format([[
|
||||
Kelvin: %.2f K
|
||||
Celcius: %.2f °C
|
||||
Rankine: %.2f °R
|
||||
Fahrenheit: %.2f °F
|
||||
]],convert_temp(21.0)))
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
fun KtoC n = n - 273.15;
|
||||
fun KtoF n = n * 1.8 - 459.67;
|
||||
fun KtoR n = n * 1.8;
|
||||
val K = argv 0;
|
||||
|
||||
if K = false then
|
||||
println "mlite -f temcon.m <temp>"
|
||||
else
|
||||
let
|
||||
val K = ston K
|
||||
in
|
||||
print "Kelvin: "; println K;
|
||||
print "Celcius: "; println ` KtoC K;
|
||||
print "Fahrenheit: "; println ` KtoF K;
|
||||
print "Rankine: "; println ` KtoR K
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
tempConvert := proc(k)
|
||||
seq(printf("%c: %.2f\n", StringTools[UpperCase](substring(i, 1)), convert(k, temperature, kelvin, i)), i in [kelvin, Celsius, Fahrenheit, Rankine]);
|
||||
return NULL;
|
||||
end proc:
|
||||
|
||||
tempConvert(21);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
tempConvert[t_] := # -> Thread@UnitConvert[#,{"DegreesFahrenheit", "DegreesCelsius", "DegreesRankine"}]&@Quantity[N@t, "Kelvins"]
|
||||
tempConvert[21]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(
|
||||
((float) (273.15 -) (9 5 / * 459.67 -) (9 5 / *)) cleave
|
||||
() 'cons 4 times "K $1\nC $2\nF $3\nR $4" swap % puts!
|
||||
) :convert
|
||||
|
||||
21 convert
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fromKelvin = function(temp)
|
||||
print temp + " degrees in Kelvin is:"
|
||||
Celsius = temp - 273.15
|
||||
print Celsius + " degrees Celsius"
|
||||
Fahrenheit = round(Celsius * 9/5 + 32,2)
|
||||
print Fahrenheit + " degrees Fahrenheit"
|
||||
Rankine = Fahrenheit + 459.67
|
||||
print Rankine + " degrees Rankine"
|
||||
end function
|
||||
|
||||
temp = input("Enter a temperature in Kelvin: ")
|
||||
fromKelvin temp.val
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
float: kelvin;
|
||||
|
||||
var float: celsius;
|
||||
var float: fahrenheit;
|
||||
var float: rankine;
|
||||
|
||||
constraint celsius == kelvin - 273.15;
|
||||
constraint fahrenheit == celsius * 1.8 + 32;
|
||||
constraint rankine == fahrenheit + 459.67;
|
||||
solve satisfy;
|
||||
|
||||
output ["K \(kelvin)\n", "C \(celsius)\n", "F \(fahrenheit)\n", "R \(rankine)\n"];
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
% while true
|
||||
... print "K ? "
|
||||
... k = float(input())
|
||||
...
|
||||
... println format("%g Kelvin = %g Celsius = %g Fahrenheit = %g Rankine degrees.", k, k-273.15, k*1.8-459.67, k*1.8)
|
||||
... end
|
||||
K ? 21
|
||||
21.0000 Kelvin = -252.150 Celsius = -421.870 Fahrenheit = 37.8000 Rankine degrees.
|
||||
K ? 222.2
|
||||
222.200 Kelvin = -50.9500 Celsius = -59.7100 Fahrenheit = 399.960 Rankine degrees.
|
||||
K ?
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols
|
||||
|
||||
numeric digits 20
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/*
|
||||
+ Kelvin Celsius Fahrenheit Rankine Delisle Newton Réaumur Rømer
|
||||
K T T-273.15 T*9/5-459.67 T*9/5 (373.15-T)*3/2 (T-273.15)*33/100 (T-273.15)*4/5 (T-273.15)*21/40+7.5
|
||||
C T+273.15 T T*9/5+32 (T+273.15)*9/5 (100-T)*3/2 T*33/100 T*4/5 T*21/40+7.5
|
||||
F (T+459.67)*5/9 (T-32)*5/9 T T+459.67 (212-T)*5/6 (T-32)*11/60 (T-32)*4/9 (T-32)*7/24+7.5
|
||||
R T*5/9 (T-491.67)*5/9 T-459.67 T (671.67-T)*5/6 (T-491.67)*11/60 (T-491.67)*4/9 (T-491.67)*7/24+7.5
|
||||
De 373.15-T*2/3 100-T*2/3 212-T*6/5 671.67-T*6/5 T 33-T*11/50 80-T*8/15 60-T*7/20
|
||||
N T*100/33+273.15 T*100/33 T*60/11+32 T*60/11+491.67 (33-T)*50/11 T T*80/33 T*35/22+7.5
|
||||
Ré T*5/4+273.15 T*5/4 T*9/4+32 T*9/4+491.67 (80-T)*15/8 T*33/80 T T*21/32+7.5
|
||||
Rø (T-7.5)*40/21+273.15 (T-7.5)*40/21 (T-7.5)*24/7+32 (T-7.5)*24/7+491.67 (60-T)*20/7 (T-7.5)*22/35 (T-7.5)*32/21 T
|
||||
*/
|
||||
method temperatureConversion(scaleFrom, scaleTo, T) public static
|
||||
|
||||
parse 'KELVIN CELSIUS FAHRENHEIT RANKINE DELISLE NEWTON REAUMUR ROEMER' -
|
||||
KELVIN CELSIUS FAHRENHEIT RANKINE DELISLE NEWTON REAUMUR ROEMER .
|
||||
scaleFrom = scaleFrom.upper()
|
||||
scaleTo = scaleTo.upper()
|
||||
select label sF case scaleFrom
|
||||
when KELVIN then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = T
|
||||
when CELSIUS then val = T - 273.15
|
||||
when FAHRENHEIT then val = T * 9 / 5 - 459.67
|
||||
when RANKINE then val = T * 9 / 5
|
||||
when DELISLE then val = (373.15 - T) * 3 / 2
|
||||
when NEWTON then val = (T - 273.15) * 33 / 100
|
||||
when REAUMUR then val = (T - 273.15) * 4 / 5
|
||||
when ROEMER then val = (T - 273.15) * 21 / 40 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when CELSIUS then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = T + 273.15
|
||||
when CELSIUS then val = T
|
||||
when FAHRENHEIT then val = T * 9 / 5 + 32
|
||||
when RANKINE then val = (T + 273.15) * 9 / 5
|
||||
when DELISLE then val = (100 - T) * 3 / 2
|
||||
when NEWTON then val = T * 33 / 100
|
||||
when REAUMUR then val = T * 4 / 5
|
||||
when ROEMER then val = T * 21 / 40 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when FAHRENHEIT then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = (T + 459.67) * 5 / 9
|
||||
when CELSIUS then val = (T - 32) * 5 / 9
|
||||
when FAHRENHEIT then val = T
|
||||
when RANKINE then val = T + 459.67
|
||||
when DELISLE then val = (212 - T) * 5 / 6
|
||||
when NEWTON then val = (T - 32) * 11 / 60
|
||||
when REAUMUR then val = (T - 32) * 4 / 9
|
||||
when ROEMER then val = (T - 32) * 7 / 24 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when RANKINE then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = T * 5 / 9
|
||||
when CELSIUS then val = (T - 491.67) * 5 / 9
|
||||
when FAHRENHEIT then val = T - 459.67
|
||||
when RANKINE then val = T
|
||||
when DELISLE then val = (671.67 - T) * 5 / 6
|
||||
when NEWTON then val = (T - 491.67) * 11 / 60
|
||||
when REAUMUR then val = (T - 491.67) * 4 / 9
|
||||
when ROEMER then val = (T - 491.67) * 7 / 24 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when DELISLE then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = 373.15 - T * 2 / 3
|
||||
when CELSIUS then val = 100 - T * 2 / 3
|
||||
when FAHRENHEIT then val = 212 - T * 6 / 5
|
||||
when RANKINE then val = 671.67 - T * 6 / 5
|
||||
when DELISLE then val = T
|
||||
when NEWTON then val = 33 - T * 11 / 50
|
||||
when REAUMUR then val = 80 - T * 8 / 15
|
||||
when ROEMER then val = 60 - T * 7 / 20
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when NEWTON then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = T * 100 / 33 + 273.15
|
||||
when CELSIUS then val = T * 100 / 33
|
||||
when FAHRENHEIT then val = T * 60 / 11 + 32
|
||||
when RANKINE then val = T * 60 / 11 + 491.67
|
||||
when DELISLE then val = (33 - T) * 50 / 11
|
||||
when NEWTON then val = T
|
||||
when REAUMUR then val = T * 80 / 33
|
||||
when ROEMER then val = T * 35 / 22 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when REAUMUR then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = T * 5 / 4 + 273.15
|
||||
when CELSIUS then val = T * 5 / 4
|
||||
when FAHRENHEIT then val = T * 9 / 4 + 32
|
||||
when RANKINE then val = T * 9 / 4 + 491.67
|
||||
when DELISLE then val = (80 - T) * 15 / 8
|
||||
when NEWTON then val = T * 33 / 80
|
||||
when REAUMUR then val = T
|
||||
when ROEMER then val = T * 21 / 32 + 7.5
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
when ROEMER then do
|
||||
select case scaleTo
|
||||
when KELVIN then val = (T - 7.5) * 40 / 21 + 273.15
|
||||
when CELSIUS then val = (T - 7.5) * 40 / 21
|
||||
when FAHRENHEIT then val = (T - 7.5) * 24 / 7 + 32
|
||||
when RANKINE then val = (T - 7.5) * 24 / 7 + 491.67
|
||||
when DELISLE then val = (60 - T) * 20 / 7
|
||||
when NEWTON then val = (T - 7.5) * 22 / 35
|
||||
when REAUMUR then val = (T - 7.5) * 32 / 21
|
||||
when ROEMER then val = T
|
||||
otherwise signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end
|
||||
end
|
||||
otherwise
|
||||
signal IllegalArgumentException(scaleFrom',' scaleTo',' T)
|
||||
end sF
|
||||
|
||||
return val
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) public static
|
||||
|
||||
tlist = [ -
|
||||
/* C....... F....... K....... R.......*/ -
|
||||
' 5500.00 9932.00 5773.15 10391.67', -
|
||||
' 300.00 572.00 573.15 1031.67', -
|
||||
' 200.00 392.00 473.15 851.67', -
|
||||
' 100.00 212.00 373.15 671.67', -
|
||||
' 37.00 98.60 310.15 558.27', -
|
||||
' 0.00 32.00 273.15 491.67', -
|
||||
' -100.00 -148.00 173.15 311.67', -
|
||||
' -200.00 -328.00 73.15 131.67', -
|
||||
' -252.15 -421.87 21.00 37.80', -
|
||||
' -273.15 -459.67 0.00 0.00' -
|
||||
]
|
||||
|
||||
parse 'CELSIUS FAHRENHEIT KELVIN RANKINE' CELSIUS FAHRENHEIT KELVIN RANKINE .
|
||||
loop temp over tlist
|
||||
parse temp ttC ttF ttK ttR .
|
||||
say ' C....... F....... K....... R.......'
|
||||
say 'C ' -
|
||||
temperatureConversion(CELSIUS, CELSIUS, ttC).format(5, 2) -
|
||||
temperatureConversion(CELSIUS, FAHRENHEIT, ttC).format(5, 2) -
|
||||
temperatureConversion(CELSIUS, KELVIN, ttC).format(5, 2) -
|
||||
temperatureConversion(CELSIUS, RANKINE, ttC).format(5, 2)
|
||||
|
||||
say 'F ' -
|
||||
temperatureConversion(FAHRENHEIT, CELSIUS, ttF).format(5, 2) -
|
||||
temperatureConversion(FAHRENHEIT, FAHRENHEIT, ttF).format(5, 2) -
|
||||
temperatureConversion(FAHRENHEIT, KELVIN, ttF).format(5, 2) -
|
||||
temperatureConversion(FAHRENHEIT, RANKINE, ttF).format(5, 2)
|
||||
|
||||
say 'K ' -
|
||||
temperatureConversion(KELVIN, CELSIUS, ttK).format(5, 2) -
|
||||
temperatureConversion(KELVIN, FAHRENHEIT, ttK).format(5, 2) -
|
||||
temperatureConversion(KELVIN, KELVIN, ttK).format(5, 2) -
|
||||
temperatureConversion(KELVIN, RANKINE, ttK).format(5, 2)
|
||||
|
||||
say 'R ' -
|
||||
temperatureConversion(RANKINE, CELSIUS, ttR).format(5, 2) -
|
||||
temperatureConversion(RANKINE, FAHRENHEIT, ttR).format(5, 2) -
|
||||
temperatureConversion(RANKINE, KELVIN, ttR).format(5, 2) -
|
||||
temperatureConversion(RANKINE, RANKINE, ttR).format(5, 2)
|
||||
say
|
||||
end temp
|
||||
|
||||
return
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
func KtoC(k : float) -> float { k - 273.15 }
|
||||
func KtoF(k : float) -> float { k * 1.8 - 459.67 }
|
||||
func KtoR(k : float) -> float { k * 1.8 }
|
||||
|
||||
func convertK(k : float) -> int {
|
||||
prints("K " + k + "\n");
|
||||
prints("C " + KtoC(k) + "\n");
|
||||
prints("F " + KtoF(k) + "\n");
|
||||
prints("R " + KtoR(k) + "\n");
|
||||
0
|
||||
}
|
||||
|
||||
func main(k : float) -> int {
|
||||
convertK(k);
|
||||
0
|
||||
}
|
||||
21
Task/Temperature-conversion/NewLISP/temperature-conversion.l
Normal file
21
Task/Temperature-conversion/NewLISP/temperature-conversion.l
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(define (to-celsius k)
|
||||
(- k 273.15)
|
||||
)
|
||||
|
||||
(define (to-fahrenheit k)
|
||||
(- (* k 1.8) 459.67)
|
||||
)
|
||||
|
||||
(define (to-rankine k)
|
||||
(* k 1.8)
|
||||
)
|
||||
|
||||
(define (kelvinConversion k)
|
||||
(if (number? k)
|
||||
(println k " kelvin is equivalent to:\n"
|
||||
(to-celsius k) " celsius\n"
|
||||
(to-fahrenheit k) " fahrenheit\n"
|
||||
(to-rankine k) " rankine")
|
||||
(println "Please enter a number only, with no º or letter. ")
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import rdstdin, strutils, strfmt
|
||||
|
||||
while true:
|
||||
let k = parseFloat readLineFromStdin "K ? "
|
||||
echo "{:g} Kelvin = {:g} Celsius = {:g} Fahrenheit = {:g} Rankine degrees".fmt(
|
||||
k, k - 273.15, k * 1.8 - 459.67, k * 1.8)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
let print_temp s t =
|
||||
print_string s;
|
||||
print_endline (string_of_float t);;
|
||||
|
||||
let kelvin_to_celsius k =
|
||||
k -. 273.15;;
|
||||
|
||||
let kelvin_to_fahrenheit k =
|
||||
(kelvin_to_celsius k)*. 9./.5. +. 32.00;;
|
||||
|
||||
let kelvin_to_rankine k =
|
||||
(kelvin_to_celsius k)*. 9./.5. +. 491.67;;
|
||||
|
||||
|
||||
print_endline "Enter a temperature in Kelvin please:";
|
||||
let k = read_float () in
|
||||
print_temp "K " k;
|
||||
print_temp "C " (kelvin_to_celsius k);
|
||||
print_temp "F " (kelvin_to_fahrenheit k);
|
||||
print_temp "R " (kelvin_to_rankine k);;
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
class Temperature {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
k := System.IO.Console->ReadString()->ToFloat();
|
||||
c := KelvinToCelsius(k);
|
||||
f := KelvinToFahrenheit(k);
|
||||
r := KelvinToRankine(k);
|
||||
|
||||
"K: {$k}"->PrintLine();
|
||||
"C: {$c}"->PrintLine();
|
||||
"F: {$f}"->PrintLine();
|
||||
"R: {$r}"->PrintLine();
|
||||
}
|
||||
|
||||
function : KelvinToCelsius(k : Float) ~ Float {
|
||||
return k - 273.15;
|
||||
}
|
||||
|
||||
function : KelvinToFahrenheit(k : Float) ~ Float {
|
||||
return k * 1.8 - 459.67;
|
||||
}
|
||||
|
||||
function : KelvinToRankine(k : Float) ~ Float {
|
||||
return k * 1.8;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
if(argc > 1)
|
||||
{
|
||||
NSString *arg1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
|
||||
// encoding shouldn't matter in this case
|
||||
double kelvin = [arg1 doubleValue];
|
||||
|
||||
NSLog(@"K %.2f",kelvin);
|
||||
NSLog(@"C %.2f\n", kelvin - 273.15);
|
||||
NSLog(@"F %.2f\n", (kelvin * 1.8) - 459.67);
|
||||
NSLog(@"R %.2f", kelvin * 1.8);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
: kelvinToCelsius 273.15 - ;
|
||||
: kelvinToFahrenheit 1.8 * 459.67 - ;
|
||||
: kelvinToRankine 1.8 * ;
|
||||
|
||||
: testTemp(n)
|
||||
n kelvinToCelsius println
|
||||
n kelvinToFahrenheit println
|
||||
n kelvinToRankine println ;
|
||||
|
|
@ -0,0 +1 @@
|
|||
f(x)=[x,x-273.15,1.8*x-459.67,1.8*x]
|
||||
18
Task/Temperature-conversion/PHP/temperature-conversion.php
Normal file
18
Task/Temperature-conversion/PHP/temperature-conversion.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
while (true) {
|
||||
echo "\nEnter a value in kelvin (q to quit): ";
|
||||
if ($kelvin = trim(fgets(STDIN))) {
|
||||
if ($kelvin == 'q') {
|
||||
echo 'quitting';
|
||||
break;
|
||||
}
|
||||
if (is_numeric($kelvin)) {
|
||||
$kelvin = floatVal($kelvin);
|
||||
if ($kelvin >= 0) {
|
||||
printf(" K %2.2f\n", $kelvin);
|
||||
printf(" C %2.2f\n", $kelvin - 273.15);
|
||||
printf(" F %2.2f\n", $kelvin * 1.8 - 459.67);
|
||||
printf(" R %2.2f\n", $kelvin * 1.8);
|
||||
} else printf(" %2.2f K is below absolute zero\n", $kelvin);
|
||||
}
|
||||
}
|
||||
}
|
||||
148
Task/Temperature-conversion/PL-I/temperature-conversion.pli
Normal file
148
Task/Temperature-conversion/PL-I/temperature-conversion.pli
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
*process source attributes xref;
|
||||
/* PL/I **************************************************************
|
||||
* 15.08.2013 Walter Pachl translated from NetRexx
|
||||
* temperatures below 0K are considered invalid
|
||||
*********************************************************************/
|
||||
temperature: Proc Options(main);
|
||||
Dcl sysin record Input;
|
||||
On Endfile(sysin) Goto eoj;
|
||||
On Record(sysin);
|
||||
Dcl 1 dat,
|
||||
2 t Pic'SSSS9V.99',
|
||||
2 * char( 1),
|
||||
2 from char(10),
|
||||
2 * char( 1),
|
||||
2 to char(10);
|
||||
Do Forever;
|
||||
Read File(sysin) Into(dat);
|
||||
If tc(t,from,'KELVIN')<0 Then
|
||||
Put Edit('Input (',t,from,') invalid. Below absolute zero')
|
||||
(Skip,a,f(8,2),x(1),a,a);
|
||||
Else
|
||||
Put edit(t,from,' -> ',tc(t,from,to),to)
|
||||
(skip,f(8,2),x(1),a(10),a,f(8,2),x(1),a(10));
|
||||
End;
|
||||
eoj: Return;
|
||||
|
||||
tc: Procedure(T,scaleFrom,scaleTo) Returns(Dec Fixed(8,2));
|
||||
Dcl t Pic'SSSS9V.99';
|
||||
Dcl (val) Dec Fixed(8,2);
|
||||
Dcl (scaleFrom,scaleTo) Char(10);
|
||||
select(scaleFrom);
|
||||
when('KELVIN ') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = T;
|
||||
when('CELSIUS ') val = T - 273.15;
|
||||
when('FAHRENHEIT') val = T * 9 / 5 - 459.67;
|
||||
when('RANKINE ') val = T * 9 / 5;
|
||||
when('DELISLE ') val = (373.15 - T) * 3 / 2;
|
||||
when('NEWTON ') val = (T - 273.15) * 33 / 100;
|
||||
when('REAUMUR ') val = (T - 273.15) * 4 / 5;
|
||||
when('ROEMER ') val = (T - 273.15) * 21 / 40 + 7.5;
|
||||
otherwise Do;
|
||||
Put Edit('scaleTo=',scaleTo)(Skip,a,a);
|
||||
Call err(1);
|
||||
End;
|
||||
end;
|
||||
end;
|
||||
when('CELSIUS') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = T + 273.15;
|
||||
when('CELSIUS ') val = T;
|
||||
when('FAHRENHEIT') val = T * 9 / 5 + 32;
|
||||
when('RANKINE ') val = (T + 273.15) * 9 / 5;
|
||||
when('DELISLE ') val = (100 - T) * 3 / 2;
|
||||
when('NEWTON ') val = T * 33 / 100;
|
||||
when('REAUMUR ') val = T * 4 / 5;
|
||||
when('ROEMER ') val = T * 21 / 40 + 7.5;
|
||||
otherwise Call err(2);
|
||||
end;
|
||||
end;
|
||||
when('FAHRENHEIT') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = (T + 459.67) * 5 / 9;
|
||||
when('CELSIUS ') val = (T - 32) * 5 / 9;
|
||||
when('FAHRENHEIT') val = T;
|
||||
when('RANKINE ') val = T + 459.67;
|
||||
when('DELISLE ') val = (212 - T) * 5 / 6;
|
||||
when('NEWTON ') val = (T - 32) * 11 / 60;
|
||||
when('REAUMUR ') val = (T - 32) * 4 / 9;
|
||||
when('ROEMER ') val = (T - 32) * 7 / 24 + 7.5;
|
||||
otherwise Call err(3);
|
||||
end;
|
||||
end;
|
||||
when('RANKINE') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = T * 5 / 9;
|
||||
when('CELSIUS ') val = (T - 491.67) * 5 / 9;
|
||||
when('FAHRENHEIT') val = T - 459.67;
|
||||
when('RANKINE ') val = T;
|
||||
when('DELISLE ') val = (671.67 - T) * 5 / 6;
|
||||
when('NEWTON ') val = (T - 491.67) * 11 / 60;
|
||||
when('REAUMUR ') val = (T - 491.67) * 4 / 9;
|
||||
when('ROEMER ') val = (T - 491.67) * 7 / 24 + 7.5;
|
||||
otherwise Call err(4);
|
||||
end;
|
||||
end;
|
||||
when('DELISLE') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = 373.15 - T * 2 / 3;
|
||||
when('CELSIUS ') val = 100 - T * 2 / 3;
|
||||
when('FAHRENHEIT') val = 212 - T * 6 / 5;
|
||||
when('RANKINE ') val = 671.67 - T * 6 / 5;
|
||||
when('DELISLE ') val = T;
|
||||
when('NEWTON ') val = 33 - T * 11 / 50;
|
||||
when('REAUMUR ') val = 80 - T * 8 / 15;
|
||||
when('ROEMER ') val = 60 - T * 7 / 20;
|
||||
otherwise Call err(5);
|
||||
end;
|
||||
end;
|
||||
when('NEWTON') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = T * 100 / 33 + 273.15;
|
||||
when('CELSIUS ') val = T * 100 / 33;
|
||||
when('FAHRENHEIT') val = T * 60 / 11 + 32;
|
||||
when('RANKINE ') val = T * 60 / 11 + 491.67;
|
||||
when('DELISLE ') val = (33 - T) * 50 / 11;
|
||||
when('NEWTON ') val = T;
|
||||
when('REAUMUR ') val = T * 80 / 33;
|
||||
when('ROEMER ') val = T * 35 / 22 + 7.5;
|
||||
otherwise Call err(6);
|
||||
end;
|
||||
end;
|
||||
when('REAUMUR') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = T * 5 / 4 + 273.15;
|
||||
when('CELSIUS ') val = T * 5 / 4;
|
||||
when('FAHRENHEIT') val = T * 9 / 4 + 32;
|
||||
when('RANKINE ') val = T * 9 / 4 + 491.67;
|
||||
when('DELISLE ') val = (80 - T) * 15 / 8;
|
||||
when('NEWTON ') val = T * 33 / 80;
|
||||
when('REAUMUR ') val = T;
|
||||
when('ROEMER ') val = T * 21 / 32 + 7.5;
|
||||
otherwise Call err(7);
|
||||
end;
|
||||
end;
|
||||
when('ROEMER') do;
|
||||
select(scaleTo);
|
||||
when('KELVIN ') val = (T - 7.5) * 40 / 21 + 273.15;
|
||||
when('CELSIUS ') val = (T - 7.5) * 40 / 21;
|
||||
when('FAHRENHEIT') val = (T - 7.5) * 24 / 7 + 32;
|
||||
when('RANKINE ') val = (T - 7.5) * 24 / 7 + 491.67;
|
||||
when('DELISLE ') val = (60 - T) * 20 / 7;
|
||||
when('NEWTON ') val = (T - 7.5) * 22 / 35;
|
||||
when('REAUMUR ') val = (T - 7.5) * 32 / 21;
|
||||
when('ROEMER ') val = T;
|
||||
otherwise Call err(8);
|
||||
end;
|
||||
end;
|
||||
otherwise Call err(9);
|
||||
end;
|
||||
return(val);
|
||||
err: Proc(e);
|
||||
Dcl e Dec fixed(1);
|
||||
Put Edit('error ',e,' invalid input')(Skip,a,f(1),a);
|
||||
val=0;
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
program TemperatureConvert;
|
||||
|
||||
type
|
||||
TemperatureType = (C, F, K, R);
|
||||
|
||||
var
|
||||
kelvin: real;
|
||||
|
||||
function ConvertTemperature(temperature: real; fromType, toType: TemperatureType): real;
|
||||
|
||||
var
|
||||
initial, result: real;
|
||||
|
||||
begin
|
||||
(* We are going to first convert whatever we're given into Celsius.
|
||||
Then we'll convert that into whatever we're asked to convert into.
|
||||
Maybe not the most efficient way to do this, but easy to understand
|
||||
and should make it easier to add any additional temperature units. *)
|
||||
if fromType <> toType then
|
||||
begin
|
||||
case fromType of (* first convert the temperature into Celsius *)
|
||||
C:
|
||||
initial := temperature;
|
||||
F:
|
||||
initial := (temperature - 32) / 1.8;
|
||||
K:
|
||||
initial := temperature - 273.15;
|
||||
R:
|
||||
initial := (temperature - 491.67) / 1.8;
|
||||
end;
|
||||
case toType of (* now convert from Celsius into whatever degree type was asked for *)
|
||||
C:
|
||||
result := initial;
|
||||
F:
|
||||
result := (initial * 1.8) + 32;
|
||||
K:
|
||||
result := initial + 273.15;
|
||||
R:
|
||||
result := (initial * 1.8) + 491.67;
|
||||
end;
|
||||
end
|
||||
else (* no point doing all that math if we're asked to convert from and to the same type *)
|
||||
result := temperature;
|
||||
ConvertTemperature := result;
|
||||
end;
|
||||
|
||||
begin
|
||||
write('Temperature to convert (in kelvins): ');
|
||||
readln(kelvin);
|
||||
writeln(kelvin : 3 : 2, ' in kelvins is ');
|
||||
writeln(' ', ConvertTemperature(kelvin, K, C) : 3 : 2, ' in degrees Celsius.');
|
||||
writeln(' ', ConvertTemperature(kelvin, K, F) : 3 : 2, ' in degrees Fahrenheit.');
|
||||
writeln(' ', ConvertTemperature(kelvin, K, R) : 3 : 2, ' in degrees Rankine.');
|
||||
end.
|
||||
13
Task/Temperature-conversion/Perl/temperature-conversion.pl
Normal file
13
Task/Temperature-conversion/Perl/temperature-conversion.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
my %scale = (
|
||||
Celcius => { factor => 1 , offset => -273.15 },
|
||||
Rankine => { factor => 1.8, offset => 0 },
|
||||
Fahrenheit => { factor => 1.8, offset => -459.67 },
|
||||
);
|
||||
|
||||
print "Enter a temperature in Kelvin: ";
|
||||
chomp(my $kelvin = <STDIN>);
|
||||
die "No such temperature!\n" unless $kelvin > 0;
|
||||
|
||||
foreach (sort keys %scale) {
|
||||
printf "%12s:%8.2f\n", $_, $kelvin * $scale{$_}{factor} + $scale{$_}{offset};
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
-->
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">K</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Enter temperature in Kelvin >=0: "</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e307</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" Kelvin: %5.2f\n Celsius: %5.2f\nFahrenheit: %5.2f\n Rankine: %5.2f\n\n"</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #0000FF;">{</span><span style="color: #000000;">K</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">K</span><span style="color: #0000FF;">-</span><span style="color: #000000;">273.15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">K</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1.8</span><span style="color: #0000FF;">-</span><span style="color: #000000;">459.67</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">K</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1.8</span><span style="color: #0000FF;">})</span>
|
||||
<!--
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(scl 2)
|
||||
|
||||
(de convertKelvin (Kelvin)
|
||||
(for X
|
||||
(quote
|
||||
(K . prog)
|
||||
(C (K) (- K 273.15))
|
||||
(F (K) (- (*/ K 1.8 1.0) 459.67))
|
||||
(R (K) (*/ K 1.8 1.0)) )
|
||||
(tab (-3 8)
|
||||
(car X)
|
||||
(format ((cdr X) Kelvin) *Scl) ) ) )
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue