GetArray2.py 978 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import math
  2. def jieChen(n):
  3. myArray = {};
  4. myArray[0] = 1;
  5. i = 1;
  6. while i<n :
  7. myArray[i] = (i+1)*myArray[i-1];
  8. i = i+1
  9. return myArray;
  10. #辗转相除法进行进制转化
  11. def changeInt2Str(i,m):
  12. if(not isinstance(m,int)):
  13. print("m is not int",m)
  14. return
  15. if(m*i == 0):
  16. return "0";
  17. result = "";i
  18. myarray = {};
  19. while(i>=m):
  20. myarray[myarray.__len__()] = i%m
  21. i=int(i/m)
  22. if(i!=0):
  23. myarray[myarray.__len__()] = i
  24. for item in myarray :
  25. result=str(myarray[item])+result
  26. return result
  27. #获取组合数
  28. def getAllArray(m,n):
  29. allArray = {}
  30. max = math.pow(m,n)
  31. index = 0;
  32. while (index < max):
  33. itemIndex = changeInt2Str(index,m)
  34. while(itemIndex.__len__()<n):
  35. itemIndex = "0"+itemIndex
  36. allArray[index]=itemIndex
  37. index = index+1
  38. print(allArray)
  39. # result = changeInt2Str(14,3);
  40. # print(result)
  41. getAllArray(2,3)