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
- Crank-Nicolson
- heap
- FTCS
- 우선순위큐
- 통계학
- 프로젝트오일러
- Turbulent
- Laminar
- 회귀
- 디스크 컨트롤러
- Compressible Flow
- Heat Equation
- 예제
- Navier-Stokes
- Statistics
- 파이썬
- 이중우선순위큐
- Python
- Finite Difference Method
- 힙
- python3
- Fluids
- projecteuler
- 유체역학
- 프로그래머스
- Fluid Dynamics
- Blasius
- regression
- programmers
Archives
- Today
- Total
Sudal's Garage
Project Euler 39 본문
Question:
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
문제:
세 변의 길이가 모두 양의 정수인 직각삼각형의 둘레가 p일 때, p = 120인 가능한 세 변 {a,b,c}의 솔루션은 세 가지가 있다.
{20,48,52}, {24,45,51}, {30,40,50}
p ≤ 1000인 p 중에서, 가장 가능한 솔루션 개수가 많은 p는 무엇일까?
Solution:
def getb(a,p): # b 계산 b = (p**2 - 2*p*a)/(2*(p-a)) if int(b) == b: # b가 정수인지를 판별 return int(b) return False def getc(a,b,p): # c 계산 return p - a - b # = c def compare(a,b,c): # 대소 판별 if a < b and b < c and a < c: return True return False def lengths(a,p): b = getb(a,p) if not b: # b가 정수가 아님. return False c = getc(a,b,p) if not compare(a,b,c): return False return [a,b,c] final = list() result = list() for p in range(120,1001): result = [p] for a in range(1,int(p/3)): if not lengths(a,p) == False: result += [lengths(a,p)] else: pass if len(result) > len(final): final = result
b가 정수이어야 함으로 이를 이용해서 b, c를 구할 수 있다.
'Programming > Project Euler - python' 카테고리의 다른 글
Project Euler 41 (0) | 2019.04.03 |
---|---|
Project Euler 40 (0) | 2019.04.02 |
Project Euler 38 (0) | 2019.03.31 |
Project Euler 37 (0) | 2019.03.30 |
Project Euler 36 (0) | 2019.03.29 |