am_dot_com

IA 2022-10-24

Oct 24th, 2022 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. # 4.py
  2.  
  3. """
  4. ferramenta #1
  5. auxiliar para a geração de modelos
  6. """
  7. def getListOfAlternatingTrueFalse(
  8. piHowManyValues:int,
  9. piAlternateEveryN:int=1,
  10. pbStartValue:bool=True
  11. ):
  12. retList = list()
  13. retList = []
  14.  
  15. bCurrentValue = pbStartValue
  16. while(len(retList)<piHowManyValues):
  17. retList.append(bCurrentValue)
  18. bAlternateTime:bool = \
  19. len(retList)%piAlternateEveryN == 0
  20. if(bAlternateTime):
  21. bCurrentValue = not bCurrentValue
  22. # while
  23.  
  24. return retList
  25. # def getListOfAlternatingTrueFalse
  26.  
  27. """
  28. l1 = getListOfAlternatingTrueFalse(
  29. 33,
  30. piAlternateEveryN=4,
  31. pbStartValue=True
  32. )
  33. print (l1)
  34. """
  35.  
  36.  
  37. """
  38. 1 prop (1 var) => basta 1 lista q alterne de 1-1
  39. 2 props (2 vars) => 2 listas (1-1 , 2-2)
  40. 3 props (3 vars) => 3 listas (1-1 , 2-2, 4-4)
  41. n props (n vars) => n listas (2**0=1, 2**1=2, ... 2**n-1)
  42. ferramenta auxiliar para compilar todas as listas
  43. de combinações possíveis
  44. """
  45. def getAllPossibleAlternatingListsForNProps(
  46. pN:int=2,
  47. pbStartValue:bool=True
  48. ):
  49. retListOfLists = list()
  50.  
  51. iHowManyCombosThereAreForNProps = 2**pN
  52. iCurrentList = 0
  53. while(len(retListOfLists)<pN):
  54. listOfAlternatingValues = \
  55. getListOfAlternatingTrueFalse(
  56. piHowManyValues=iHowManyCombosThereAreForNProps,
  57. piAlternateEveryN=2**iCurrentList,
  58. pbStartValue=pbStartValue
  59. )
  60. retListOfLists.append(listOfAlternatingValues)
  61. iCurrentList+=1
  62. # while
  63. return retListOfLists
  64. # def getAllPossibleAlternatingListsForNProps
  65.  
  66. """
  67. l2 = getAllPossibleAlternatingListsForNProps(3)
  68. print (l2)
  69. """
  70.  
  71. def getAllModelsForNProps(
  72. pN:int=2,
  73. pbStartValue:bool=True
  74. ):
  75. retListOfAllPossibleModels = list()
  76.  
  77. listAlts =\
  78. getAllPossibleAlternatingListsForNProps(
  79. pN=pN,
  80. pbStartValue=pbStartValue
  81. )
  82.  
  83. for idxValue in range(2**pN):
  84. currentModel = list()
  85. for idxListAlt in range(len(listAlts)):
  86. currentList = listAlts[idxListAlt]
  87. bCurrentValue:bool = currentList[idxValue]
  88. currentModel.append(bCurrentValue)
  89. # for
  90. # a new model is ready
  91.  
  92. currentModel.reverse() # in-place
  93. retListOfAllPossibleModels.append(
  94. currentModel
  95. )
  96. # for
  97.  
  98. return retListOfAllPossibleModels
  99. # def getAllModelsForNProps
  100.  
  101. """
  102. models = getAllModelsForNProps(3)
  103. print(models)
  104. """
  105.  
  106. def getAllDictModelsForNamedProps(
  107. pListNamedProps = ["a", "b", "c"]
  108. ):
  109. retListOfDictModels = list()
  110.  
  111. iHowManyProps = len(pListNamedProps)
  112. allModels = getAllModelsForNProps(pN=iHowManyProps)
  113.  
  114. for idxModel in range(len(allModels)):
  115. currentModel = allModels[idxModel]
  116. newDictModel = dict()
  117. for idxProp in range(len(pListNamedProps)):
  118. strCurrentProp = pListNamedProps[idxProp]
  119. bCurrentValue:bool = currentModel[idxProp]
  120. newDictModel[strCurrentProp] = bCurrentValue
  121. # for
  122. # new model (as dict)
  123. retListOfDictModels.append(newDictModel)
  124. # for
  125.  
  126. return retListOfDictModels
  127. # def getAllDictModelsForNamedProps
  128.  
  129. allModelsAsDicts = getAllDictModelsForNamedProps(
  130. ["troveja", "chove", "durmo"]
  131. )
  132. print(allModelsAsDicts)
Advertisement
Add Comment
Please, Sign In to add comment