In [2]:
data = []
with open("data.txt", "r") as f:
    for l in f.readlines():
        data.append(l.strip().split(','))

In [6]:
data = [(int(x[0]), int(x[1])) for x in data]
data


Out[6]:
[(12, 12), (13, 65), (14, 50)]

In [20]:
from matplotlib import pyplot as plt
import numpy as np
# import seaborn as sns

In [21]:
# %matplotlib inline
# sns.set_context("poster")

In [23]:
X = [x[0] for x in data]
Y = [x[1] for x in data]
plt.plot(X, Y, label="helol")
plt.show()


/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

In [25]:
#assumes good input and a solution, no checks done for this
def slice_cake(cake):
    def loop(cake_slice, index):
        #base case => found a slice that exactly slices cake
        if index == len(cake):
            return cake_slice
    
        len_slice = len(cake_slice)
        
        #if the next slice is the same length as the current slice
        #keep looking
        if cake[index:index + len_slice] == cake_slice:
            return loop(cake_slice, index + len_slice)
        else:
            return loop(cake[:len_slice + 1], len_slice + 1)
    
    return len(loop(cake[0], 1))

In [31]:
slice_cake("121212")


Out[31]:
2

In [ ]: