# Kata Task

You are given a list of cogs in a gear train

Each element represents the number of teeth of that cog

e.g. `[100, 50, 25]` means 
* 1st cog has 100 teeth 
* 2nd cog has 50 teeth
* 3rd cog has 25 teeth

If the ``nth`` cog rotates clockwise at 1 RPM what is the RPM of the cogs at each end of the gear train? 

**Notes**
* no two cogs share the same shaft
* return an array whose two elements are RPM of the first and last cogs respectively
* use negative numbers for anti-clockwise rotation
* for convenience `n` is zero-based
* For C and NASM coders, the returned array will be `free`'d.

---

Series:
* Cogs
* Cogs 2

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def cog_RPM(cogs, n):
	

Solutions:
def cog_RPM(cogs, n):
	return [cogs[n] / cogs[0] * (-1 if n % 2 else 1), cogs[n] / cogs[-1] * (1 if (len(cogs) - n) % 2 else -1)]


def cog_RPM(cogs, n):
	sign1 = -1 if n % 2 else 1
	sign2 = 1 if (len(cogs) - n) % 2 else -1
	return [sign1 * cogs[n] / cogs[0], sign2 * cogs[n] / cogs[-1]]


def cog_RPM(l, i):
	return [(-1 + (i + 1) % 2 * 2) * l[i] / l[0], (-1 + (len(l) - i) % 2 * 2) * l[i] / l[-1]]


def cog_RPM(cogs, n):
	(a, b) = (1, 1)
	if n % 2 == 1:
		a = -1
	if len(cogs) % 2 == n % 2:
		b = -1
	return [a * cogs[n] / cogs[0], b * cogs[n] / cogs[-1]]


def cog_RPM(cogs, n):
	return [cogs[n] / cogs[0] * (-1) ** n, cogs[n] / cogs[-1] * (-1) ** (len(cogs) - n - 1)]


def cog_RPM(cogs, n):
	output = []
	if n % 2 == 0:
		a = 1
		if len(cogs) % 2 - 1 == 0:
			b = 1
		else:
			b = -1
	else:
		a = -1
		if (len(cogs) - 1) % 2 == 0:
			b = -1
		else:
			b = 1
	output.append(cogs[n] / cogs[0] * a)
	output.append(cogs[n] / cogs[-1] * b)
	return output


def cog_RPM(cogs, idx):
	first = cogs[idx] / cogs[0] * [1, -1][idx & 1]
	last = cogs[idx] / cogs[-1] * [1, -1][len(cogs) - idx - 1 & 1]
	return [first, last]


def cog_RPM(cogs, n):
	r = [cogs[n] / cogs[0], cogs[n] / cogs[-1]]
	if n % 2 == 1:
		r[0] *= -1
	if (len(cogs) - n) % 2 == 0:
		r[1] *= -1
	return r


def cog_RPM(cogs, i):
	(x, y) = (cogs[i] / cogs[0], cogs[i] / cogs[-1])
	if i & 1:
		x = -x
	if len(cogs) - 1 - i & 1:
		y = -y
	return [x, y]


from functools import reduce
from operator import mul

def cog_RPM(cogs, n):
	f = lambda l: 1 if len(l) < 2 else reduce(mul, [-x / y for (x, y) in zip(l, l[1:])])
	return [f(cogs[:n + 1][::-1]), f(cogs[n:])]