Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: oscarj24 en 28 Abril 2011, 19:13 PM

Título: [Ayuda] permutaciones .net
Publicado por: oscarj24 en 28 Abril 2011, 19:13 PM
Hola a todos  ;D,

estaba realizando una aplicacion en donde necesito todas las combinaciones posibles de numeros del 0 al 9 en grupos de 6.

Por lo que creo que deberia tener algo asi:

000000
111111
222222
333333
444444
555555
666666
777777
888888
999999

y luego mezclarlos para obtener numeros de 6 digitos pero que toleren
numeros que van del 0 al 9, alguna idea?

PD. encontre ejemplos de permutaciones pero no me fueron utiles ya
que no tengo idea de como agruparlos en 6, saludos!

>:D
Título: Re: [Ayuda] permutaciones .net
Publicado por: neoncyber en 29 Abril 2011, 01:45 AM
Podrias utilizar estructuras for anidadas con IFs dependiendo de las restricciones del problema, tal vez no sea una forma rapida de hacer las cosas pero podria funcionar.

Saludos
Título: Re: [Ayuda] permutaciones .net
Publicado por: seba123neo en 29 Abril 2011, 06:15 AM
aca tenes un ejemplo que es facil adaptarlo.

aclaro que si vos queres permutaciones de 6 y realizados con 10 numeros (del 0 al 9), eso daria un total de 10 mil millones de valores (10 elevado a la 10) si lo haces con valores que pueden repetirse.

pero si los haces con valores sin repeticion la cifra seria factorial de 10! o sea 3628800 de valores.

este ejemplo lo hace de la longitud que quieras pero sin repeticion.

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

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

        Dim inputLine As String = "123"

        Dim rec As New Recursion()
        rec.InputSet = rec.MakeCharArray(inputLine)
        rec.CalcPermutation(0)

        Debug.WriteLine("# of Permutations: " + rec.PermutationCount.ToString)
    End Sub

    Class Recursion
        Private elementLevel As Integer = -1
        Private numberOfElements As Integer
        Private permutationValue As Integer() = New Integer(-1) {}

        Private m_inputSet As Char()
        Public Property InputSet() As Char()
            Get
                Return m_inputSet
            End Get
            Set(ByVal value As Char())
                m_inputSet = value
            End Set
        End Property

        Private m_permutationCount As Integer = 0
        Public Property PermutationCount() As Integer
            Get
                Return m_permutationCount
            End Get
            Set(ByVal value As Integer)
                m_permutationCount = value
            End Set
        End Property

        Public Function MakeCharArray(ByVal InputString As String) As Char()
            Dim charString As Char() = InputString.ToCharArray()
            Array.Resize(permutationValue, charString.Length)
            numberOfElements = charString.Length
            Return charString
        End Function

        Public Sub CalcPermutation(ByVal k As Integer)
            elementLevel += 1
            permutationValue.SetValue(elementLevel, k)

            If elementLevel = numberOfElements Then
                OutputPermutation(permutationValue)
            Else
                For i As Integer = 0 To numberOfElements - 1
                    If permutationValue(i) = 0 Then
                        CalcPermutation(i)
                    End If
                Next
            End If
            elementLevel -= 1
            permutationValue.SetValue(0, k)
        End Sub

        Private Sub OutputPermutation(ByVal value As Integer())
            For Each i As Integer In value
                Debug.Write(m_inputSet.GetValue(i - 1))
            Next
            Debug.WriteLine("")
            PermutationCount += 1
        End Sub
    End Class
End Class


saludos.

Título: Re: [Ayuda] permutaciones .net
Publicado por: oscarj24 en 29 Abril 2011, 22:54 PM
Gracias por la ayuda, pero encontre otro ejemplo que tenia implementadas muchisimas funciones, cheka esta web: http://www.codeproject.com/KB/recipes/Combinatorics.aspx

a mi me sirvio, pero vale la intencion.