Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -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
|
||||
|
|
@ -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,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,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
|
||||
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
|
||||
|
|
@ -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,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,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.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
while '' ne my $answer = prompt 'Temperature: ' {
|
||||
while my $answer = prompt 'Temperature: ' {
|
||||
my $k = do given $answer {
|
||||
when s/:i C $// { $_ + 273.15 }
|
||||
when s/:i F $// { ($_ + 459.67) / 1.8 }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
function temp($k){
|
||||
try{
|
||||
$c = $k - 273.15
|
||||
$r = $k / 5 * 9
|
||||
$f = $r - 459.67
|
||||
} catch {
|
||||
Write-host "Input error."
|
||||
return
|
||||
}
|
||||
|
||||
Write-host ""
|
||||
Write-host " TEMP (Kelvin) : " $k
|
||||
Write-host " TEMP (Celsius) : " $c
|
||||
Write-host " TEMP (Fahrenheit): " $f
|
||||
Write-host " TEMP (Rankine) : " $r
|
||||
Write-host ""
|
||||
|
||||
}
|
||||
|
||||
$input=Read-host "Enter a temperature in Kelvin"
|
||||
temp $input
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Procedure.d Kelvin2Celsius(tK.d) : ProcedureReturn tK-273.15 : EndProcedure
|
||||
Procedure.d Kelvin2Fahrenheit(tK.d) : ProcedureReturn tK*1.8-459.67 : EndProcedure
|
||||
Procedure.d Kelvin2Rankine(tK.d) : ProcedureReturn tK*1.8 : EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
Repeat
|
||||
Print("Temperatur Kelvin? ") : Kelvin.d = ValD(Input())
|
||||
PrintN("Conversion:")
|
||||
PrintN(#TAB$+"Celsius "+#TAB$+RSet(StrD(Kelvin2Celsius(Kelvin),2),8,Chr(32)))
|
||||
PrintN(#TAB$+"Fahrenheit"+#TAB$+RSet(StrD(Kelvin2Fahrenheit(Kelvin),2),8,Chr(32)))
|
||||
PrintN(#TAB$+"Rankine "+#TAB$+RSet(StrD(Kelvin2Rankine(Kelvin),2),8,Chr(32)))
|
||||
PrintN("ESC = End.")
|
||||
Repeat
|
||||
k$=Inkey() : Delay(50) : If RawKey()=#ESC : End : EndIf
|
||||
Until RawKey()
|
||||
ForEver
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
WScript.StdOut.Write "Enter the temperature in Kelvin:"
|
||||
tmp = WScript.StdIn.ReadLine
|
||||
|
||||
WScript.StdOut.WriteLine "Kelvin: " & tmp
|
||||
WScript.StdOut.WriteLine "Fahrenheit: " & fahrenheit(CInt(tmp))
|
||||
WScript.StdOut.WriteLine "Celsius: " & celsius(CInt(tmp))
|
||||
WScript.StdOut.WriteLine "Rankine: " & rankine(CInt(tmp))
|
||||
|
||||
Function fahrenheit(k)
|
||||
fahrenheit = (k*1.8)-459.67
|
||||
End Function
|
||||
|
||||
Function celsius(k)
|
||||
celsius = k-273.15
|
||||
End Function
|
||||
|
||||
Function rankine(k)
|
||||
rankine = (k-273.15)*1.8+491.67
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue