Python Implementation of Optimal Sample Variance for Voyager 2’s Spaceflight

As such, I think the best way to assess the optimal sample is to then sort our scores with the following structure:#create list of paired planets and scoresscoreRanks = [[planetA, planetB], score-of-planetA-to-planetB],…]Sorting in ascending order leaves us with:import operatorscoreRanks = sorted(scoreRanks, key=itemgetter(1))Lastly, say we want to retrieve 3-planets that represents the best combination for maximising variance and minimising cost..We can achieve this by recursively iterating through our sorted scoreRanks .def planetCombination(self, scoreRanks, length=3, result): #iteratively determine optimal ranking and then return the top-number of hits determined by LENGTH if len(set(result)) == length: return result else: #pull highest value if len(result) == 0: result.append(scoreRanks[0][0][0]) result.append(scoreRanks[0][0][1]) #find highest value from last item for entry in scoreRanks: if entry[0][0] == result[:-1] and entry[0][0] not in result: result.append(entry[0][0]) self.planetCombination(scoreRanks=scoreRanks, result=result)Our final outputted list will show us a list of a combination of three planets (our requirement of three is a fixed-input in this example, assigned as the variable length ), that satisfies our base-case.Github link is here.The above is an unoptimised solution..If you can think of any superior alternatives or suggestions please let me know!Thanks!. More details

Leave a Reply