5 kyu

Antipodal Points with Same Temperature

Description:

Imagine two thermometers placed on the equator, at exact opposite points of the globe.

Two thermometers

We will now swap the thermometers, maintaining 180º longtitude between them, and as each thermometer travels around the equator, we will record it's readings.

Swap

Common sense and Intermediate Value Theorem tells us that during this journey thermometers' readings will cross at some point at least once.

Readings

Let's look at this from above.

Above view

As you can see, at some point, defined by longtitude φ, thermometers' readings are equal.

Your task is to implement a function equalTemperatureLongtitude, that will return the first longtitude φ, for which this statement is correct.

Your function will recieve an object of class Strip, containing the temperatures on the equator, that has the following methods:

getDatapointsCount() - returns the number of datapoints provided,

raw() - returns an array of raw datapoints,

getTemperatureAt(longtitude) - (longtitude in degrees) returns current temperature at specified longtitude. Important: readings are interpolated linearly between datapoints.

As a result, your function must return the minimum longtitude φ, at which temperatures are equal.

Tolerance for temperature difference is 0.001º Celcius and for longtitude is 0.01º.

For example, for Strip([0,1,2,3]) the first (and only) longtitude where both thermometers have same readings is 135º.

135 example

Sidenotes:

  1. Strip object will always contain N ∈ [4, 5, ..., 36] datapoints
  2. You may pass any longtitude to getTemperatureAt (negative or greater than 360º), it will be mapped to [0º, 360º) internally (-1º becomes 359º and so on)
  3. Temperatures will be in range [15, 25).
  4. I urge you not to use the most naive approach as it wastes CodeWars' computing power! (you will also run out of time, probably)

Hints:

  1. According to Intermediate Value Theorem, ANY input has at least 1 solution
  2. By definition, the solution always lies in [0º, 180º) range
  3. Revise numerical methods of solving equations
  4. Temperature is interpolated linearly between datapoints, but its difference may not be that linear sometimes!

Good luck and have fun!

Algorithms

Stats:

CreatedJun 4, 2017
PublishedJun 4, 2017
Warriors Trained56
Total Skips0
Total Code Submissions359
Total Times Completed15
JavaScript Completions15
Python Completions2
Total Stars6
% of votes with a positive feedback rating100% of 8
Total "Very Satisfied" Votes8
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • danilkamyshov Avatar
  • JohanWiltink Avatar
  • dfhwze Avatar
Ad