# ---
# 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] pycharm={"name": "#%% md\n"}
# # Problem 52
# ## Permuted multiples
#
# 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.
#
# OEIS Sequence: [A133220](https://oeis.org/A133220)
#
# ## Solution

# + pycharm={"name": "#%%\n"}
def compute(n: int) -> int:
    i = 1
    while True:
        for j in range(10 ** i, 10 ** (i + 1) // n):
            j_digits = sorted(str(j))
            for k in range(2, n + 1):
                k_digits = sorted(str(j * k))
                if j_digits != k_digits:
                    break
            else:
                return j
        i += 1


# + pycharm={"name": "#%%\n"}
compute(2)

# + pycharm={"name": "#%%\n"}
compute(6)

# + pycharm={"name": "#%%\n"}
# %timeit -n 100 -r 1 -p 6 compute(6)

StarcoderdataJupyterScriptsDedupFiltered