sorting

haskell sorting

ぃ、小莉子 提交于 2021-02-07 12:11:17
问题 How can it be done in most simply way to write (or maybe there is something embedded in haskell) function which takse as arguments list of tuples (String, Int) and Int x and return top x tuples as list according to x value. I wonder if its possible to write a function which also takes 3 argument which is the name of (or index) of filed in tuple according to which sorting has to be done. What are best solutions to make it quite generic? 回答1: take x $ sortBy (compare `on` fst) [("asd", 1), ...]

haskell sorting

喜夏-厌秋 提交于 2021-02-07 12:01:09
问题 How can it be done in most simply way to write (or maybe there is something embedded in haskell) function which takse as arguments list of tuples (String, Int) and Int x and return top x tuples as list according to x value. I wonder if its possible to write a function which also takes 3 argument which is the name of (or index) of filed in tuple according to which sorting has to be done. What are best solutions to make it quite generic? 回答1: take x $ sortBy (compare `on` fst) [("asd", 1), ...]

Fastest gap sequence for shell sort?

。_饼干妹妹 提交于 2021-02-07 11:17:23
问题 According to Marcin Ciura's Optimal (best known) sequence of increments for shell sort algorithm, the best sequence for shellsort is 1, 4, 10, 23, 57, 132, 301, 701..., but how can I generate such a sequence? In Marcin Ciura's paper, he said: Both Knuth’s and Hibbard’s sequences are relatively bad, because they are defined by simple linear recurrences. but most algorithm books I found tend to use Knuth’s sequence: k = 3k + 1, because it's easy to generate. What's your way of generating a

Fastest gap sequence for shell sort?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 11:15:22
问题 According to Marcin Ciura's Optimal (best known) sequence of increments for shell sort algorithm, the best sequence for shellsort is 1, 4, 10, 23, 57, 132, 301, 701..., but how can I generate such a sequence? In Marcin Ciura's paper, he said: Both Knuth’s and Hibbard’s sequences are relatively bad, because they are defined by simple linear recurrences. but most algorithm books I found tend to use Knuth’s sequence: k = 3k + 1, because it's easy to generate. What's your way of generating a

sorting list of cards

最后都变了- 提交于 2021-02-07 11:00:51
问题 I have two lists: card_candidates = ['9D', '9S', '3S', '0D'] card_order = ['2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K', 'A'] I want to be able to sort the first list with respect to the second lists order. So the sorted card_candidates should look like this: sorted_candidates = ['3S', '9D', '9S', '0D'] The '0' is just the value of 10, just wanted to make all the cards the same length. If there is a tie, like with '9D' and '9S', then the letters will need to be sorted instead.

sort a dictionary <object, List<int>> c#

旧时模样 提交于 2021-02-07 10:56:19
问题 I would like to sort a list of objects, The structure is a Dictionary<Object, List<int>> items in the dictionary would be item_1, (2,2,3) item_2, (1,3,4) item_3, (2,3,4) item_4, (1,2) once the items are sorted they should appear as item_4, 1,2 item_2, 1,3,4 item_1, 2,2,3 item_3, 2,3,4 so, essentially I have to sort on the first item in the list, then the second item, then the 3rd items, what would be an easy way of implementing such a solution using linq 回答1: What you need is a custom

Swift - Sorting an array retrieved from Core Data [duplicate]

只愿长相守 提交于 2021-02-07 10:32:39
问题 This question already has an answer here : Sorting Array received from Core Data in Swift (1 answer) Closed 6 years ago . I want to sort the array with usernames that I retrieve from my core data. I retrieve it like this: override func viewDidAppear(animated: Bool) { let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate let context:NSManagedObjectContext = appDel.managedObjectContext! let freq = NSFetchRequest(entityName: "User") let en = NSEntityDescription

Python: Sort a list of strings composed of letters and numbers [duplicate]

耗尽温柔 提交于 2021-02-07 09:30:45
问题 This question already has answers here : Is there a built in function for string natural sort? (19 answers) Closed 2 years ago . I have a list that its elements are composed of a letters and numbers as shown below : ['H1', 'H100', 'H10', 'H3', 'H2', 'H6', 'H11', 'H50', 'H5', 'H99', 'H8'] I wanted to sort it, so I used the function sort, but I got as output : >>> a = ['H1', 'H100', 'H10', 'H3', 'H2', 'H6', 'H11', 'H50', 'H5', 'H99', 'H8'] >>> print sorted(a) ['H1', 'H10', 'H100', 'H11', 'H2',

Sort Colour / Color Values

北城以北 提交于 2021-02-07 09:20:28
问题 Im looking to align the following array of colours as precisely as possible. After searching & trying many solutions suggested on Stackoverflow, the pusher.color library has the best solution, however, it too is far from perfect. I would like to hear solutions on how we can align them perfectly. JSFIDDLE LINK : http://jsfiddle.net/dxux7y3e/ Code: var coloursArray=['#FFE9E9','#B85958','#FFB1AE','#FFC2BF','#C55E58','#FFC7C4','#FF9A94','#FF9D96','#FA9790','#A78B88','#A78B88','#CE675B','#DB8073',

Java: sorting an array with lambda expression?

て烟熏妆下的殇ゞ 提交于 2021-02-07 09:17:05
问题 I've recently got into functional programming and Java 8 lambdas. I have an array of ints and I want to sort it in an ascending order. The way I am trying to do this with lambda is as follows: Arrays.stream(intArray).sorted((x, y) -> Integer.compare(x, y) == -1); The issue with this is that my compiler says: Error:(12, 32) java: method sorted in interface java.util.stream.IntStream cannot be applied to given types; required: no arguments found: (x,y)->Int[...]== -1 reason: actual and formal