Differences between revisions 3 and 4
Revision 3 as of 2006-01-31 14:45:13
Size: 1181
Editor: 143
Comment:
Revision 4 as of 2006-01-31 15:40:15
Size: 1177
Editor: 143
Comment:
Deletions are marked like this. Additions are marked like this.
Line 35: Line 35:
||mgenome ||||<style="TEXT-ALIGN: center">173초 ||||<style="TEXT-ALIGN: center">15.5초 ||
||yong27 ||||<style="TEXT-ALIGN: center">107초 ||||<style="TEXT-ALIGN: center">12.7초 ||
||mgenome ||||<style="TEXT-ALIGN: center">164초 ||||<style="TEXT-ALIGN: center">10초 ||
||yong27 ||||<style="TEXT-ALIGN: center">82초 ||||<style="TEXT-ALIGN: center">8.6초 ||

[Recursion]을 써서 만들었습니다.

--- ["yong27"] 님 감사합니다.

   1 def ThreePlusOne(n, count=0):
   2     count += 1
   3     if n==1:
   4         return count
   5     elif n%2==0:
   6         return ThreePlusOne(n/2, count) # return을 빼먹으면 None이  리턴
   7     else:
   8         return ThreePlusOne(n*3+1, count) #return을 빼먹으면 None이 리턴
   9         
  10 def main():
  11     i, j = raw_input().split()
  12 
  13     b = 0
  14     for a in range(int(i), int(j)+1):
  15         temp = ThreePlusOne(a)
  16         if b < temp: b = temp
  17     print i, j, b
  18 
  19 if __name__ == '__main__':
  20     #import psyco
  21     #psyco.bind(main)
  22     main()

속도를 재서 다른 분들과 비교해 봤습니다. input이 1 999999 일때.

작성자

걸린시간

[Psyco]를 쓴 후 걸린 시간

mgenome

164초

10초

yong27

82초

8.6초

windist

9.5초

3.5초

3N+1Problem 참조

AlgorithmQuiz/3Plus1/mgenome (last edited 2013-08-09 16:13:17 by 61)

web biohackers.net