3
\$\begingroup\$

The Australian Apparent Temperature (aka, wind chill) in °C AT is given by this algorithm from the Australian Bureau of Meterology (wp, source):

enter image description here

AT = Ta + (0.33 * e) - (.7 * ws) - 4.0

Where:

Ta = Dry bulb temperature (°C)

e = Water vapour pressure (hPa)

ws = Wind speed (m/s) (at an elevation of 10 meters)

The water vapour pressure in hectoPascals e is given by this algorithm:

enter image description here

e = (rh / 100) * 6.105 * exp( ( 17.27 * Ta ) / ( 237.7 + Ta ) )

Where:

Ta = Dry bulb temperature (°C)

rh = Relative humidity [%]

exp represents the exponential function

The domain of:

  • Ta is -273.15°C to 2e7°C.

  • e is the real numbers

  • ws is 0 m/s to 2e7 m/s

  • rh is 0% to 100%

For inputs outside these domains, your code can do anything, including give the right answer.


Output

Given a dry bulb temperature in °C, a wind speed in metres / second, and a relative humidity in %, your code should give the Apparent Temperature in °C, accurate to 0.1°C.

Assuming your platform or language can represent reals, for correct functions correct_func,

enter image description here

or in C, fabsl( correct_func(Ta, rH, ws) - expected ) < 0.1.

Test cases

1 value for Ta, rh, ws -> output

0 -> -4
2 -> -3.35346
4 -> -2.69275
6 -> -2.01507
8 -> -1.31719
10 -> -0.595428
12 -> 0.154404
14 -> 0.937065
16 -> 1.75793
18 -> 2.62308
20 -> 3.5393
22 -> 4.51423
24 -> 5.55638
26 -> 6.67525
28 -> 7.88137
30 -> 9.18643

49, 99, 67 -> 36.268

Repl.it for any test case: https://repl.it/H9xL/0

You can use a builtin function for the exponential function, ex, if you like.

This is , so the shortest code wins!

\$\endgroup\$
8
  • \$\begingroup\$ Is there a single input to the program or are the test cases just weird? \$\endgroup\$ Commented May 1, 2017 at 17:21
  • \$\begingroup\$ @JonathanAllan The algorithm takes three inputs, but I was lazy in creating the test cases, using one value for three args. \$\endgroup\$
    – cat
    Commented May 1, 2017 at 17:24
  • 3
    \$\begingroup\$ This challenge doesn't really have much room for golfing. \$\endgroup\$
    – mbomb007
    Commented May 1, 2017 at 19:10
  • 1
    \$\begingroup\$ @xnor The inputs have bounds. "For inputs outside these domains, your code can do anything, including give the right answer." \$\endgroup\$
    – mbomb007
    Commented May 1, 2017 at 19:22
  • 1
    \$\begingroup\$ This isn't a problem with the people. There's little room for creativity when the algorithm is straight-up the simplest way to solve it. \$\endgroup\$
    – mbomb007
    Commented May 1, 2017 at 19:28

7 Answers 7

5
\$\begingroup\$

Python 3, 76 bytes

t=lambda T,r,V:.0201465*r*2.718281828459045**(1727*T/(100*T+23770))+T-.7*V-4

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Commented May 1, 2017 at 19:05
4
\$\begingroup\$

Python, 78 72 66 bytes

Pretty much a direct implementation of the algorithm provided in the challenge description.

lambda T,r,w:T+.0201465*r*2.7182818284**(17.27*T/(237.7+T))-.7*w-4

Try it online

This was specifically tested with the maximum value of T to find how many digits of Euler's constant were required for the error to be within the allowed amount.

\$\endgroup\$
3
\$\begingroup\$

TI-BASIC, 41 bytes

:Prompt T,R,W
:T-.7W-4+.02014565Re^(17.27T/(237.7+T

Surprisingly, a calculator is really good at crunching numbers.

\$\endgroup\$
2
\$\begingroup\$

Javascript, 56 bytes

(a,r,w)=>a+.0201465*r*Math.exp(17.27*a/(237.7+a))-.7*w-4

var f = (a,r,w)=>a+.0201465*r*Math.exp(17.27*a/(237.7+a))-.7*w-4
var expected = [-4, -3.35346, -2.69275, -2.01507, -1.31719, -0.595428, 0.154404, 0.937065, 1.75793, 2.62308, 3.5393, 4.51423, 5.55638, 6.67525, 7.88137, 9.18643]; for (var i = 0; i < 16; i++) {var g = f(2*i,2*i,2*i); var diff = expected[i] - g; document.getElementById('w').innerHTML += '\n' + ((diff > 0.1 || diff < -0.1) ? 'KO' : 'OK') + '   ' + (expected[i] - g) + '   ' + g + '   ' + expected[i];}
<pre id="w">Passed  |  Diff  |  Actual result  |  Expected</pre>

\$\endgroup\$
2
\$\begingroup\$

Octave, 54 49 bytes

@(T,r,V).0201465*r*e^(17.27*T/(237.7+T))+T-.7*V-4

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ (17.27*T/(237.7+T) is shorter. \$\endgroup\$
    – mbomb007
    Commented May 1, 2017 at 19:23
2
\$\begingroup\$

Japt, 40 38 bytes

U+.0#É465*V*MEp17.27*U/(#í.7 +U)-.7*W-4

Try it online!

This is my first Japt answer, so please don't judge it too harshly ;-)

\$\endgroup\$
2
  • \$\begingroup\$ Hey, thanks for using Japt :-) You can save a couple bytes by replacing 201 and 237 with and , respectively. (It's an odd trick, but it works...) \$\endgroup\$ Commented May 2, 2017 at 14:28
  • \$\begingroup\$ @ETHproductions: that's odd indeed. Thanks though! \$\endgroup\$
    – Luke
    Commented May 2, 2017 at 15:24
1
\$\begingroup\$

Perl 6, 52 (possibly non-competing)

{$^a+.0201465*$^c*exp(17.27*$a/(237.7+$a))-4-.7*$^b}

This can't be evaluated by itself. You either have to pass in arguments, or store the block into a variable.

\$\endgroup\$
4
  • \$\begingroup\$ What do you mean, “This can't be evaluated by itself”? As I see, it can be called as any anonymous function. (Maybe you should specify that it expects parameters in Ta, ws, rh order.) \$\endgroup\$
    – manatwork
    Commented May 2, 2017 at 8:59
  • \$\begingroup\$ If you type it by itself in the REPL, you'll get an error. You either have to pass in the arguments, or assign the block to a variable. \$\endgroup\$
    – bb94
    Commented May 2, 2017 at 18:41
  • \$\begingroup\$ Sure you have to pass it arguments, but no need to assign to variable. pastebin.com/7W3cJSrX This is the same as calling anonymous functions in other languages. \$\endgroup\$
    – manatwork
    Commented May 2, 2017 at 18:50
  • \$\begingroup\$ What I meant was that if you typed the expression alone without either, you got an error. \$\endgroup\$
    – bb94
    Commented May 2, 2017 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.