Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The Rows of cakes solution in Uncategorized category for The Rows of Cakes by capback250
# migrated from python 2.7
import math
from functools import reduce
def checkio(array):
all_lines = []
all_points = []
for first_point in array:
for second_point in array:
if first_point == second_point:
pass
else:
x1,y1=first_point
x2,y2=second_point
A = (y1 - y2)
B = (x2 - x1)
C = (x1*y2-x2*y1)
nod = gcd(abs(A), abs(B), abs(C))
if divisioner([A,B,C], nod) not in all_lines:
all_lines.append(divisioner([A,B,C], nod))
for line in all_lines:
temp = []
for point in array:
if line[0]*point[0] + line[1]*point[1] + line[2] == 0:
temp.append(point)
if len(temp) > 2:
if temp not in all_points:
all_points.append(temp)
return len(all_points)
def gcd(*args):
ar = [x for x in args if x != 0]
def factors(n):
k = sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n))+1) if n % i == 0))), reverse=True)
return k
for i in factors(min(ar)):
if all([x % i == 0 for x in ar]):
return i
def divisioner(arr, nod):
return [x / nod for x in arr]
Oct. 27, 2015