Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69373793f5a867f769cde137 Challenge 152: Circular Prime 29 challenge-152

--description--

Given an integer, determine if it is a circular prime.

A circular prime is an integer where all rotations of its digits are themselves prime.

For example, 197 is a circular prime because all rotations of its digits: 197, 971, and 719, are prime numbers.

--hints--

is_circular_prime(197) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_circular_prime(197), True)`)
}})

is_circular_prime(23) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_circular_prime(23), False)`)
}})

is_circular_prime(13) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_circular_prime(13), True)`)
}})

is_circular_prime(89) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_circular_prime(89), False)`)
}})

is_circular_prime(1193) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_circular_prime(1193), True)`)
}})

--seed--

--seed-contents--

def is_circular_prime(n):

    return n

--solutions--

import math
def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(math.isqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

def rotations(n):
    s = str(n)
    return [int(s[i:] + s[:i]) for i in range(len(s))]

def is_circular_prime(n):
    return all(is_prime(rot) for rot in rotations(n))