티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | string="" temp=0 for i in range(1,10000): string="" for j in range(1,10): if(len(string)+len(str(i*j))>9): break string=string+str(i*j) if(len(string)==9): #이 안에서 팬디지털 판정 if((string.find('1')!=-1 and string.find('2')!=-1 and string.find('3')!=-1 and string.find('4')!=-1 and string.find('5')!=-1 and string.find('6')!=-1 and string.find('7')!=-1 and string.find('8')!=-1 and string.find('9')!=-1)) and string.find('0')==-1: if(temp<int(string)): temp=int(string) print(temp) | cs |
find 함수 사용 시 원하는 값을 찾지 못하면 -1을 리턴하는 것을 이용하여
위와 같은 무식한 알고리즘을 짰다.
시작 부분은 아홉 자리 수만 취급하는 알고리즘을 짜는 것이다.
아홉 자리가 넘어가는 수는 아예 생각하지 않게끔 했다.
아홉 자리 수들 중에서 팬디지털 숫자인지를 판정하고,
그 중 가장 큰 수를 구하였다.
'Algorithm > Project Euler' 카테고리의 다른 글
프로젝트 오일러 29번 (0) | 2017.06.29 |
---|---|
프로젝트 오일러 27번 (0) | 2017.06.29 |
프로젝트 오일러 34번 (0) | 2017.06.29 |
프로젝트 오일러 33번 (0) | 2017.06.29 |
프로젝트 오일러 30번 (0) | 2017.06.29 |
댓글