|
272
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 31 Octubre 2014, 15:58 pm
|
⇲List(Of T).Sort Method - MSDNNota: Es un método, no una función, por lo tanto debes asignar la lista a una variable, la ordenas utilizando el método indicado, y ya puedes agregar la lista ordenada a la colección de listas. Saludos Probando me da este error no se si te entendi bien pero te muestro el codigo Excepción del tipo 'System.OutOfMemoryException' en System.Core.dll ' Do Until count = (constantValues.Count - length - skipStart) Do Until skipStart = (constantValues.Count - length) combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList) ' Debug.WriteLine(String.Join(", ", values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToArray)) count += 1 Loop ' count = (constantValues.Count - length) skipStart += 1 Loop ' skipStart = (constantValues.Count - length) combinations.ForEach(Sub(combination As List(Of Integer)) ListBox2.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString))) End Sub)
Luis
|
|
|
273
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 31 Octubre 2014, 14:56 pm
|
Otro rollo jeje este codigo me entrega los numeros ordenados de menor a mayor funciona bien,pero depues de modificarlo me entrega los combinaciones desordenadas,he probado con ordenar la variable y el listbox pero no se que mas , codigo original Public Class Form1 Dim combinations As Integer Dim seta As Integer ReadOnly constantValues As New List(Of Integer) From { 2, 3, 5I, 6I, 7I, 8I, 9I, 11, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 29, 30, 31, 33, 44, 48 } Private Shadows Sub Load() Handles MyBase.Load Dim combinations As New List(Of List(Of Integer)) Dim length As Integer = 9 Dim skipStart As Integer = 0 Do Until skipStart = (constantValues.Count - length) Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length) Dim count As Integer = 0 Do Until count = (constantValues.Count - length - skipStart) combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList) Debug. WriteLine(String. Join(", ", values. Concat(constantValues. Skip(skipStart + length + count ). Take(1)). ToArray)) count += 1 Loop ' count = (constantValues.Count - length) skipStart += 1 Loop ' skipStart = (constantValues.Count - length) combinations.ForEach(Sub(combination As List(Of Integer)) ListBox1.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString))) End Sub) End Sub
ahora como he modificado la variable " constantValues " por constantValues.AddRange(Resultss.ToArray()) para usar los numeros de " resultss " y estos numeros cambian no son fijos codigo modificado Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim combinations As New List(Of List(Of Integer)) Dim length As Integer = 9 Dim skipStart As Integer = 0 Do Until skipStart = (constantValues.Count - length) Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length) Dim count As Integer = 0 Do Until count = (constantValues.Count - length - skipStart) combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList) ' Debug.WriteLine(String.Join(", ", values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToArray)) count += 1 Loop ' count = (constantValues.Count - length) skipStart += 1 Loop ' skipStart = (constantValues.Count - length) combinations.ForEach(Sub(combination As List(Of Integer)) ListBox2.Items.Add(String.Join(", ", From value As Integer In combination Select If(value.ToString.Length = 1I, value.ToString.Insert(0I, "0"c), value.ToString))) End Sub) y me entrega las combinaciones desordenadas de esta forma 03, 05, 12, 13, 30, 08, 27, 28, 14, 26 03, 05, 12, 13, 30, 08, 27, 28, 14, 31 03, 05, 12, 13, 30, 08, 27, 28, 14, 32 03, 05, 12, 13, 30, 08, 27, 28, 14, 11 03, 05, 12, 13, 30, 08, 27, 28, 14, 17 03, 05, 12, 13, 30, 08, 27, 28, 14, 33 03, 05, 12, 13, 30, 08, 27, 28, 14, 37 03, 05, 12, 13, 30, 08, 27, 28, 14, 38
Luis
|
|
|
275
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 28 Octubre 2014, 10:25 am
|
Tu tienes esto: Lista · Sub-Lista · {2, 9} · Sub-Lista · {10, 15} Y lo que quieres conseguir es esto (aparentemente, ya que no está muy claro lo que has dicho) : ¿Qué tienes que hacer?, unir las sub-listas en una sola lista. ¿Cómo hacerlo?, puedes hacerlo con el método que te mostré, JoinEnumerables, el cual desarrollé para que realizase esa tarea en específico. Saludos! Hola asta ahora no he podido ver nada ( catarrazooo) me podrias enseñar algun ejemplo con mayores detalles luis
|
|
|
276
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 24 Octubre 2014, 19:45 pm
|
jejej de nuevo al ataque ahora funciona y ya he probado a modificar algunas cosillas como por ejemplo el orden en .First = items(0), .Second = items(2)
lo que no entiendo es como hacer que en ves de dos,me muestre combinaciones de mas de dos números por ejemplo " 02 09 10 15 " , ahora solo me saca en la ventana " 02 09 " y en otra " 10 15 " y en otra "21 28 " etc. en una sola ventana,
|
|
|
277
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 24 Octubre 2014, 19:20 pm
|
1) Por cierto, no quiero ver marranadas, ya me estás separando 'Luislibrary' de la Class 'Form1', crea un archivo de Class individual en el projecto y ahí copias y pegas el namespace 'LuisLibrary' y vas añadiendo tus distintas "utilidades" para usarlas en el futuro. estoy en pruebas ya me haré mi archivo de rutinas Saludos.
|
|
|
278
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 24 Octubre 2014, 14:59 pm
|
Me voy a suicidar Un valor de tipo 'System.Collections.Generic.List(Of WindowsApplication1.LuisLibrary.Group)' no se puede convertir en 'System.Collections.Generic.List(Of System.Text.RegularExpressions.Group)'. Un valor de tipo 'System.Text.RegularExpressions.Group' no se puede convertir en 'WindowsApplication1.LuisLibrary.Group'. Imports System.Text.RegularExpressions Namespace LuisLibrary Friend NotInheritable Class Group Protected Friend Property First As Integer = 0I Protected Friend Property Second As Integer = 0I End Class End Namespace Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim values As New List(Of Integer) From { 2, 8, 9, 10, 11, 15, 21, 22, 28, 50, 55, 58 } Dim groupedValues As List(Of Group) = (From i As Integer In values Group By i.ToString("00").First Into items = Group Select New LuisLibrary.Group With { .First = items(0), .Second = items(1) }).ToList For Each g As LuisLibrary.Group In groupedValues Dim str As String = String.Format("{0:00}, {1:00}", g.First, g.Second) MessageBox.Show(str) Next g End Sub End Class
|
|
|
279
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 24 Octubre 2014, 14:25 pm
|
me explicas este error ? cada dia hay algo jejeje ,estoy probando este codigo y me dice: " El tipo 'LuisLibrary.Group' no está definido " Imports System.Text.RegularExpressions Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim values As New List(Of Integer) From { 2, 8, 9, 10, 11, 15, 21, 22, 28, 50, 55, 58 } Dim groupedValues As List(Of Group) = (From i As Integer In values Group By i.ToString("00").First Into items = Group Select New LuisLibrary.Group With { .First = items(0), .Second = items(1) }).ToList For Each g As LuisLibrary.Group In groupedValues Dim str As String = String.Format("{0:00}, {1:00}", g.First, g.Second) MessageBox.Show(str) Next g End Sub End Class
|
|
|
280
|
Programación / .NET (C#, VB.NET, ASP) / Re: formar combinaciones de 7 y 8 numeros con 25 numeros
|
en: 23 Octubre 2014, 19:08 pm
|
Luis, estoy muy harto de verte cometer el mismo fallo en el mismo punto crítico después de habertelo explicado y resuelto decenas de veces ya :-/ ¿Por qué no practicas un poco todo lo referente a colecciones genéricas y LINQ?. ' Join Enumerables ' ( By Elektro ) ' ' Examples : ' ' Dim listA As New List(Of String) From {"a", "b"} ' Dim listB As New List(Of String) From {"c", "d"} ' Dim newlist As List(Of String) = JoinEnumerables(Of String)({listA, listB}).ToList ' Result: {"a", "b", "c", "d"} ''' <summary> ''' Joins the specified <see cref="IEnumerable"/> colecctions into a single <see cref="IEnumerable"/>. ''' </summary> ''' <typeparam name="T"></typeparam> ''' <param name="enumerables">The <see cref="IEnumerable"/> collections to join.</param> ''' <returns>IEnumerable(Of T).</returns> Friend Function JoinEnumerables(Of T)(ByVal enumerables As IEnumerable(Of T)()) As IEnumerable(Of T) Return enumerables.SelectMany(Function(enumerable As IEnumerable(Of T)) enumerable) End Function
Dim joinedGroups As List(Of Integer) = JoinEnumerables(Of Integer)( (From group As List(Of Integer) In groupedValues Select group).ToArray ).ToList ListBox1.Items.Add(String.Join(", ", joinedGroups))
Espero que eso te ayude a entender un poco más, aunque se que por el momento no vas a entender el parámetro de Type (T), pero bueno xD. Saludos Como ya sabes voy a pasos, si me dices que hace cada cosa lo entendería mejor ya que tengo que ir a preguntar por todo jejej y lo que hago es enredarme mas luis
|
|
|
|
|
|
|