LoginSignup
1
0

More than 5 years have passed since last update.

Project Euler 36「二種類の基数による回文数」

Posted at

Problem 36 「二種類の基数による回文数」

585 = 10010010012 (2進) は10進でも2進でも回文数である.
100万未満で10進でも2進でも回文数になるような数の総和を求めよ.
(注: 先頭に0を含めて回文にすることは許されない.)

def hoge(num):
    for n in range(1, num):
        str_n = str(n)
        if str_n != str_n[::-1]:
            continue
        n2 = format(n, 'b')
        if n2 == n2[::-1]:
            yield n

print(sum(hoge(1000000)))

そのまんま。
やたら頭使うのとそうでないののギャップが激しいですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0