formar combinaciones de 7 y 8 numeros con 25 numeros

Iniciado por luis456, 11 Octubre 2014, 11:54 AM

0 Miembros y 1 Visitante están viendo este tema.

Eleкtro

#10
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








luis456

Valla que facilito no   ? :)   ¡ solo me faltaban dos meses para hacerlo jejejje

funciona  ;-)

gracias elektro

Luis
Que tu sabiduria no sea motivo de Humillacion para los demas

luis456

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
Que tu sabiduria no sea motivo de Humillacion para los demas

Eleкtro

#13
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!








luis456

Que tu sabiduria no sea motivo de Humillacion para los demas

Eleкtro

#15
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








luis456

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
Que tu sabiduria no sea motivo de Humillacion para los demas

luis456

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
Que tu sabiduria no sea motivo de Humillacion para los demas

luis456

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
Que tu sabiduria no sea motivo de Humillacion para los demas

Eleкtro

#19
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