程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Guess the age of American mathematician Wiener

編輯:Python

Title Description
         American mathematician Wiener (N.Wiener) Precocious intelligence ,11 I went to college at the age of . He was in 1935~1936 He was invited to give a lecture in Tsinghua University, China . once , He attended some important meeting , Young faces stand out . So someone asked his age , And he said :“ The cube of my age is 4 digit . Of my age 4 The power is a 6 digit . this 10 The number contains exactly from 0 To 9 this 10 A digital , Every one happens to be 1 Time .” Please program the output of Wiener's age in that year .
‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬

Ideas

     First if...else... sentence , Limit the range of numbers , Age i A bit of the third power of 、 ten 、 Hundred bit 、 Thousands of digits are added to the empty list L1 in , Will age i A bit of the fourth power of 、 ten 、 Hundred bit 、 Thousand bit 、 Ten thousand position 、 Add 100000 digits to the empty list L2 in . Yes L1、L2 Merge the two lists to remove duplicates , Use when removing weight set() obtain L4, Yes L4,L3 Sort sort()( This is the key , Compare dishes stuck in this half day ), Last , contrast L4 Is it equal to L3. Output age i.

L1 = []
L2 = []
L4 = []
L3 = [0,1,2,3,4,5,6,7,8,9]
for i in range(0, 101):
if(i**3>=1000 and i**3<=9999 and i**4>=100000 and i**4<=999999):
L1.append((i**3)%10)
L1.append((i**3)/10%10)
L1.append((i**3)/100%10)
L1.append((i**3)/1000%10)
L2.append((i**4)%10)
L2.append((i**4)/10%10)
L2.append((i**4)/100%10)
L2.append((i**4)/1000%10)
L2.append((i**4)/10000%10)
L2.append((i**4)/100000%10)
L4 = L1 +L2
L4 = list(set(L4))
L4 = L4.sort()
L3 = L3.sort()
if(L4 == L3):
print(i)
break
else:
print(i)
continue
else:
continue

  This method is stupid for reference only ( There are good ways to exchange and learn from each other in the comment area Hey, hey, hey )


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved