숫자 팰린드롬 확인기
숫자가 팰린드롬인지 확인하고, 범위 내 팰린드롬을 검색합니다.
✅
12321
회문입니다
역순: 12321
이 도구 소개
수 회문(palindrome)은 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.