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
- 유체역학
- Boundary Layers
- python3
- Finite Difference Method
- Navier-Stokes
- regression
- 프로젝트오일러
- Blasius
- Turbulent
- Fluids
- Python
- 파이썬
- projecteuler
- 회귀
- Statistics
- Fluid Dynamics
- programmers
- 예제
- Compressible Flow
- 통계학
- 우선순위큐
- 이중우선순위큐
- FTCS
- 프로그래머스
- Heat Equation
- Laminar
- 힙
- heap
- 디스크 컨트롤러
- Crank-Nicolson
Archives
- Today
- Total
Sudal's Garage
Project Euler 28 본문
Question:
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
21 22 23 24 25
20 7 8 9 10
19 6 1 2 11
18 5 4 3 12
17 16 15 14 13It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
문제:
1부터 시작해서 오른쪽으로 움직인 뒤 시계방향으로 숫자를 적어나가는 방식으로 나선을 만든다고 하자. 5*5 크기의 나선은 다음과 같이 만들어진다.
21 22 23 24 25
20 7 8 9 10
19 6 1 2 11
18 5 4 3 12
17 16 15 14 13위 나선에서 빨간색으로 표시된 대각선 위의 수들의 합은 101이다.
같은 방식으로 1001*1001 크기의 나선을 만들고 대각선 위의 수들의 합을 구하면 얼마일까?
Solution:
def diagsum(N): result = 1 fn = [1] for i in range(1,int((N+1)/2)): fn.append(fn[-1] + 2 + 8 * (i-1)) a = [fn[-1] + x * i * 2 for x in range(0,4)] result += sum(a) return print("The diagonal sum of {0} X {0} sprial is: {1}".format(N,result))
diagsum(N) 은 N x N 크기의 나선들의 합을 계산한다.
fn 에는 더해지는 숫자들을 넣는다. 각 n번째 사각형 모서리들의 숫자들의 관계식을 구한다.
'Programming > Project Euler - python' 카테고리의 다른 글
Project Euler 30 (0) | 2019.03.18 |
---|---|
Project Euler 29 (0) | 2019.03.17 |
Project Euler 26 (0) | 2019.03.16 |
Project Euler 27 (0) | 2019.03.15 |
Project Euler 25 (0) | 2019.03.13 |