Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 통계학
- 유체역학
- 예제
- Heat Equation
- programmers
- Blasius
- 파이썬
- Turbulent
- heap
- 프로그래머스
- Compressible Flow
- regression
- FTCS
- 프로젝트오일러
- 디스크 컨트롤러
- projecteuler
- 회귀
- Statistics
- Fluid Dynamics
- Python
- Laminar
- Fluids
- Navier-Stokes
- 이중우선순위큐
- Boundary Layers
- 힙
- Crank-Nicolson
- python3
- 우선순위큐
- Finite Difference Method
Archives
- Today
- Total
Sudal's Garage
Project Euler 36 본문
Question:
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
(Please note that the palindromic number, in either base, may not include leading zeros.)
문제:
십진수 585를 이진수로 표현하면 다음과 같다. 585 = 10010010012 그리고 이 수는 십진법으로도 이진법으로도 회문이다.(거꾸로 읽어도 같은 수, palindrome)
백만보다 작은 십진법으로도 이진법으로도 회문인 모든 수의 합을 구하여라.
(십진법, 이진법 모두 0으로 시작하는 수는 고려하지 않는다.)
Solution:
import time start = time.time() numbers = [] for i in range(1,1000001): if list(str(i)) == list(reversed(str(i))): # 10진법 일 때 회문인가? if list(bin(i)[2:]) == list(reversed(bin(i)[2:])): # 2진법 일 때 회문인가? numbers.append(i) print(sum(numbers)) print("Found in ...%.3fs" %(time.time() - start))
bin(n): n 을 2진법으로 바꾸어준다.
ex) bin(2796202)
'0b1010101010101010101010'
앞 0b는 2진법임을 나타낸다.
회문임을 확인하는 방법은 그냥 list 로 만든 후, 거꾸로 뒤집어서 같은지 확인했다.
1.2초 걸렸다.
'Programming > Project Euler - python' 카테고리의 다른 글
Project Euler 38 (0) | 2019.03.31 |
---|---|
Project Euler 37 (0) | 2019.03.30 |
Project Euler 35 (0) | 2019.03.28 |
Project Euler 34 (0) | 2019.03.27 |
Project Euler 33 (0) | 2019.03.26 |