In [54]:
from collections import defaultdict
    from functools import reduce
    from math import cos, pi, sin
    import pandas as pd
    
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    
    
    def get_counter_array(points):
        dimx = reduce(max, map(lambda p: p[0], points))
        dimy = reduce(max, map(lambda p: p[1], points))
        maxlines = (dimx + dimy)
        parameterspace = [0] * (dimx * dimy)
        pspace = defaultdict(lambda: 0)
        allx = []
        ally = []
        for i, j in points:
            xs = []
            ys = []
            for h in ((float(line) / maxlines) * pi for line in range(maxlines)):
                p = i * sin(h) + j * cos(h)
                k = int(p)
                print("{} -> {}".format(h, 360 / (2 * math.pi) * h))
                print(p)
                parameterspace[int(p + h * dimx)] += 1
                pspace[(round(p, 1), h)] += 1
                xs.append(p)
                ys.append(h)
                allx.append(p)
                ally.append(h)
     
            xpos = np.asarray(xs)
            ypos = np.asarray(ys)
            zpos = np.zeros(len(xs))
            dx = 0.5 * np.ones_like(zpos)
            dy = dx.copy()
            dz = np.ones_like(zpos)
            plt.scatter(xpos, ypos, s=dz * 5 * np.pi, alpha=0.5)
            plt.show()
                
#        fig = plt.figure()
#        ax2 = fig.add_subplot(111, projection='3d')
        hist, xedges, yedges = np.histogram2d(allx, ally, bins=maxlines)
        print(hist)
        elements = (len(xedges) - 1) * (len(yedges) - 1)
        xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25)
        xpos = xpos.flatten()
        ypos = ypos.flatten()
        zpos = np.zeros(elements)
        dx = 0.5
        dy = 0.5
        dz = hist.flatten()
        plt.scatter(xpos, ypos, s=dz * 5 * np.pi, alpha=0.5)
        plt.show()
#        ax2.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
#        plt.show()
        print(pspace.values())
        return pspace
    
    
    def find_minimums(counters):
        print([c for c in counters.values() if c >= 3])
        return [c for c in counters.values() if c >= 3]
    
    
    def checkio(cakes):
        print("=" * 30)
        numcakes = len(find_minimums(get_counter_array(cakes)))
        print("Found : {}".format(numcakes))
        return numcakes
    
    
    checkio([[3, 3], [5, 5], [8, 8], [2, 8], [8, 2]])


==============================
0.0 -> 0.0
3.0
0.19634954084936207 -> 11.25
3.527626807258076
0.39269908169872414 -> 22.5
3.9196888946291293
0.5890486225480862 -> 33.75
4.161119535966442
0.7853981633974483 -> 45.0
4.242640687119286
0.9817477042468103 -> 56.25
4.161119535966442
1.1780972450961724 -> 67.5
3.9196888946291297
1.3744467859455345 -> 78.75
3.527626807258076
1.5707963267948966 -> 90.0
3.0
1.7671458676442586 -> 101.25
2.3570848751613065
1.9634954084936207 -> 112.5
1.6235883004385907
2.1598449493429825 -> 123.74999999999999
0.8276981378488306
2.356194490192345 -> 135.0
4.440892098500626e-16
2.552544031041707 -> 146.25
-0.8276981378488295
2.748893571891069 -> 157.5
-1.6235883004385903
2.945243112740431 -> 168.75
-2.3570848751613056
0.0 -> 0.0
5.0
0.19634954084936207 -> 11.25
5.879378012096794
0.39269908169872414 -> 22.5
6.532814824381883
0.5890486225480862 -> 33.75
6.935199226610737
0.7853981633974483 -> 45.0
7.0710678118654755
0.9817477042468103 -> 56.25
6.935199226610738
1.1780972450961724 -> 67.5
6.532814824381883
1.3744467859455345 -> 78.75
5.879378012096794
1.5707963267948966 -> 90.0
5.0
1.7671458676442586 -> 101.25
3.9284747919355114
1.9634954084936207 -> 112.5
2.7059805007309854
2.1598449493429825 -> 123.74999999999999
1.3794968964147172
2.356194490192345 -> 135.0
4.440892098500626e-16
2.552544031041707 -> 146.25
-1.3794968964147154
2.748893571891069 -> 157.5
-2.7059805007309845
2.945243112740431 -> 168.75
-3.928474791935509
0.0 -> 0.0
8.0
0.19634954084936207 -> 11.25
9.407004819354869
0.39269908169872414 -> 22.5
10.452503719011013
0.5890486225480862 -> 33.75
11.09631876257718
0.7853981633974483 -> 45.0
11.31370849898476
0.9817477042468103 -> 56.25
11.09631876257718
1.1780972450961724 -> 67.5
10.452503719011013
1.3744467859455345 -> 78.75
9.40700481935487
1.5707963267948966 -> 90.0
8.0
1.7671458676442586 -> 101.25
6.285559667096818
1.9634954084936207 -> 112.5
4.329568801169576
2.1598449493429825 -> 123.74999999999999
2.207195034263548
2.356194490192345 -> 135.0
8.881784197001252e-16
2.552544031041707 -> 146.25
-2.2071950342635454
2.748893571891069 -> 157.5
-4.329568801169575
2.945243112740431 -> 168.75
-6.285559667096814
0.0 -> 0.0
8.0
0.19634954084936207 -> 11.25
8.2364628872581
0.39269908169872414 -> 22.5
8.156403124820473
0.5890486225480862 -> 33.75
7.762897364459566
0.7853981633974483 -> 45.0
7.0710678118654755
0.9817477042468103 -> 56.25
6.107501088761909
1.1780972450961724 -> 67.5
4.909226523943293
1.3744467859455345 -> 78.75
3.5222931369354873
1.5707963267948966 -> 90.0
2.0000000000000004
1.7671458676442586 -> 101.25
0.4008479846774353
1.9634954084936207 -> 112.5
-1.2137083938981443
2.1598449493429825 -> 123.74999999999999
-2.781622639551725
2.356194490192345 -> 135.0
-4.242640687119285
2.552544031041707 -> 146.25
-5.540616432381158
2.748893571891069 -> 157.5
-6.625669395360114
2.945243112740431 -> 168.75
-7.456101599193587
0.0 -> 0.0
2.0
0.19634954084936207 -> 11.25
3.522293136935487
0.39269908169872414 -> 22.5
4.909226523943292
0.5890486225480862 -> 33.75
6.107501088761908
0.7853981633974483 -> 45.0
7.071067811865475
0.9817477042468103 -> 56.25
7.762897364459566
1.1780972450961724 -> 67.5
8.156403124820473
1.3744467859455345 -> 78.75
8.2364628872581
1.5707963267948966 -> 90.0
8.0
1.7671458676442586 -> 101.25
7.4561015991935875
1.9634954084936207 -> 112.5
6.625669395360115
2.1598449493429825 -> 123.74999999999999
5.54061643238116
2.356194490192345 -> 135.0
4.242640687119286
2.552544031041707 -> 146.25
2.7816226395517267
2.748893571891069 -> 157.5
1.2137083938981457
2.945243112740431 -> 168.75
-0.400847984677432
[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  2.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  1.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.  0.  1.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  2.  1.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.  2.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  0.  0.  3.  0.  0.  1.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  2.  0.  0.  1.  0.]
 [ 2.  0.  0.  0.  0.  0.  0.  0.  2.  1.  1.  1.  0.  1.  0.  0.]
 [ 0.  2.  1.  1.  1.  1.  1.  2.  0.  1.  0.  0.  1.  0.  0.  0.]
 [ 1.  0.  1.  0.  0.  0.  1.  0.  1.  0.  1.  0.  0.  0.  0.  0.]
 [ 0.  1.  1.  1.  0.  1.  1.  1.  0.  1.  0.  1.  0.  0.  0.  0.]
 [ 0.  0.  0.  2.  3.  2.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.]
 [ 2.  1.  1.  0.  0.  0.  1.  1.  2.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  1.  0.  0.  0.  0.  0.  1.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  1.  1.  1.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]
dict_values([1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1])
[3, 3]
Found : 2
Out[54]:
2