6 kyu

Power Laws

27 of 77marbiru

Description:

A Power Law distribution occurs whenever "a relative change in one quantity results in a proportional relative change in the other quantity." For example, if y = 120 when x = 1 and y = 60 when x = 2 (i.e. y halves whenever x doubles) then when x = 4, y = 30 and when x = 8, y = 15.

Therefore, if I give you any pair of co-ordinates (x1,y1) and (x2,y2) in a power law distribution, you can plot the entire rest of the distribution and tell me the value of y for any other value of x.

Given a pair of co-ordinates (x1,y1) and (x2,y2) and another x co-ordinate x3, return the value of y3

powerLaw(x1y1, x2y2, x3)
e.g. powerLaw([1,120], [2,60], 4)
- when x = 1, y = 120
- when x = 2, y = 60
- therefore whenever x doubles, y halves
- therefore when x = 4, y = 60 * 0.5
- therfore solution = 30

(x1,y1) and (x2,y2) will be given as arrays. Answer should be to the nearest integer, but random tests will give you leeway of 1% of the reference solution to account for possible discrepancies from different methods.

Fundamentals

More By Author:

Check out these other kata created by marbiru

Stats:

CreatedSep 11, 2017
PublishedSep 14, 2017
Warriors Trained280
Total Skips8
Total Code Submissions516
Total Times Completed77
JavaScript Completions27
Python Completions56
Total Stars6
% of votes with a positive feedback rating86% of 33
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes2
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • marbiru Avatar
  • ZED.CWT Avatar
Ad