Help us understand the problem. What is going on with this article?

Project Euler 49「素数数列」

More than 1 year has passed since last update.

2つ前の激遅コードを自分なりに高速化しようと試みるもパクり以外に思いつかない。
なので気分転換に先へ進む。
もうちょっと成長したら再トライしようと思う。(多分しない)

Problem 49 「素数数列」

項差3330の等差数列1487, 4817, 8147は次の2つの変わった性質を持つ.

(i)3つの項はそれぞれ素数である.
(ii)各項は他の項の置換で表される.
1, 2, 3桁の素数にはこのような性質を持った数列は存在しないが, 4桁の増加列にはもう1つ存在する.

それではこの数列の3つの項を連結した12桁の数を求めよ.

def hoge():
    f = lambda n: sorted(list(str(n)))
    for n in range(1000, 3340): # 10000 - 6660 = 3340
        if n == 1487: continue # 問の例はスキップ
        N = [ n + 3330 * i for i in range(3) ]
        if all( is_prime(m) for m in N ) and \
           f(N[0]) == f(N[1]) == f(N[2]):
            return ''.join( str(m) for m in N )

def is_prime(n):
    if n < 2: return False
    if n == 2: return True
    if n % 2 == 0: return False
    return all(n % i != 0 for i in range(3, int(n ** 0.5) + 1, 2))

print(hoge())
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away