|
헤이요~
카테고리
전체trace programming something good letter diary in English 이글루 파인더
이전블로그
2008년 02월2008년 01월 2007년 12월 2007년 11월 2007년 04월 2007년 03월 2007년 02월 2007년 01월 2006년 12월 2006년 11월 2006년 10월 2006년 09월 2006년 08월 2006년 07월 2006년 06월 최근 등록된 덧글
31,32번은 저 보라고 올..by 이정민 at 03/29 Gloridea/ 정말 그런가요.. by 별아이 at 03/26 꿈은 노력으로 얻어져요. .. by Gloridea at 03/26 블로그에 작은 변화를 .. by 이정민 at 03/15 저 이거 퍼갈께요^^ by 뉘집자식 at 03/07 http://www.iomania... by 강진 at 03/06 kj/ ㅎ 일단 고맙구리..... by 별아이 at 03/06 Jesus paid it all를 .. by kj at 03/05 음.. 내가 블레이딩을 .. by kj at 03/05 첨에 깜짝 놀랬네영~ ㅎ by kj at 03/05 최근 등록된 트랙백
Soma style.by How to grow soma sty.. Tramadol meprobamat.. by Soma drug test. Soma massage scho.. by Soma massage. Soma side effects. by Soma intimates. Ashes of soma. by Ashes of soma lyrics. Soma medication. by Prescription medicati.. Best rated interest on.. by Best rated low interes.. Establish business .. by Credit ebook. Chase bank secured.. by Jp morgan chase ba.. Accept credit card p.. by Continental finance.. |
어떤 자연수 n이 있을 때, d(n)을 n의 각 자릿수 숫자들과 n 자신을 더한 숫자라고 정의하자.
예를 들어 d(91) = 9 + 1 + 91 = 101이 때, n을 d(n)의 제네레이터(generator)라고 한다. 위의 예에서 91은 101의 제네레이터이다. 어떤 숫자들은 하나 이상의 제네레이터를 가지고 있는데, 101의 제네레이터는 91 뿐 아니라 100도 있다. 그런데 반대로, 제네레이터가 없는 숫자들도 있으며, 이런 숫자를 인도의 수학자 Kaprekar가 셀프 넘버(self-number)라 이름 붙였다. 예를 들어 1,3,5,7,9,20,31 은 셀프 넘버 들이다. 문제: 1 이상이고 5000 보다 작은 모든 셀프 넘버들의 합을 구하라. generator()와 sumOfSelfnum()에 대해 각각 테스트케이스를 만들어서 해봤는데, num에 5000을 넣고 돌리니.. 흑... 안습이다. 1분 내외의 시간이 걸린다.. 처음 버전에 비하면 정말 빨라진거긴 한데, 0.2초만에 어케 나오게 하는거지? ㅡ.ㅡ;; class selfnumber { private static sumOfSelfnum(num){ def l = (1..<num).toList() l.minus(l.collect{this.generator(it)}).inject(0){sum, it -> sum += it} } private static generator(num){ num.toString().toList().inject(num){ sum , it -> sum += it.toInteger()} } } 참.. 이것은 groovy version이다. ;-) ---------------------------------------------------------------------------------------- 변신~~! class selfnumber { private static sumOfSelfnum(num) { def u = new HashSet(1..<num) def non_selfnums = u.collect { this.generator(it) } u.removeAll(new HashSet(non_selfnums)) u.inject(0) { sum, it -> sum + it } } private static generator(num) { num.toString().toList().inject(num) { sum, it -> sum + it.toInteger() } } } 전문가의 손을 거쳐 탈바꿈한 소스... HashSet()을 사용했구낭... 자료구조니 알고리즘에 무지한 나의 한계가 더욱 파파박 와닿는당..ㅠㅜ
| |||