Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: luis456 en 11 Octubre 2014, 11:54 AM

Título: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 11 Octubre 2014, 11:54 AM
Hola
bien esto de las combinaciones me esta volviendo adicto a lo imposible jejej

tengo 25 números de dos dígitos y como siempre desde el 00 hasta el 99 y quiero hacer o formar grupos de 7 y 8 números donde estén todos los números de entre estos 25 .

ejemplo: 01 09 11 12 14 16 20 24 35 38 40 44 50 58 59 60 68 70 77 80 81 88 90 92 99

alguna idea

Luis

Hoy sabado a programar mm como me gusta jejejej :)
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 11 Octubre 2014, 16:34 PM
Cita de: luis456 en 11 Octubre 2014, 11:54 AM
hacer grupos de 7 y 8 números donde estén todos los números de entre estos 25 .

¿puedes mostrar como sería el resultado.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: XresH en 11 Octubre 2014, 17:49 PM
Con simple logica basica lo logras, forma arrays redimensionandolos cada vez que le asignas un numero(redim preserve), despues verificas (por si no queres repetidos) y obtenes valores aleatorios de la manera tradicional.

Podes agregarlos a un control cualquiera que maneje listas para luego regir su busqueda y comparacion a traves del index.

Hay varias formas.


Cita de: Eleкtro en 11 Octubre 2014, 16:34 PM
¿puedes mostrar como sería el resultado.

Saludos

Aca esta un supuesto resultado:
Cita de: luis456
"ejemplo: 01 09 11 12 14 16 20 24 35 38 40 44 50 58 59 60 68 70 77 80 81 88 90 92 99"

Saludos.

Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 11 Octubre 2014, 19:44 PM
Cita de: Eleкtro en 11 Octubre 2014, 16:34 PM
¿puedes mostrar como sería el resultado.

Saludos

muestra de numeros a combinar
01 09 11 12 14 16 20   24  35 38 40  44  50  58  59 60 68 70 77 80 81 88 90 92 99


01 09 11 12 14 16 20 24
01 09 11 12 14 16 20 35
01 09 11 12 14 16 20 38
01 09 11 12 14 16 20 40
01 09 11 12 14 16 20 44
01 09 11 12 14 16 20 50
01 09 11 12 14 16 20 58
01 09 11 12 14 16 20 59
01 09 11 12 14 16 20 60
01 09 11 12 14 16 20 68
01 09 11 12 14 16 20 70 hasta el 99

y después sigue con el segundo numero

09 11 12 14 16 20 24 35
09 11 12 14 16 20 24 38

y haci hasta acabar con todos


Luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 12 Octubre 2014, 07:25 AM
Código (vbnet) [Seleccionar]
Public Class Form1

   ReadOnly constantValues As New List(Of Integer) From
       {
           1I, 9I, 11, 12, 14, 16, 20, 24, 35, 38,
           40, 44, 50, 58, 59, 60, 68, 70, 77, 80,
           81, 88, 90, 92, 99
       }

   Private Shadows Sub Load() Handles MyBase.Load

       Dim combinations As New List(Of Integer())

       Dim length As Integer = 7
       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)).ToArray)
               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)

   End Sub

End Class



Output:
Citar1, 9, 11, 12, 14, 16, 20, 24
1, 9, 11, 12, 14, 16, 20, 35
1, 9, 11, 12, 14, 16, 20, 38
1, 9, 11, 12, 14, 16, 20, 40
1, 9, 11, 12, 14, 16, 20, 44
1, 9, 11, 12, 14, 16, 20, 50
1, 9, 11, 12, 14, 16, 20, 58
1, 9, 11, 12, 14, 16, 20, 59
1, 9, 11, 12, 14, 16, 20, 60
1, 9, 11, 12, 14, 16, 20, 68
1, 9, 11, 12, 14, 16, 20, 70
1, 9, 11, 12, 14, 16, 20, 77
1, 9, 11, 12, 14, 16, 20, 80
1, 9, 11, 12, 14, 16, 20, 81
1, 9, 11, 12, 14, 16, 20, 88
1, 9, 11, 12, 14, 16, 20, 90
1, 9, 11, 12, 14, 16, 20, 92
1, 9, 11, 12, 14, 16, 20, 99

9, 11, 12, 14, 16, 20, 24, 35
9, 11, 12, 14, 16, 20, 24, 38
9, 11, 12, 14, 16, 20, 24, 40
9, 11, 12, 14, 16, 20, 24, 44
9, 11, 12, 14, 16, 20, 24, 50
9, 11, 12, 14, 16, 20, 24, 58
9, 11, 12, 14, 16, 20, 24, 59
9, 11, 12, 14, 16, 20, 24, 60
9, 11, 12, 14, 16, 20, 24, 68
9, 11, 12, 14, 16, 20, 24, 70
9, 11, 12, 14, 16, 20, 24, 77
9, 11, 12, 14, 16, 20, 24, 80
9, 11, 12, 14, 16, 20, 24, 81
9, 11, 12, 14, 16, 20, 24, 88
9, 11, 12, 14, 16, 20, 24, 90
9, 11, 12, 14, 16, 20, 24, 92
9, 11, 12, 14, 16, 20, 24, 99

11, 12, 14, 16, 20, 24, 35, 38
11, 12, 14, 16, 20, 24, 35, 40
11, 12, 14, 16, 20, 24, 35, 44
11, 12, 14, 16, 20, 24, 35, 50
11, 12, 14, 16, 20, 24, 35, 58
11, 12, 14, 16, 20, 24, 35, 59
11, 12, 14, 16, 20, 24, 35, 60
11, 12, 14, 16, 20, 24, 35, 68
11, 12, 14, 16, 20, 24, 35, 70
11, 12, 14, 16, 20, 24, 35, 77
11, 12, 14, 16, 20, 24, 35, 80
11, 12, 14, 16, 20, 24, 35, 81
11, 12, 14, 16, 20, 24, 35, 88
11, 12, 14, 16, 20, 24, 35, 90
11, 12, 14, 16, 20, 24, 35, 92
11, 12, 14, 16, 20, 24, 35, 99

12, 14, 16, 20, 24, 35, 38, 40
12, 14, 16, 20, 24, 35, 38, 44
12, 14, 16, 20, 24, 35, 38, 50
12, 14, 16, 20, 24, 35, 38, 58
12, 14, 16, 20, 24, 35, 38, 59
12, 14, 16, 20, 24, 35, 38, 60
12, 14, 16, 20, 24, 35, 38, 68
12, 14, 16, 20, 24, 35, 38, 70
12, 14, 16, 20, 24, 35, 38, 77
12, 14, 16, 20, 24, 35, 38, 80
12, 14, 16, 20, 24, 35, 38, 81
12, 14, 16, 20, 24, 35, 38, 88
12, 14, 16, 20, 24, 35, 38, 90
12, 14, 16, 20, 24, 35, 38, 92
12, 14, 16, 20, 24, 35, 38, 99

14, 16, 20, 24, 35, 38, 40, 44
14, 16, 20, 24, 35, 38, 40, 50
14, 16, 20, 24, 35, 38, 40, 58
14, 16, 20, 24, 35, 38, 40, 59
14, 16, 20, 24, 35, 38, 40, 60
14, 16, 20, 24, 35, 38, 40, 68
14, 16, 20, 24, 35, 38, 40, 70
14, 16, 20, 24, 35, 38, 40, 77
14, 16, 20, 24, 35, 38, 40, 80
14, 16, 20, 24, 35, 38, 40, 81
14, 16, 20, 24, 35, 38, 40, 88
14, 16, 20, 24, 35, 38, 40, 90
14, 16, 20, 24, 35, 38, 40, 92
14, 16, 20, 24, 35, 38, 40, 99

16, 20, 24, 35, 38, 40, 44, 50
16, 20, 24, 35, 38, 40, 44, 58
16, 20, 24, 35, 38, 40, 44, 59
16, 20, 24, 35, 38, 40, 44, 60
16, 20, 24, 35, 38, 40, 44, 68
16, 20, 24, 35, 38, 40, 44, 70
16, 20, 24, 35, 38, 40, 44, 77
16, 20, 24, 35, 38, 40, 44, 80
16, 20, 24, 35, 38, 40, 44, 81
16, 20, 24, 35, 38, 40, 44, 88
16, 20, 24, 35, 38, 40, 44, 90
16, 20, 24, 35, 38, 40, 44, 92
16, 20, 24, 35, 38, 40, 44, 99

20, 24, 35, 38, 40, 44, 50, 58
20, 24, 35, 38, 40, 44, 50, 59
20, 24, 35, 38, 40, 44, 50, 60
20, 24, 35, 38, 40, 44, 50, 68
20, 24, 35, 38, 40, 44, 50, 70
20, 24, 35, 38, 40, 44, 50, 77
20, 24, 35, 38, 40, 44, 50, 80
20, 24, 35, 38, 40, 44, 50, 81
20, 24, 35, 38, 40, 44, 50, 88
20, 24, 35, 38, 40, 44, 50, 90
20, 24, 35, 38, 40, 44, 50, 92
20, 24, 35, 38, 40, 44, 50, 99

24, 35, 38, 40, 44, 50, 58, 59
24, 35, 38, 40, 44, 50, 58, 60
24, 35, 38, 40, 44, 50, 58, 68
24, 35, 38, 40, 44, 50, 58, 70
24, 35, 38, 40, 44, 50, 58, 77
24, 35, 38, 40, 44, 50, 58, 80
24, 35, 38, 40, 44, 50, 58, 81
24, 35, 38, 40, 44, 50, 58, 88
24, 35, 38, 40, 44, 50, 58, 90
24, 35, 38, 40, 44, 50, 58, 92
24, 35, 38, 40, 44, 50, 58, 99

35, 38, 40, 44, 50, 58, 59, 60
35, 38, 40, 44, 50, 58, 59, 68
35, 38, 40, 44, 50, 58, 59, 70
35, 38, 40, 44, 50, 58, 59, 77
35, 38, 40, 44, 50, 58, 59, 80
35, 38, 40, 44, 50, 58, 59, 81
35, 38, 40, 44, 50, 58, 59, 88
35, 38, 40, 44, 50, 58, 59, 90
35, 38, 40, 44, 50, 58, 59, 92
35, 38, 40, 44, 50, 58, 59, 99

38, 40, 44, 50, 58, 59, 60, 68
38, 40, 44, 50, 58, 59, 60, 70
38, 40, 44, 50, 58, 59, 60, 77
38, 40, 44, 50, 58, 59, 60, 80
38, 40, 44, 50, 58, 59, 60, 81
38, 40, 44, 50, 58, 59, 60, 88
38, 40, 44, 50, 58, 59, 60, 90
38, 40, 44, 50, 58, 59, 60, 92
38, 40, 44, 50, 58, 59, 60, 99

40, 44, 50, 58, 59, 60, 68, 70
40, 44, 50, 58, 59, 60, 68, 77
40, 44, 50, 58, 59, 60, 68, 80
40, 44, 50, 58, 59, 60, 68, 81
40, 44, 50, 58, 59, 60, 68, 88
40, 44, 50, 58, 59, 60, 68, 90
40, 44, 50, 58, 59, 60, 68, 92
40, 44, 50, 58, 59, 60, 68, 99

44, 50, 58, 59, 60, 68, 70, 77
44, 50, 58, 59, 60, 68, 70, 80
44, 50, 58, 59, 60, 68, 70, 81
44, 50, 58, 59, 60, 68, 70, 88
44, 50, 58, 59, 60, 68, 70, 90
44, 50, 58, 59, 60, 68, 70, 92
44, 50, 58, 59, 60, 68, 70, 99

50, 58, 59, 60, 68, 70, 77, 80
50, 58, 59, 60, 68, 70, 77, 81
50, 58, 59, 60, 68, 70, 77, 88
50, 58, 59, 60, 68, 70, 77, 90
50, 58, 59, 60, 68, 70, 77, 92
50, 58, 59, 60, 68, 70, 77, 99

58, 59, 60, 68, 70, 77, 80, 81
58, 59, 60, 68, 70, 77, 80, 88
58, 59, 60, 68, 70, 77, 80, 90
58, 59, 60, 68, 70, 77, 80, 92
58, 59, 60, 68, 70, 77, 80, 99

59, 60, 68, 70, 77, 80, 81, 88
59, 60, 68, 70, 77, 80, 81, 90
59, 60, 68, 70, 77, 80, 81, 92
59, 60, 68, 70, 77, 80, 81, 99

60, 68, 70, 77, 80, 81, 88, 90
60, 68, 70, 77, 80, 81, 88, 92
60, 68, 70, 77, 80, 81, 88, 99

68, 70, 77, 80, 81, 88, 90, 92
68, 70, 77, 80, 81, 88, 90, 99

70, 77, 80, 81, 88, 90, 92, 99

Saludos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 12 Octubre 2014, 10:09 AM
Gracias elektro

si funciona como queria esta genial :) ahora estoy tratando de mostrarlo en un listbox pero no me sale, ademas de que tengo que cambiar o introducir  los valores de  " constantValues" los números a mano a través de texbox pero eso creo resolverlo jejej


Código (vbnet) [Seleccionar]
Public Class Form1

    ReadOnly constantValues As New List(Of Integer) From
        {
            1I, 9I, 11, 12, 14, 16, 20, 24, 35, 38,
            40, 44, 50, 58, 59, 60, 68, 70, 77, 80,
            81, 88, 90, 92, 99
        }

    Private Shadows Sub Load() Handles MyBase.Load

        Dim combinations As New List(Of Integer())

        Dim length As Integer = 7
        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)).ToArray)
                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)

        ListBox1.Items.AddRange(????????.Cast(Of Object).ToArray) <-----no y no

    End Sub

End Class



saludos
Luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 12 Octubre 2014, 16:28 PM
AAAA GGGG no puedo pasarlo a un listbox ? he probado con todas las variables y nada

luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 12 Octubre 2014, 20:08 PM
Cita de: luis456 en 12 Octubre 2014, 16:28 PMAAAA GGGG no puedo pasarlo a un listbox ? he probado con todas las variables y nada

Hace poco tuviste el mismo problema, como añadir una lista a un listbox... y te mostré la solución, de hecho se supone que ese código lo utilizaste para tu aplicación de los números así que no entiendo como puedes tener el mismo problema por segunda vez,
yo no estoy dispuesto a hacerle el trabajo a alguien para que ni me escuche ni aprenda, puedes buscar entre tus publicaciones en el foro y/o en tus códigos del pasado y hallarás la solución al problema.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 13 Octubre 2014, 04:44 AM
Tu creees que no he estado en ello :) el ejemplo que me dices es este ,pero de verdad que no logro hacerlo andar


Código (vbnet) [Seleccionar]
combinations.ForEach(Sub(comb As List(Of Integer))

                           ' Convierto la Lista a 'String', le añado los ceros, y añado el string formateado al Listbox.
                           ListBox1.Items.Add(String.Join(", ",
                                                          From value As String In comb
                                                          Select If(value.Length = 1I,
                                                                    value.Insert(0I, "0"c),
                                                                    value)))
                           ListBox1.Sorted = True



luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 13 Octubre 2014, 13:57 PM
Otra ves al ataque :) bien tratando con los ejemplos que me diste la otra ves y no doy pie con bola he cambiado todas las variables y nada no me aclaro cual es la que debo mostrar en el listbox


Código (vbnet) [Seleccionar]
Dim combinations As New List(Of Integer()) <---creo esta es la que tiene las combis
Dim length As Integer = 7 <----------esta es la determina las cantidad
Dim skipStart As Integer = 0 <----------NPI



Estos son las  formas que me enseñaste

Combos.ForEach(Sub(comb As List(Of Integer))
                           ListBox1.Items.Add(String.Join(", ", comb))
                       End Sub)

---------------------------------------------------------------------------


ListBox1.Items.AddRange(
            (From comb As List(Of Integer) In Combos
             Select String.Join(", ", comb)).ToArray
         )



-------------------------------------------------------------------------------------

Combos.ForEach(Sub(comb As List(Of Integer))

                           ' Convierto la Lista a 'String', le añado los ceros, y añado el string formateado al Listbox.
                           ListBox1.Items.Add(String.Join(", ",
                                                          From value As String In comb
                                                          Select If(value.Length = 1I,
                                                                    value.Insert(0I, "0"c),
                                                                    value)))

                       End Sub)
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 13 Octubre 2014, 20:30 PM
En el primer código que te mostré, reemplaza esto:
Código (vbnet) [Seleccionar]
Dim combinations As New List(Of Integer())
combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToArray)


por esto:
Código (vbnet) [Seleccionar]
Dim combinations As New List(Of List(Of Integer))
combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList)



Ahora, ya puedes hacer algo parecido a esto:

Código (vbnet) [Seleccionar]
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)


Cita de: luis456 en 13 Octubre 2014, 13:57 PM
Código (vbnet) [Seleccionar]
Dim skipStart As Integer = 0 <----------NPI
Es el contador que determina la cantidad de dígitos que se deben saltar/omitir (skip) al inicio de cada combinación.

Ejemplo:

3, 9, 11... hasta 99

skipStart=1 (saltar el primer dígito, el "3")

9, 11... hasta 99

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 14 Octubre 2014, 07:39 AM
Valla que facilito no   ? :)   ¡ solo me faltaban dos meses para hacerlo jejejje

funciona  ;-)

gracias elektro

Luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 14 Octubre 2014, 13:08 PM
Estoy uniendo esta funcion a otro programa y no me da error en programación pero cuando lo ejecuto me da este error.

" El  desplazamiento y la longitud están fuera de los límites para esta matriz o el recuento es superior al número de elementos desde el índice al final de la colección de origen. "


Código (vbnet) [Seleccionar]
  Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length)

luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 15 Octubre 2014, 03:40 AM
Cita de: luis456 en 14 Octubre 2014, 13:08 PM
" El  desplazamiento y la longitud están fuera de los límites para esta matriz o el recuento es superior al número de elementos desde el índice al final de la colección de origen. "

Te está indicando que no se puede seleccionar el rango que has especificado, porque el primer o el segundo parámetro (skipstart, length) son erroneos, esto podría ocurrir si skipstart (el desplazamiento) es mayor que la variable length ( ej: Lista.GetRange(5, 0) ) o si la variable length (la longitud) supera a la cantidad de elementos, o si la variable skipStart es un número negativo, etc...

Comprueba el valor de las variables Skipstart y Length antes de usar el método GetRange, y también comprueba la cantidad de elementos ( ej: Lista.Count )

Saludos!
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 15 Octubre 2014, 06:30 AM
OK miro


luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 15 Octubre 2014, 10:33 AM
Cita de: luis456 en 15 Octubre 2014, 06:30 AM
OK miro

Intuyo que el problema debe ser la variable skipStart ya que no la reseteo a 0 en el ejemplo que te mostré... pero sin ver como es el código que estás utilizando, ni idea.

Al terminar la iteración de las combinaciones, debes resetear las variables que hayas utilizado a 0, en caso de que posteriormente las vayas a utilizar para algo...

Ejemplo:
Código (vbnet,6) [Seleccionar]
Dim skipStart As Integer

Do Until skipStart...
Loop

skipStart = 0
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 15 Octubre 2014, 13:48 PM
Cita de: Eleкtro en 15 Octubre 2014, 10:33 AM
Intuyo que el problema debe ser la variable skipStart ya que no la reseteo a 0 en el ejemplo que te mostré... pero sin ver como es el código que estás utilizando, ni idea.

Al terminar la iteración de las combinaciones, debes resetear las variables que hayas utilizado a 0, en caso de que posteriormente las vayas a utilizar para algo...

Ejemplo:
Código (vbnet,6) [Seleccionar]
Dim skipStart As Integer

Do Until skipStart...
Loop

skipStart = 0




De prisa y corriendo te respondo ya que el código que estoy usando es el de siempre jeje

a la noche te lo pongo mas concreto

luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 15 Octubre 2014, 13:49 PM
aca hago el cambio

Código (vbnet) [Seleccionar]
Dim Resultss As IEnumerable(Of Integer) =
            (
                From Value As Integer
                In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
                Where Value <= MAX
            )

        ListBox1.Items.AddRange(Resultss.Cast(Of Object).ToArray)
        ListBox1.Sorted = True

        'funcion unir combis

        Dim constantValues As IEnumerable(Of Integer) =
            (
                From Value As Integer
                In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
                Where Value <= MAX
            )



luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 15 Octubre 2014, 20:15 PM
Hola bueno llegando y pongo el codigo

Código (vbnet) [Seleccionar]
Imports System.IO

Public Class Form1
    Dim maximum As Short = 99
    Dim Número As Double
    Private TextBoxes As TextBox() = {Nothing}
    Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32(), Result4 As Int32(), Result5 As Int32(), Result6 As Int32()
    Private _textBox As Object
    ReadOnly MAX As Integer = 99
    Dim Rand As New Random
    Dim Rand2 As New Random
    Dim Result22 As Integer
    Dim Counter, Counter2 As Integer
    Dim myLabelArray(6) As Label
    Dim x As Integer = 0
    Private Property ListBox1Count As Integer
    ReadOnly Randomizer As New Random
    Dim Combo As List(Of Integer) = Nothing
    Dim Combos As New List(Of List(Of Integer))
    Dim FixedValues As Integer() = Nothing
    ReadOnly RandomValues As Integer() =
        Enumerable.Range(0, 99).ToArray


    Public Sub solonumeros(ByRef e As System.Windows.Forms.KeyPressEventArgs)
        ' evitar letras
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If

    End Sub

    Private Property Calcular As Object

    Private Property TextBox(ByVal TextBoxCount As Short) As Object
        Get
            Return _textBox
        End Get
        Set(ByVal value As Object)
            _textBox = value
        End Set
    End Property

    ReadOnly Property Num1 As Int32
        Get
            Return CInt(TextBox1.Text)
        End Get
    End Property
    ReadOnly Property Num2 As Int32
        Get
            Return CInt(TextBox2.Text)
        End Get
    End Property
    ReadOnly Property Num3 As Int32
        Get
            Return CInt(TextBox3.Text)
        End Get
    End Property
    ReadOnly Property Num4 As Int32
        Get
            Return CInt(TextBox4.Text)
        End Get
    End Property

    ReadOnly Property Num5 As Int32
        Get
            Return CInt(TextBox5.Text)
        End Get
    End Property
    '---------------------------------
    ReadOnly Property Num6 As Int32
        Get
            Return CInt(TextBox6.Text)
        End Get
    End Property



    Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        '--------------------------------------------------

        Result1 = {Num1 + 2, Num1 + 3, Num1 \ 2, Num1 \ 3, Num1 * 3} _
       .Distinct().ToArray
        Array.Sort(Result1)

        Result2 = {Num2 + 2, Num2 + 3, Num2 \ 2, Num2 \ 3, Num2 * 3} _
                  .Distinct().ToArray
        Array.Sort(Result2)

        Result3 = {Num3 + 2, Num3 + 3, Num3 - 2, Num3 - 3, Num3 * 3, Num3 \ 2, Num3 \ 2} _
                  .Distinct().ToArray
        Array.Sort(Result3)

        Result4 = {Num4 + 2, Num4 + 3, Num4 - 2, Num4 - 3, Num4 * 2, Num4 * 3, Num4 \ 2, Num4 \ 3} _
                  .Distinct().ToArray
        Array.Sort(Result4)

        Result5 = {Num5 + 2, Num5 + 3, Num5 - 3, Num5 - 10, Num5 * 3, Num5 \ 2, Num5 \ 3, Num5 \ 4} _
                  .Distinct().ToArray
        Array.Sort(Result5)

        Result6 = {Num6 + 2, Num6 + 3, Num6 - 2, Num6 - 3, Num6 - 7, Num6 \ 2, Num6 \ 3} _
                  .Distinct().ToArray

        Array.Sort(Result6)




        ' Elimino duplicados al mismo tiempo que selecciono los números inferiores a MAX.
        Dim Resultss As IEnumerable(Of Integer) =
            (
                From Value As Integer
                In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
                Where Value <= MAX
            )

        ListBox1.Items.AddRange(Resultss.Cast(Of Object).ToArray)
        ListBox1.Sorted = True

        'funcion unir combis

        Dim constantValues As IEnumerable(Of Integer) =
            (
                From Value As Integer
                In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
                Where Value <= MAX
            )

       

        ' Application.Exit()

    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub
    Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        solonumeros(e)
        If e.KeyChar = ChrW(Keys.Enter) Then
            e.Handled = True
            SendKeys.Send("{TAB}")

        End If

    End Sub


    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For Each obj As Control In Me.Controls
            If (TypeOf obj Is TextBox) Then
                obj.Text = ""
            End If
            If (TypeOf obj Is GroupBox) Then
                For Each caja As Control In obj.Controls
                    If (TypeOf caja Is TextBox) Then
                        caja.Text = ""
                    End If
                Next
            End If
            ListBox1.Items.Clear()


        Next
       

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim rutaFichero As String
        Dim i As Integer

        rutaFichero = Path.Combine(Application.StartupPath, "Multiples.txt")
        Dim fichero As New IO.StreamWriter(rutaFichero)
        For i = 0 To ListBox1.Items.Count - 1
            fichero.WriteLine(ListBox1.Items(i))
        Next
        fichero.Close()
    End Sub

    Dim combinations As Integer
    Dim seta As Integer

   


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim constantValues As New List(Of Integer)
        Dim combinations As New List(Of List(Of Integer))
        Dim length As Integer = 5
        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
            skipStart = 0
        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
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 15 Octubre 2014, 20:28 PM
Cita de: luis456 en 15 Octubre 2014, 20:15 PMHola bueno llegando y pongo el codigo

Especifica el número de linea donde da error, y el error en si mismo. no se, muestra un ejemplo, o algo...

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 15 Octubre 2014, 20:59 PM
Bien es el mismo error que puse antes

Código (vbnet) [Seleccionar]
Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length)

El desplazamiento y la longitud están fuera de los límites para esta matriz o el recuento es superior al número de elementos desde el índice al final de la colección de origen.


Excepción del tipo 'System.ArgumentException' en mscorlib.dll
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 15 Octubre 2014, 21:55 PM
En serio, Luis... ...

Piensa un poco en lo que estás haciendo, si quieres te lo digo yo... pero es que a estas alturas... como mínimo deberías poder darte cuenta tú de este fallo tan obvio y básico.

Te muestro la parte del código en conflicto:

Código (vbnet, 1, 10, 14) [Seleccionar]
       Dim constantValues As IEnumerable(Of Integer) =
          (
              From Value As Integer
              In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
              Where Value <= MAX
          )

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
   
      Dim constantValues As New List(Of Integer)

      Do Until ...

          Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length)

          Do Until ...

          Loop

      Loop

  End Sub


¿ Lo entiendes ?


Aparte del sin sentido que estás intentando hacer, luego está esto otro, lo cual en conjunto con el otro fallo me ha tocado un poco las narices ver esto... para ser sinceros, no me explico esta contradicción que añadiste (¿sumas el valor, y seguídamente le reasignas un cero?, ¿entonces para que sumas, si siempre será cero?):

Citar
Código (vbnet,7,8) [Seleccionar]
      Do Until ...

          Do Until ...

          Loop

          skipStart += 1
          skipStart = 0

      Loop

La instrucción 'Skipstart = 0' debe ir fuera del búcle como comenté, esto significa fuera de la anidación (fuera del bloque de los 2 búcles, debajo del todo), no fuera del primer búcle.
De todas formas directamente elimina esa modificación del 0, ya que no estás rehutilizando la variable fuera del búcle así que no tienes porque reasignarle el valor 0.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 18 Octubre 2014, 16:30 PM
Cita de: Eleкtro en 15 Octubre 2014, 21:55 PM
En serio, Luis... ...

Piensa un poco en lo que estás haciendo, si quieres te lo digo yo... pero es que a estas alturas... como mínimo deberías poder darte cuenta tú de este fallo tan obvio y básico.

Te muestro la parte del código en conflicto:

Código (vbnet, 1, 10, 14) [Seleccionar]
       Dim constantValues As IEnumerable(Of Integer) =
          (
              From Value As Integer
              In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
              Where Value <= MAX
          )

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
   
      Dim constantValues As New List(Of Integer)

      Do Until ...

          Dim values As List(Of Integer) = constantValues.GetRange(skipStart, length)

          Do Until ...

          Loop

      Loop

  End Sub


¿ Lo entiendes ?


Aparte del sin sentido que estás intentando hacer, luego está esto otro, lo cual en conjunto con el otro fallo me ha tocado un poco las narices ver esto... para ser sinceros, no me explico esta contradicción que añadiste (¿sumas el valor, y seguídamente le reasignas un cero?, ¿entonces para que sumas, si siempre será cero?):

La instrucción 'Skipstart = 0' debe ir fuera del búcle como comenté, esto significa fuera de la anidación (fuera del bloque de los 2 búcles, debajo del todo), no fuera del primer búcle.
De todas formas directamente elimina esa modificación del 0, ya que no estás rehutilizando la variable fuera del búcle así que no tienes porque reasignarle el valor 0.

Saludos


Sábado a programar ( bueno creo yo jejej)

si elektro fallos muy tontos pero que para mi son insondables porque antes de poner el código  probé cambiando a integer y casi me explota el PC jejeje por eso lo deje como en principio lo puse,ya que al poner integer la variable me pone que


'Count' no es un miembro de 'Integer'.   
'GetRange' no es un miembro de 'Integer'


Lo que trato es de usar los mismos datos que estan en :

Código (vbnet) [Seleccionar]
Dim Resultss As IEnumerable(Of Integer) =
           (
               From Value As Integer
               In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6)).Distinct
               Where Value <= MAX
           )

       ListBox1.Items.AddRange(Resultss.Cast(Of Object).ToArray)
       ListBox1.Sorted = True



en :

constantValues


luis




Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 18 Octubre 2014, 18:46 PM
Cita de: luis456 en 18 Octubre 2014, 16:30 PM
'Count' no es un miembro de 'Integer'.   
'GetRange' no es un miembro de 'Integer'

Será porque Integer es un DataType, no una Lista / Colección Genérica, por lo tanto no contiene esas extensiones de método...

Sin ánimo de ofender, pero ya es hora de aprender lo básico por tu cuenta para no tener que pedirlo todo hecho siempre, ¿no crees?.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 18 Octubre 2014, 20:01 PM
BUAAAA

No me pegues que no es mi culpa por ser tan bruto :) estoy en ello


luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 22 Octubre 2014, 07:51 AM
Yaaaaaaa   ;D ;D ;D ;D ;D ;D ;D ;D


Código (vbnet) [Seleccionar]
constantValues.AddRange(Resultss.ToArray())


me tenia confundido lo de "list"
luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros (subRangos)
Publicado por: luis456 en 22 Octubre 2014, 15:41 PM
Formar combinaciones por Subrangos


Bueno ya resuelto un problema :) ahora se me ocurre formar estas combiaciones dentro de subrangos

ya tenemos la variable " constantValues" con x numeros como siempre ocurre con mis ideas locas :)

siempre trabajo con el rango de 00 al 99 estas se subdividirian en :

subrangos

00 al 09
10 al 19
20 al 29
30 al 39
40 al 49
50 al 59
60 al 69
70 al 79
80 al 89
90 al 99

La pregunta como haria que las combinaciones no tomen mas de dos numeros de un mismo subrango ?

ejemplo

02 08 10 15 21 28 50 58... ETC


Codigo funcionando :)


Código (vbnet) [Seleccionar]
constantValues.AddRange(Resultss.ToArray()) <-----variable con numeros con los que formamos las combinaciones


        Dim combinations As New List(Of List(Of Integer))
        Dim length As Integer = 7
        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)

        ListBox2.Sorted = True




Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 22 Octubre 2014, 16:44 PM
Código (vbnet) [Seleccionar]
Namespace LuisLibrary

Friend NotInheritable Class Group

   Protected Friend Property First As Integer = 0I
   Protected Friend Property Second As Integer = 0I

End Class

End Namespace


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 LuisLibrary.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


...O bien:
Código (vbnet) [Seleccionar]
' Type anónimo
Dim groupedValues =
   From i As Integer In values
   Group By i.ToString("00").First
   Into items = Group Select New With {
      Key .First = items(0),
      Key .Second = items(1)
   }


...O también:
Código (vbnet) [Seleccionar]
Dim groupedValues As List(Of List(Of Integer)) =
   (From i As Integer In values
    Group By i.ToString("00").First Into items = Group
    Select New List(Of Integer) From {items(0), items(1)}
    ).ToList


Saludos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 22 Octubre 2014, 18:13 PM
Cita de: Eleкtro en 22 Octubre 2014, 16:44 PM
Código (vbnet) [Seleccionar]
Namespace LuisLibrary

Friend NotInheritable Class Group

   Protected Friend Property First As Integer = 0I
   Protected Friend Property Second As Integer = 0I

End Class

End Namespace


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 LuisLibrary.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}, {1}",
                                     g.First.ToString("00"),
                                     g.Second.ToString("00"))

   MessageBox.Show(str)

Next g


...O bien:
Código (vbnet) [Seleccionar]
' Type anónimo
Dim groupedValues =
   From i As Integer In values
   Group By i.ToString("00").First
   Into items = Group Select New With {
      Key .First = items(0),
      Key .Second = items(1)
   }


...O también:
Código (vbnet) [Seleccionar]
Dim groupedValues As List(Of List(Of Integer)) =
   (From i As Integer In values
    Group By i.ToString("00").First Into items = Group
    Select New List(Of Integer) From {items(0), items(1)}
    ).ToList


Saludos.


AAAAA Me tendre que ahorcar para entender esto ( es broma me pongo en ello)


Luis

Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 22 Octubre 2014, 18:53 PM
Te explicaré la query de LINQ del primer ejemplo:

1) Creo grupos de los números según su primer dígito (habiendo añadido temporalmente un "0" a los números del 1 al 9), es decir, grupo de números que empiezan por 0, o por 1, 2, 3, etc.
   Cada grupo contiene todos los números de la colección que empiecen por ese primer dígito de la regla. por ejemplo el grupo del "0" contendrá { 02, 08, 09 } (el cero es imaginario)

2) Asigno los grupos a la variable/propiedad 'items'.

3) Instancio un objeto 'LuisLibrary.Group' por cada grupo, al que le asigno el primer número del grupo (items(0)) a la propiedad 'First', y el segundo número del grupo (items(1)) a la propiedad 'Second'.

4) Devuelvo una Lista de los objetos 'LuisLibrary.Group'.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 22 Octubre 2014, 19:35 PM
Cita de: Eleкtro en 22 Octubre 2014, 18:53 PM
Te explicaré la query de LINQ del primer ejemplo:

1) Creo grupos de los números según su primer dígito (habiendo añadido temporalmente un "0" a los números del 1 al 9), es decir, grupo de números que empiezan por 0, o por 1, 2, 3, etc.
   Cada grupo contiene todos los números de la colección que empiecen por ese primer dígito de la regla. por ejemplo el grupo del "0" contendrá { 02, 08, 09 } (el cero es imaginario)

2) Asigno los grupos a la variable/propiedad 'items'.

3) Instancio un objeto 'LuisLibrary.Group' por cada grupo, al que le asigno el primer número del grupo (items(0)) a la propiedad 'First', y el segundo número del grupo (items(1)) a la propiedad 'Second'.

4) Devuelvo una Lista de los objetos 'LuisLibrary.Group'.

Saludos



O sea que los tres van juntos en el mismo codigo ?

luis

Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 22 Octubre 2014, 19:59 PM
¿te refieres a los 3 ejemplos que dí?... no, son 3 ejemplos distintos para conseguir practicamente lo mismo, siendo el primer ejemplo el más elaborado.

saludos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 23 Octubre 2014, 11:23 AM
hola

estoy probando con este codigo y cuando lo ejecuto solo me muestra en el listbox

"coleccion"  ? hay que hacer mas cosas, la variabe que contiene los numeros

es " resultss" 


Código (vbnet) [Seleccionar]
  Dim groupedValues As List(Of List(Of Integer)) =
    (From i As Integer In Resultss
     Group By i.ToString("00").First Into items = Group
     Select New List(Of Integer) From {items(0), items(1)}
     ).ToList

        ListBox3.Items.AddRange(groupedValues.Cast(Of Object).ToArray)
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 23 Octubre 2014, 17:34 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?.

Código (vbnet) [Seleccionar]
   ' 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


Código (vbnet) [Seleccionar]
       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
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 23 Octubre 2014, 19:08 PM
Cita de: Eleкtro en 23 Octubre 2014, 17:34 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?.

Código (vbnet) [Seleccionar]
   ' 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


Código (vbnet) [Seleccionar]
       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




Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 23 Octubre 2014, 19:57 PM
Cita de: luis456 en 23 Octubre 2014, 19:08 PM

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

A ver Luis, en el código tu tienes una lista que contiene más listas ( List(Of List(Of Integer)) ), y estás intentando mostrar/añadir la lista que contiene más listas en el Listbox, por eso te muestra "colección" y no te muestra los números, porque le estás pasando una serie de colecciones genéricas... no le estás pasando diréctamente los números, debes pasarle un String o una colección de Strings al método Add o AddRange del ListBox, ahi es donde fallas siempre, jolín :P.

La función del código de arriba ( JoinEnumerables ) simplemente lo que hace es UNIR cada List(Of Integer) de la Lista principal, en una única lista, y con el método String.Join() UNO los items de la lista para devolver un String...

Slaudos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 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 "

Código (vbnet) [Seleccionar]
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
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 24 Octubre 2014, 14:42 PM
Cita de: luis456 en 24 Octubre 2014, 14:25 PM" El tipo 'LuisLibrary.Group' no está definido "

Es demasiado obvio, no se puede encontrar ningún miembro que se llame 'Group' en el código, al no estar creado o no tener la visibilidad suficiente para poder acceder a él.

En el código que muestras falta la parte más importante, el NameSpace o Class 'LuisLibrary' y el miembro de Class 'Group', si no los creas entonces no existen...
no necesitas crearlos desde cero, en el primer ejemplo que te mostré ya lo hice yo, añádelo a tu código.

Saludos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 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'.




Código (vbnet) [Seleccionar]
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


Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 24 Octubre 2014, 15:18 PM
Cita de: luis456 en 24 Octubre 2014, 14:59 PMUn 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'.

Se debe a que el nombre 'Group' es ambiguo, 'Group' existe tanto en el NameSpace 'RegularExpressions' como en el Namespace 'LuisLibrary' así que se produce un conflicto en la manera en que lo intentas usar,
tu has importado directamente en el código el namespace 'RegularExpressions' así que al escribir 'Group' se toma como referencia lo que has importado... 'RegularExpressions.Group'.

¿Solución?, especifica el nombre del Namespace ( 'LuisLibrary.Group' ) en lugar de escribir solo 'Group', o modifica el nombre de la Class 'Group' por otro más apropiado como podría ser 'Int32Group' y luego importa el namespace 'LuisLibrary'.

Reemplaza:
Citar
Código (vbnet) [Seleccionar]
Dim groupedValues As List(Of Group) =...

Por:
Código (vbnet) [Seleccionar]
Dim groupedValues As List(Of LuisLibrary.Group) =...

EDITO:
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.

2) En el código que muestras no necesitas usar expresiones regulares, al menos en el código que has mostrado, si no estás seguro de porque importaste 'RegularExpressions' entonces elimina ese Import.

Saludos.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 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.
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 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

Código (vbnet) [Seleccionar]
  .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,
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 24 Octubre 2014, 20:30 PM
Cita de: luis456 en 24 Octubre 2014, 19:45 PMlo 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 "


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) :
Lista
   · {2, 9, 10, 15}



¿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!
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 28 Octubre 2014, 10:25 AM
Cita de: Eleкtro en 24 Octubre 2014, 20:30 PM

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) :
Lista
   · {2, 9, 10, 15}



¿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

Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 28 Octubre 2014, 18:15 PM
Cita de: luis456 en 28 Octubre 2014, 10:25 AMHola asta ahora no he podido ver nada ( catarrazooo)  me podrias enseñar algun ejemplo con mayores detalles :)

Lo siento Luis pero considero que ya he invertido bastante tiempo en mostrarte decenas de ejemplos, no se que más mostrarte ya, no soy un prefesor, y siento que cada ejemplo que escribo no sirve para nada al final por que o bien no lo usas o no hallas el modo.

Ponte a desarrollar tu aplicación/código y si tienes alguna duda específica, pregunta, con detalles.

Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 28 Octubre 2014, 18:29 PM
Buaaaaaaaaaa


luis
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 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 ,

Código (vbnet) [Seleccionar]
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


Código (vbnet) [Seleccionar]
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




Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 31 Octubre 2014, 15:32 PM
Cita de: luis456 en 31 Octubre 2014, 14:56 PM

Código (vbnet,3) [Seleccionar]
       Do Until skipStart = (constantValues.Count - length)
           ...
           combinations.Add(values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList)
           ...
       Loop


List(Of T).Sort Method - MSDN (//http://)

Nota: 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
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 31 Octubre 2014, 15:58 PM
Cita de: Eleкtro en 31 Octubre 2014, 15:32 PM

List(Of T).Sort Method - MSDN (//http://)

Nota: 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





Código (vbnet) [Seleccionar]

          ' 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
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 31 Octubre 2014, 16:57 PM
No veo que hayas hecho nada de lo que te dije en ese código.

Aparte, ¿me vas a decir en que intrucción te da el error?.

En el código que puse arriba, resalté solo 1 linea y es en la que te tienes que fijar (es la misma que está en tu código, tienes que sacarla de ahi meterla en una variable, ordenarla y luego procedes como ya expliqué), por si acaso te digo que no vayas a cambiar de posición estas lineas:
Citar
Código (vbnet) [Seleccionar]
         ' Do Until count = (constantValues.Count - length - skipStart)
          Do Until skipStart = (constantValues.Count - length)

En resumen, deja el código como lo tenias... solo tienes que asignar la lista a una variable y usar el método List.Sort... la lista la tienes en la linea que resalté en el código de mi ultimo comentario...

saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: Eleкtro en 31 Octubre 2014, 17:08 PM
Me gustaría que aprendieses a hacerlo por ti mismo porque es algo muy básico, pero bueno, aquí tienes:

Código (vbnet) [Seleccionar]

do until...
 ...
 dim list as list(of integer) = values.Concat(constantValues.Skip(skipStart + length + count).Take(1)).ToList
 list.sort()

 combinations.Add(list)
 ...
loop


Saludos
Título: Re: formar combinaciones de 7 y 8 numeros con 25 numeros
Publicado por: luis456 en 31 Octubre 2014, 17:48 PM
Gracias Elektro , no creas que ya no resuelvo algunas cosas por mi mismo :) y eso es gracias a ti en este lenguaje, pero aprendo muy despacio jejej y ademas cambiar de  programación a esta edad me confunde mucho


Luis