A [Power Law](https://en.wikipedia.org/wiki/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.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def power_law(x1y1, x2y2, x3):
	

Solutions:
from math import log

def power_law(p1, p2, x3):
	((x1, y1), (x2, y2)) = (p1, p2)
	x1 += 1e-09
	y1 += 1e-09
	return round(y1 * (y2 / y1) ** log(x3 / x1, x2 / x1))


from math import log

def power_law(x1y1, x2y2, x3):
	(a, b, c) = (x2y2[0] / x1y1[0], x2y2[1] / x1y1[1], x3 / x1y1[0])
	try:
		return round(x1y1[1] * b ** log(c, a))
	except ZeroDivisionError:
		return round(x1y1[1] * b)


from math import log

def power_law(x1y1, x2y2, x3):
	(x1, y1) = x1y1
	(x2, y2) = x2y2
	if x1 == x2:
		return y2
	return round(y1 * (y2 / y1) ** log(x3 / x1, x2 / x1))


def power_law(a1, a2, x3):
	import math
	x1 = a1[0]
	y1 = a1[1]
	x2 = a2[0]
	y2 = a2[1]
	if x1 == x2:
		return y2
	else:
		return round(y1 * (y2 / y1) ** (math.log10(x3 / x1) / math.log10(x2 / x1)))


power_law = lambda a, b, x: round(a[1] * (b[1] / (a[1] + 1e-09)) ** __import__('math').log(x / (a[0] + 1e-09), b[0] / (a[0] + 1e-09)))


import math

def power_law(x1y1, x2y2, x3):
	if x1y1[0] == x2y2[0]:
		return x2y2[1]
	(x_asc_rate, y_dsec_rate) = (x2y2[0] / x1y1[0], x1y1[1] / x2y2[1])
	return round(x2y2[1] / y_dsec_rate ** (math.log(x3 / x2y2[0]) / math.log(x_asc_rate)))


from math import log

def power_law(x1y1, x2y2, x3):
	((x1, y1), (x2, y2)) = (x1y1, x2y2)
	try:
		k = log(y1 / y2, x1 / x2)
		a = y1 / x1 ** k
		return round(a * x3 ** k)
	except ZeroDivisionError:
		return y2


import math

def power_law(x1y1, x2y2, x3):
	x1 = x1y1[0]
	y1 = x1y1[1]
	x2 = x2y2[0]
	y2 = x2y2[1]
	x = x2 / x1
	y = y2 / y1
	if x1 == x2:
		return y2
	return round(y1 * y ** (math.log(x3 / x1) / math.log(x)))