<jupyter_start><jupyter_text>Problem 4: Largest palindrome productA palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.Find the largest palindrome made from the product of two 3-digit numbers.  SolutionWe'll begin by a slow and inefficient method, that does the following: 1. Go backward through all 3 digit numbers 2. Check if product is a palindrone  3. Done I am sure some simple maths will provide us with either an analytic solution or a highly optimized version, but let's get a baselien working version first<jupyter_code>import numpy as np
def largest_palindrome(n_digits):
    """
        Evaluates the two largest numbers that when multipled result 
        in a palindromic number. 
        
    """
    # Cycle backwards through the all the possible n digit combination 
    # of numbers and store they're palindromes 
    pals = []
    for n in xrange(10**(n_digits)-1,10**(n_digits-1),-1):
        for m in xrange(10**(n_digits)-1,10**(n_digits-1),-1):
            if is_palindrome(n*m):
                pals.append(n*m)
                # Failed to find two products 
    return np.max(pals) #[-1,-1]
        
from math import log10,floor
def parse_integer(n):
    """
        Splits an integer n into it's base 10^i components 
        e.g 4321 -> [4,3,2,1]
    """
    cols = []
    for i in xrange(1,int(floor(log10(n))+2),1):
        cols.append(n%10**i/10**(i-1))
        n = n - cols[-1]
    cols.reverse()
    return cols

import copy 
def is_palindrome(n):
    components = parse_integer(n)
    components_rev = copy.copy(components)
    components_rev.reverse()

    for i,j in zip(components,components_rev):
        if i != j:
            return False
    return True

# Put a test int to check that we're working
# assert largest_palindrome(2) == [99,91], "The largest palindrome function failed to pass the basic sanity check!"
print largest_palindrome(3)
%time<jupyter_output>906609
CPU times: user 2 µs, sys: 0 ns, total: 2 µs
Wall time: 5.01 µs
{'fraction_non_alphanumeric': 0.09250243427458617, 'fraction_numerical': 0.035053554040895815, 'mean_word_length': 3.0058479532163744, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '221852', 'license': 'MIT', 'n_tokens_mistral': 715, 'n_tokens_neox': 638, 'n_words': 240, 'path': '04/04.ipynb', 'repo_name': 'JacobRawling/ProjectEuler', 'size': '2054'}