<jupyter_start><jupyter_text>smallest perfect squaresDetermine the smallest number of perfect squares that sum up to N.   Exponential time complexity - each recur calls prompts additional calls<jupyter_code>def recur(n, perfect_squares):
    if n == 0 or n == 1:
        return n
    else:
        result = n

        for p in perfect_squares:
            if n - p >= 0:
                result = min(result, 1 + recur(n - p, perfect_squares))
            else:
                break

        return result

def min_squares(n):
    perfect_squares = []

    for i in range(1, int(n ** 0.5) + 1):
        if i * i <= n:
            perfect_squares.append(i * i)

    return recur(n, perfect_squares)<jupyter_output><empty_output><jupyter_text>Dynamic programming- Keep track of array that holds the minimum number of perfect squares<jupyter_code>def min_squares(n):
    perfect_squares = []
    for i in range(1, int(n ** 0.5) + 1):
        if i * i <= n:
            perfect_squares.append(i * i)

    min_squares = [i for i in range(n + 1)]

    for i in range(2, n + 1):
        for p in perfect_squares:
            min_squares[i] = min(min_squares[i], 1 + min_squares[i - p])

    return min_squares[-1]<jupyter_output><empty_output><jupyter_text>Kind of cheating... but math solution- Integer can be expressed as the sum of the at most four perfect squares<jupyter_code>def min_squares(n):
    perfect_squares = set()
    for i in range(1, int(n ** 0.5) + 1):
        if i * i <= n:
            perfect_squares.add(i * i)

    if n in perfect_squares:
        return 1

    for p in perfect_squares:
        if n - p in perfect_squares:
            return 2

    while n % 4 == 0:
        n /= 4
    if n % 8 != 4:
        return 3

    return 4<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0983698707138842, 'fraction_numerical': 0.016863406408094434, 'mean_word_length': 2.2660550458715596, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '77067', 'license': 'MIT', 'n_tokens_mistral': 646, 'n_tokens_neox': 580, 'n_words': 191, 'path': 'Daily/smallest perfect square N.ipynb', 'repo_name': 'jasonyum/python_go', 'size': '1779'}