| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- 상합
- 프랙탈
- 지오지브라
- 구분구적법
- java
- 수학탐구
- 리만합
- 피타고라스 정리
- 제곱근의뜻
- 정오각형
- 이항분포
- 시뮬레이션
- 몬테카를로
- algeomath
- 확률실험
- 알지오매스
- 블록코딩
- counting sunday
- 하합
- python
- 삼각함수의그래프
- 파이썬
- Geogebra
- 재귀함수
- project euler
- 작도
- 큰수의법칙
- 큰 수의 법칙
- 오일러
- 프로젝트 오일러
- Today
- Total
이경수 선생님의 수학실험실
Problem 4(Largest palindrome product) 본문
Problem 4(Largest palindrome product)
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
In Python:
product=0; result=0; num=[]
for i in range(100, 1000):
for j in range(100, 1000):
product=i*j
num=str(product)
if num==num[::-1]:
if product>result:
result=product
print(result)
Run time: 1.6162359714508057 seconds
In Java:
package project_euler;
import java.util.ArrayList;
public class Euler4 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
ArrayList<Integer> numList1 = new ArrayList<Integer>();
ArrayList<Integer> numList2 = new ArrayList<Integer>();
int product = 0;
int result = 0;
for (int i = 100; i < 1000; i++) {
for (int j = 100; j < 1000; j++) {
product = i * j;
while (product > 0) {
numList1.add(product % 10);
numList2.add(0, product % 10);
product /= 10;
}
if (numList1.equals(numList2)) {
if (i * j > result) {
result = i * j;
}
}
numList1.clear();
numList2.clear();
}
}
System.out.println(result);
long endTime = System.currentTimeMillis();
System.out.println((double)(endTime - startTime)/(double)1000 +"seconds");
System.out.println((endTime - startTime) +"ms");
}
}
Run time: 1.022seconds, 1022ms
solution: 906609
[from Project Euler: https://projecteuler.net/problem=4]
'Project Euler' 카테고리의 다른 글
| Problem 6(Sum square difference) (0) | 2019.02.08 |
|---|---|
| Problem 5(Smallest multiple) (0) | 2019.02.08 |
| Problem 3(Largest prime factor) (0) | 2019.02.06 |
| Problem 2(Even Fibonacci numbers) (0) | 2019.02.06 |
| Problem 1(Multiples of 3 and 5) (0) | 2019.02.06 |