Last active
January 28, 2023 21:21
-
-
Save fumiyanll23/c15dbd614271514b3b02b7ff40648848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
N = 50 | |
M = N * N | |
# 結果を書き込むファイルのパスを指定する | |
PATH = './palindromic_expression.txt' | |
time_start = time.time() | |
print('searching...') | |
# 任意の1桁の数は回文数なので,n ≧ 11として探索する | |
for n in range(11, N): | |
# n < m | |
for m in range(n+1, M): | |
n_rev = int(str(n)[::-1]) | |
m_rev = int(str(m)[::-1]) | |
if str(n*m) == str(n*m)[::-1] and n*m == n_rev*m_rev: | |
with open(PATH, 'a') as f: | |
f.write(f'{n} * {m} = {n*m} = {m_rev} * {n_rev}\n') | |
print('finished :)') | |
time_end = time.time() | |
print(f'Time: {time_end - time_start}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About
回文数ならぬ回文数式を見つけるスクリプトです.回文数式 (palindromic expression) とは著者の造語で,以下の条件を充たす数式のことをいいます:
Example
References