Skip to content

Commit

Permalink
feat: Implement A065722 Paterson Primes (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij10496 authored Nov 22, 2023
1 parent caff2d3 commit a9364c9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
23 changes: 23 additions & 0 deletions oeis.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def __getitem__(self, key: Union[int, slice]) -> Union[int, Sequence[int]]:
"""Return a slice or a value from an integer sequence."""
raise NotImplementedError

def __iter__(self) -> Iterator[int]:
"""Iterate over the integer sequence."""
for i in count(self.offset):
yield self[i]


class IntegerSequenceFromGenerator(IntegerSequence):
"""IntegerSequence based on a generator.
Expand Down Expand Up @@ -752,6 +757,24 @@ def A002182() -> Iterable[int]:
yield n


@oeis.from_generator(offset=0)
def A065722() -> Iterable[int]:
"""Primes that when written in base 4, then reinterpreted in base 10, again give primes."""
for p in A000040: # pylint: disable=not-an-iterable
# Refer: https://github.com/pylint-dev/pylint/issues/9251
if _is_patterson_prime(p):
yield p


def _is_patterson_prime(n):
import numpy as np
from sympy.ntheory import isprime

base_four_repr = np.base_repr(n, base=4)
base_ten_repr = int(base_four_repr)
return isprime(base_ten_repr)


def main() -> None: # pylint: disable=too-many-branches
"""Command line entry point."""
args = parse_args()
Expand Down
65 changes: 65 additions & 0 deletions tests/test_A065722.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from oeis import A065722


def test_A065722():
from_oeis_org = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
37,
43,
47,
53,
61,
71,
73,
79,
83,
97,
103,
107,
109,
113,
131,
149,
151,
157,
163,
167,
181,
191,
193,
197,
227,
233,
241,
251,
277,
293,
307,
311,
313,
317,
349,
359,
373,
389,
401,
419,
421,
433,
443,
449,
463,
467,
503,
]

assert A065722[: len(from_oeis_org)] == from_oeis_org

0 comments on commit a9364c9

Please sign in to comment.