Imagine four people stand in a line. The first looks at a thermometer, and tells the temperature to the person on their right. This continues down the line, until the last person writes the temperature on a sheet of paper. Unfortunately, due to a miscommunication, every person in the line converts the temperature to their preferred unit, without knowing which it already was.
Let's say the people's preferred units are
celsius. The first reads the temperature as 20°C. The second converts to fahrenheit, and determines that it is 68°F. The third, not knowing they have received the temperature in °F already, determines that it is 154.4°F. Finally, it is converted back to °C by the fourth person, who determines that it is 68°C.
You will be given two inputs: a temperature (
t), and a number of people (
n). Your program (or function) should return the average difference between the original and resulting temperatures, for every possible assortment of
There are two temperature units: °F and °C. To convert between them, you can use \$F=\frac95C+32\$ and \$C=\frac59(F-32)\$.
You can choose whether your program receives the inputted temperature in °F or °C. The first person should always receive an accurate temperature, converted to their preferred unit only if necessary.
As an example, we'll use an inputted temperature of 41°F, and just 3 people. There are 8 temperature preferences possible:
FFF 41°F -> 41.0 -> 105.8 -> 222.44 -> 222.44°F FFC 41°F -> 41.0 -> 105.8 -> 41.00 -> 105.80°F FCF 41°F -> 41.0 -> 5.0 -> 41.00 -> 41.00°F FCC 41°F -> 41.0 -> 5.0 -> -15.00 -> 5.00°F CFF 41°F -> 5.0 -> 41.0 -> 105.80 -> 105.80°F CFC 41°F -> 5.0 -> 41.0 -> 5.0 -> 41.00°F CCF 41°F -> 5.0 -> -15.0 -> 5.00 -> 5.00°F CCC 41°F -> 5.0 -> -15.0 -> -26.11 -> -15.00°F
The average distance from 41°F is 54.88°F, which is the program's output.
Temperature should be represented as a float, decimal, or fraction of some sort. The accuracy should be within reasonable bounds; for inputs less than ten people at low temperatures there shouldn't be floating point errors or imprecision noticeable in the first four decimal digits.
You may represent the temperatures inputted and outputted as either °F or °C, but must be consistent (although the input can output can be different units as long as they don't change). Temperatures can be negative. The number of people will never be less than two.
The output is referred to as a temperature above, although it's technically the arithmetic mean of multiple temperatures.
Input unit is the same as output unit for all test cases.
41°F 2 -> 25.2 41°F 3 -> 54.88 41°F 4 -> 77.236444... 41°F 10 -> 295.4268... 20°C 4 -> 57.21218... -1°C 2 -> 12.133... -20°C 2 -> 6.2222... -40°F 4 -> 0
This is code-golf, shortest answer in bytes per language wins!