Update: I know that I have questioned very badly. Here is a second run. Consider the following functions: First of all I am making the list generated list for N = 5: , the function takes each element into the list and compares its list with itself, such that you do this : Saying that I am comparing [0, 0, 5] against [3, 1, 1]. Loses 0 to 3 (no points), loses 0, no number, 5 wins against 1 (1 point for that). A draw gets 0.5 points, one win becomes 1 point. For any item, if the win is greater than losing, then that item is considered optimum and it is added to the optimum list. For n = 5, the optimal list is: My question is that I have a short way How can I write the above mentioned work? I am particularly interested in functional algorithms, answers to Python, Ruby, Java, Haskell will be appreciated. (After saying this, if you have a clean solution in any language, then okay.) Sorry to repeat the same question. I agree that the original question was messy and there was a problem in understanding. I hope this is now clear. Update (on the comment of rampion): Is there a skilled algorithm for this (or thus) problem? Second Update : Great - now I understand what you want . This is similar to the code in your most recent edit: If you want to see the previous versions of this answer, check the edit; It was getting too long
myList = [] optimal = address [] def findOptimumListItems (): n = 5 i range (N + 1 ): For the range in Jammu (n + 1 - i): myList.append ((i, j, nij)) for my list: win = 0.0 draw = 0.0 j in myList: score = 0 [0]> J [0]: Score + = 1 if (i [0] == j [0]): Score + = 0.5 if (i [1]> gt [1]): score = = 1 if (i [1] == j [1]): score + = 0.5 if (i [2]> j [2]): score + = 1 if (i [2] == j [2] ): Score + = 0.5 if (score == 2): win = = 1 if (score == 1.5): Draw = 1 if (win / (Lynn (Marylist) -Wine-draw)> 1.0): OptimumList.append (i) Maximum optimal list
[(0, 0, 5, 0,), (0, 5,), (0, 1, 4), (0, 2, 3), (0, 3, 2), (0, 4, 1) 4), (1, 1, 3), (1, 2, 2), (1, 3, 1) (1, 4, 0), (2, 0, 3), (2, 1, 2) (3, 2, 2), (4, 0, 1), (4 , 1, 0), (5, 0, 0)]
[(0, 2, 3), (0, 3, 2), (1, 1, 3) ), (1, 2, 2), (1, 3, 1), (2, 0, 3) (2, 1, 2), (2, 2, 1), (2, 3, 0), 3, 0, 2), (3, 1, 1), (3, 2, 0)]
def optimize (myList): score_tup = lambda tup_a, tup_b: sum (1.0 if A> B other 0.5 if a = = (I) for tup_a in mylist) score for tup_a in mylist = ((tupa, score quote) 2) scores in scores score (1.5) for scores) score in tup, win, score for tup ( Win * 1.0 / (Lane (Marylist) - Win - Draw)) gt; 1.0] myList Print Optimization (myList) for i in range (a + 1) in (a + 1 - i)] for a = 5 myList = [i +, i, j, aij] category < / Pre>
Comments
Post a Comment