Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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
;

View file

@ -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);
}

View file

@ -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

View file

@ -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, !

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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 ;

View file

@ -0,0 +1,3 @@
atom K = prompt_number("Enter temperature in Kelvin >=0: ",{0,1e307})
printf(1," Kelvin: %5.2f\n Celsius: %5.2f\nFahrenheit: %5.2f\n Rankine: %5.2f\n\n",
{K, K-273.15, K*1.8-459.67, K*1.8})

View file

@ -0,0 +1,11 @@
k = 21.0 c = 0 r = 0 f = 0
convertTemp(k)
see "Kelvin : " + k + nl +
"Celcius : " + c + nl +
"Rankine : " + r + nl +
"Fahrenheit : " + f + nl
func convertTemp k
c = k - 273.15
r = k * 1.8
f = r - 459.67

View file

@ -0,0 +1,12 @@
var scale = Hash(
Celcius => Hash.new(factor => 1 , offset => -273.15 ),
Rankine => Hash.new(factor => 1.8, offset => 0 ),
Fahrenheit => Hash.new(factor => 1.8, offset => -459.67 ),
);
var kelvin = Sys.readln("Enter a temperature in Kelvin: ").to_n;
kelvin >= 0 || die "No such temperature!";
scale.keys.sort.each { |key|
printf("%12s:%8.2f\n", key, kelvin*scale{key}{:factor} + scale{key}{:offset});
}

View file

@ -0,0 +1,7 @@
decl double k
while true
out "Temp. in Kelvin? " console
set k (in double console)
out "K\t" k endl "C\t" (- k 273.15) endl console
out "F\t" (- (* k 1.8) 459.67) endl "R\t" (* k 1.8) endl endl console
end while

View file

@ -0,0 +1,25 @@
#DEFINE ABSZC 273.16
#DEFINE ABSZF 459.67
LOCAL k As Double, c As Double, f As Double, r As Double, n As Integer, ;
cf As String
n = SET("Decimals")
cf = SET("Fixed")
SET DECIMALS TO 2
SET FIXED ON
CLEAR
DO WHILE .T.
k = VAL(INPUTBOX("Degrees Kelvin:", "Temperature"))
IF k <= 0
EXIT
ENDIF
? "K:", k
c = k - ABSZC
? "C:", c
f = 1.8*c + 32
? "F:", f
r = f + ABSZF
? "R:", r
?
ENDDO
SET FIXED &cf
SET DECIMALS TO n

View file

@ -0,0 +1,13 @@
(DEFUN CONVERT-TEMPERATURE ()
(SETQ *FLONUM-FORMAT* "%.2f")
(DISPLAY "Enter a temperature in Kelvin.")
(NEWLINE)
(DISPLAY "> ")
(DEFINE K (READ))
(DISPLAY `(K = ,K))
(NEWLINE)
(DISPLAY `(C = ,(- K 273.15)))
(NEWLINE)
(DISPLAY `(F = ,(- (* K 1.8) 459.67)))
(NEWLINE)
(DISPLAY `(R = ,(* K 1.8))))

View 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

View file

@ -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