Browse Source

打印出所有排列组合数

duh 6 years ago
parent
commit
6494d50856
3 changed files with 42 additions and 13 deletions
  1. 13 7
      phxb/elab/utils/GetAllModule.py
  2. 0 5
      phxb/elab/utils/GetArray.py
  3. 29 1
      phxb/elab/utils/GetArray2.py

+ 13 - 7
phxb/elab/utils/GetAllModule.py

@@ -4,11 +4,17 @@ from pyautocad import Autocad, APoint
 #这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
 acad = Autocad(create_if_not_exists = True)
 acad.prompt("Hello, Autocad from Python\n")
-print(acad.doc.Name)
-
-#遍历cad图形对象
-for obj in acad.iter_objects():
+# print(acad.doc.Name)
+def printObjects():
+  #遍历cad图形对象
+  for obj in acad.iter_objects():
     print(obj.ObjectName)
-#按类型查找出所有某种图元
-for text in acad.iter_objects('Text'):
-    print(text.TextString, text.InsertionPoint)
+def printTheTypeObject(type):
+  #按类型查找出所有某种图元
+  for text in acad.iter_objects(type):
+    print(text.TextString, text.InsertionPoint)
+
+printObjects()
+print("-------")
+# printTheTypeObject('Text')
+printTheTypeObject('Circle')

+ 0 - 5
phxb/elab/utils/GetArray.py

@@ -1,5 +0,0 @@
-def getArray(n):
-  if(n<=1):
-    return n;
-  else:
-    return n*getArray(n-1);

+ 29 - 1
phxb/elab/utils/GetArray2.py

@@ -7,6 +7,10 @@ def jieChen(n):
         myArray[i] = (i+1)*myArray[i-1];
         i = i+1
     return myArray;
+def jieChenNumber(n):
+    if(n <= 1):
+        return 1;
+    return jieChen(n)[n-1];
 #辗转相除法进行进制转化
 def changeInt2Str(i,m):
     if(not isinstance(m,int)):
@@ -36,6 +40,30 @@ def getAllArray(m,n):
         allArray[index]=itemIndex
         index = index+1
     print(allArray)
+#获取单个组合的各边重复项
+def getitemIndexArray(itemIndex,n):
+    a = {};
+    for item in range(n):
+        index = 0;
+        indexNum = 0;
+        while(index < n):
+            if(itemIndex[index] == str(item)):
+                indexNum = indexNum + 1
+            index = index+1
+        a[item]=indexNum
+    print(a)
+    return a
+def getitemIndexArrayNumber(itemIndex,n):
+    itemIndexArrayNumber = 0;
+    a = getitemIndexArray(itemIndex,n)
+    for item in a:
+        intItem = int(a[item])
+        if(intItem > 1):
+            itemIndexArrayNumber = jieChenNumber(intItem)+itemIndexArrayNumber
+    return itemIndexArrayNumber
 # result = changeInt2Str(14,3);
 # print(result)
-getAllArray(2,3)
+# getAllArray(4,3)
+# getitemIndexArray("01200",5)
+number = getitemIndexArrayNumber("01200",5)
+print(number)