from itertools import permutations

def is_valid_solution(n, N):
    combined_digits = str(n) + str(N)
    return sorted(combined_digits) == ['1', '2', '3', '4', '5', '6', '7', '8', '9']

def find_solutions():
    solutions = []
    for perm in permutations('123456789'):
        for i in range(1, 9):  
            n_str = ''.join(perm[:i])
            N_str = ''.join(perm[i:])
            n = int(n_str)
            N = int(N_str)
            if n ** 2 == N and is_valid_solution(n, N):
                solutions.append((n, N))
    return solutions

solutions = find_solutions()
for n, N in solutions:
    print(f"n = {n}, N = {N}")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: