Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>VB is usually not the language of choice for code golf, but here goes anyway.</p> <p>The setup -</p> <pre><code> Dim m1 As List(Of Integer) = New List(Of Integer) Dim m2 As List(Of Integer) = New List(Of Integer) Dim m3 As List(Of Integer) = New List(Of Integer) Dim m4 As List(Of Integer) = New List(Of Integer) m1.Add(1) m1.Add(2) m1.Add(3) m2.Add(4) m2.Add(5) m2.Add(6) m3.Add(7) m3.Add(8) m3.Add(9) Dim m5 As List(Of List(Of Integer)) = New List(Of List(Of Integer)) m5.Add(m1) m5.Add(m2) m5.Add(m3) </code></pre> <p>An attempt in VB.NET (without sort)</p> <pre><code> While m5.Count &gt; 0 Dim idx As Integer = 0 Dim min As Integer = Integer.MaxValue For k As Integer = 0 To m5.Count - 1 If m5(k)(0) &lt; min Then min = m5(k)(0) : idx = k Next m4.Add(min) : m5(idx).RemoveAt(0) If m5(idx).Count = 0 Then m5.RemoveAt(idx) End While </code></pre> <p>Another VB.NET attempt (with an <em>allowed</em> sort)</p> <pre><code> Private Function Comp(ByVal l1 As List(Of Integer), ByVal l2 As List(Of Integer)) As Integer Return l1(0).CompareTo(l2(0)) End Function . . . While m5.Count > 0 m5.Sort(AddressOf Comp) m4.Add(m5(0)(0)) : m5(0).RemoveAt(0) If m5(0).Count = 0 Then m5.RemoveAt(0) End While </code></pre> <p>The entire program -</p> <pre><code> Dim rand As New Random Dim m1 As List(Of Integer) = New List(Of Integer) Dim m2 As List(Of Integer) = New List(Of Integer) Dim m3 As List(Of Integer) = New List(Of Integer) Dim m4 As List(Of Integer) = New List(Of Integer) Dim m5 As List(Of List(Of Integer)) = New List(Of List(Of Integer)) m5.Add(m1) m5.Add(m2) m5.Add(m3) For Each d As List(Of Integer) In m5 For i As Integer = 0 To 100000 d.Add(rand.Next()) Next d.Sort() Next Dim sw As New Stopwatch sw.Start() While m5.Count &gt; 0 Dim idx As Integer = 0 Dim min As Integer = Integer.MaxValue For k As Integer = 0 To m5.Count - 1 If m5(k)(0) &lt; min Then min = m5(k)(0) : idx = k Next m4.Add(min) : m5(idx).RemoveAt(0) If m5(idx).Count = 0 Then m5.RemoveAt(idx) End While sw.Stop() 'Dim sw As New Stopwatch 'sw.Start() 'While m5.Count &gt; 0 ' m5.Sort(AddressOf Comp) ' m4.Add(m5(0)(0)) : m5(0).RemoveAt(0) ' If m5(0).Count = 0 Then m5.RemoveAt(0) 'End While 'sw.Stop() Console.WriteLine(sw.Elapsed) Console.ReadLine() </code></pre>
 

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