# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] nbgrader={}
# # Project Euler: Problem 52

# + [markdown] nbgrader={}
# https://projecteuler.net/problem=52
#
# It can be seen that the number, $125874$, and its double, $251748$, contain exactly the same digits, but in a different order.
#
# Find the smallest positive integer, $x$, such that $2x$, $3x$, $4x$, $5x$, and $6x$, contain the same digits.

# + [markdown] nbgrader={}
# First, write a function `same_digits(x,y)` that returns `True` if two integers `x` and `y` have the exact same set of digits and multiplicities and `False` if they have different digits.

# + nbgrader={"checksum": "aad5ed41801af39fc06f00c8d275a010", "solution": true}
def same_digits(x, y):
    value = True
    xs = str(x)
    ys = str(y)
    
    xl = [i for i in xs]
    yl = [j for j in ys]
    
    xs = sorted(xl)
    ys = sorted(yl)
    
    if len(xs) != len(ys):
        value = False
    else:
        for i in range(0,len(xs)):
            if xs[i]!=ys[i]:
                value = False
    return value


# + deletable=false nbgrader={"checksum": "dd0aff5d565bc794cee175aaa6c0cb3d", "grade": true, "grade_id": "projecteuler52a", "points": 4}
assert same_digits('132', '321')
assert not same_digits('123', '3')
assert not same_digits('456', '0987654321')

# + [markdown] nbgrader={}
# Now use the `same_digits` function to solve this Euler problem. As you work on this problem, be careful to debug and test your code on small integers before trying it on the full search.
# -

# Searching for the smallest. So I will look from the bottom and the first one I find is the smallest

# + deletable=false nbgrader={"checksum": "6cff4e8e53b15273846c3aecaea84a3d", "solution": true}
myint = 0
for b in range(1,200000):
    if same_digits(b, 2*b) and same_digits(b, 3*b) and same_digits(b, 4*b) and same_digits(b, 5*b) and same_digits(b, 6*b)  :
        myint = b
        break
myint




# + deletable=false nbgrader={"checksum": "dafbda681e8fb50925790dc1d0600750", "grade": true, "grade_id": "projecteuler52b", "points": 6}
assert True # leave this cell to grade the solution

StarcoderdataJupyterScriptsDedupFiltered