일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 삼각함수의그래프
- 알지오매스
- 큰수의법칙
- 피타고라스 정리
- 블록코딩
- 이항분포
- 정오각형
- 재귀함수
- 지오지브라
- 구분구적법
- java
- 상합
- 작도
- 큰 수의 법칙
- 제곱근의뜻
- 리만합
- 파이썬
- 하합
- 프랙탈
- Geogebra
- 오일러
- 시뮬레이션
- 수학탐구
- 프로젝트 오일러
- project euler
- counting sunday
- python
- 몬테카를로
- algeomath
- 확률실험
- Today
- Total
이경수 선생님의 수학실험실
Problem 15(Lattice paths) 본문
Problem 15(Lattice paths)
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a 20×20 grid?
In Python:
#PE14 Longest Collatz sequence
import time
start_time = time.time()
lenChain = []
for num in range(2, pow(10, 6)):
i = 0
while num > 1:
i += 1
if num % 2 == 0:
num /= 2
else:
num = 3 * num + 1
lenChain.append(i)
print(lenChain.index(max(lenChain))+2)
print(time.time() - start_time, "seconds")
Run Time: 0.00011491775512695312 seconds
In Java:
//Euler15 Lattice paths
package project_euler;
public class Euler15 {
public static double factorial(int n) {
if (n == 1) {
return 1;
}
else {
return n * factorial(n-1);
}
}
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
double result = 0;
result = factorial(40) / (factorial(20) * factorial(20));
System.out.println((long)result);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime) / (double)1000 + "seconds");
}
}
Run time: 0.001seconds
Solution: 137846528820
[from Project Euler: https://projecteuler.net/problem=15]
'Project Euler' 카테고리의 다른 글
problem17 (Number letter counts) (0) | 2019.02.14 |
---|---|
problem16 (Power digit sum) (0) | 2019.02.14 |
Problem 14(Longest Collatz sequence) (0) | 2019.02.10 |
Problem 13(Large sum) (0) | 2019.02.10 |
Problem 12(Highly divisible triangular number) (0) | 2019.02.10 |