Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. class n():
  2. """ Creates a class for a score - returns rep and has inbuilt attribute for
  3. whether or not a double has been scored thus allowing the player to finish
  4. """
  5. def __init__(self, n):
  6. self.n = n
  7. self.double_test = False
  8. self.rep = str(n)
  9.  
  10. def __repr__(self):
  11. return self.rep
  12.  
  13. def single(self):
  14. self.rep = "S" + str(self.n)
  15.  
  16. def double(self):
  17. self.double_test = True
  18. self.rep = "D" + str(self.n)
  19. self.n = self.n*2
  20.  
  21. def triple(self):
  22. self.rep = "T" + str(self.n)
  23. self.n = self.n*3
  24.  
  25.  
  26.  
  27. #make list to contain all possible darts
  28. scores = []
  29. scores.append(n(0))
  30. for i in range(1,20):
  31. #append single score
  32. dart = n(i)
  33. dart.single()
  34. scores.append(dart)
  35.  
  36. #append double score
  37. dart = n(i)
  38. dart.double()
  39. scores.append(dart)
  40.  
  41. # append triple score
  42. dart = n(i)
  43. dart.triple()
  44. scores.append(dart)
  45.  
  46. # inner and outer bull
  47. dart = n(25)
  48. dart.single()
  49. scores.append(dart)
  50.  
  51. dart = n(25)
  52. dart.double()
  53. scores.append(dart)
  54.  
  55.  
  56. # ------------------ MAIN ----------------------
  57.  
  58. target = 6
  59.  
  60. # get all combinations which add up to target
  61. outs = [ [i,j,k] for i in scores for j in scores for k in scores if i.n + j.n + k.n == target ]
  62.  
  63.  
  64. """
  65.  
  66. # sort first two values
  67. for i in range(len(outs)):
  68. # make temp list of first two values
  69. _temp = [ outs[i][0],outs[i][1] ]
  70. # sort this list
  71. sorted(_temp, key = lambda score : score.n)
  72. # replace first to values with sorted values
  73. outs[i][0] = _temp[0]
  74. outs[i][1] = _temp[1]
  75. """
  76.  
  77. # sort first two values
  78. for i in range(len(outs)):
  79. if outs[i][0].n > outs[i][1].n:
  80. outs[i][0], outs[i][1] = outs[i][1], outs[i][0]
  81.  
  82.  
  83. # find unique outs
  84. sorted_outs = []
  85. for i in outs :
  86. if i not in sorted_outs:
  87. sorted_outs.append(i)
  88.  
  89. # append only scores which finish on a double
  90. final_outs = []
  91. for i in outs:
  92. if i[2].double_test == True:
  93. final_outs.append(i)
  94. else: pass
  95.  
  96. print(*final_outs, sep = "n")
Add Comment
Please, Sign In to add comment