Note that there are some explanatory texts on larger screens.

plurals
  1. POCode golf: combining multiple sorted lists into a single sorted list
    text
    copied!<p>Implement an algorithm to merge an arbitrary number of sorted lists into one sorted list. The aim is to create the smallest working programme, in whatever language you like.</p> <p>For example:</p> <pre><code>input: ((1, 4, 7), (2, 5, 8), (3, 6, 9)) output: (1, 2, 3, 4, 5, 6, 7, 8, 9) input: ((1, 10), (), (2, 5, 6, 7)) output: (1, 2, 5, 6, 7, 10) </code></pre> <p><strong>Note</strong>: solutions which concatenate the input lists then use a language-provided sort function are not in-keeping with the spirit of golf, and will not be accepted:</p> <pre><code>sorted(sum(lists,[])) # cheating: out of bounds! </code></pre> <p>Apart from anything else, your algorithm <em>should</em> be (but doesn't have to be) a lot faster!</p> <p>Clearly state the language, any foibles and the character count. Only include meaningful characters in the count, but feel free to add whitespace to the code for artistic / readability purposes.</p> <p>To keep things tidy, suggest improvement in comments or by editing answers where appropriate, rather than creating a new answer for each "revision".</p> <p><strong>EDIT</strong>: if I was submitting this question again, I would expand on the "no language provided sort" rule to be "don't concatenate all the lists then sort the result". Existing entries which do concatenate-then-sort are actually very interesting and compact, so I won't retro-actively introduce a rule they break, but feel free to work to the more restrictive spec in new submissions.</p> <hr> <p>Inspired by <a href="https://stackoverflow.com/questions/464342/combining-two-sorted-lists-in-python">Combining two sorted lists in Python</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload