Created
January 10, 2024 21:16
-
-
Save orjanv/a83911c8b66376ede4a880df9ea19720 to your computer and use it in GitHub Desktop.
Kode for å telle femsifrede palindrome hentekoder og sjekke om noen av de er primtall
This file contains hidden or 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
palindromer = [] | |
palindromprimtall = [] | |
for tall in range(00000,99999+1): | |
sjekk = f'{tall:05}' | |
if sjekk == ''.join(list(reversed(sjekk))): | |
palindromer.append(tall) | |
if all(int(sjekk) % i for i in range(2, int(sjekk))): | |
palindromprimtall.append(tall) | |
print(f'For et femsifret tall, er det {len(palindromer)} palindromer') | |
print(f'Av de {len(palindromer)} palindromtallene, er {len(palindromprimtall)} også primtall') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment