数字回文チェッカー
数字が回文かチェック、範囲内の回文を検索、興味深い回文数を発見します。
✅
12321
は回文です
反転: 12321
このツールについて
数字回文とは、121や3443のように前から読んでも後ろから読んでも同じ数字のことです。数値回文チェッカーを使えば、任意の数値が回文かどうかを即座に確認したり、範囲内のすべての回文を探したり、これらの対称的な数字の興味深い数学的性質を発見できます。
ツールの使い方は簡単です。単一の数値を入力して回文かどうかを確認することも、範囲を指定してその中のすべての回文を見つけることもできます。小さな整数から大きな値まで、さまざまな数値範囲における回文の分布を調べたり、それらの出現頻度と数学的特性を理解したりできます。
このツールは数論を学んでいる学生、数値パターンを探求する数学者、数字の奇妙な性質に好奇心を持つ誰もが有用に活用できます。チェッカーはあらゆる正の整数に対応していますが、非常に大きな数値の処理には若干時間がかかる場合があります。ただし基本原理は変わりません。真の回文は中央の桁を中心に完全に対称です。
よくある質問
コード実装
def is_palindrome(n) -> bool:
"""Check if a number (int or string) is a palindrome."""
s = str(n)
return s == s[::-1]
def next_palindrome(n: int) -> int:
"""Find the next palindrome after n."""
n += 1
while not is_palindrome(n):
n += 1
return n
def find_palindromes_in_range(start: int, end: int) -> list[int]:
"""Find all palindrome numbers in range [start, end]."""
return [i for i in range(start, end + 1) if is_palindrome(i)]
# Check specific numbers
for num in [12321, 12345, 99999, 100001, 1234321]:
result = "✓ palindrome" if is_palindrome(num) else "✗ not palindrome"
print(f"{num}: {result}")
# Find palindromes in range
print("\nPalindromes 100-200:", find_palindromes_in_range(100, 200))
print("Next palindrome after 999:", next_palindrome(999))
print("Next palindrome after 12345:", next_palindrome(12345))
# Lychrel number check (reverse and add)
def reverse_and_add(n: int, steps: int = 50) -> tuple[bool, int]:
for _ in range(steps):
n += int(str(n)[::-1])
if is_palindrome(n):
return True, n
return False, n
print("\n196 Lychrel test:", reverse_and_add(196, 100)[0]) # Famous non-palindromeComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.