Foro de elhacker.net

Programación => .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
  1. Public Class Form1
  2.  
  3.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5.        Dim inputLine As String = "123"
  6.  
  7.        Dim rec As New Recursion()
  8.        rec.InputSet = rec.MakeCharArray(inputLine)
  9.        rec.CalcPermutation(0)
  10.  
  11.        Debug.WriteLine("# of Permutations: " + rec.PermutationCount.ToString)
  12.    End Sub
  13.  
  14.    Class Recursion
  15.        Private elementLevel As Integer = -1
  16.        Private numberOfElements As Integer
  17.        Private permutationValue As Integer() = New Integer(-1) {}
  18.  
  19.        Private m_inputSet As Char()
  20.        Public Property InputSet() As Char()
  21.            Get
  22.                Return m_inputSet
  23.            End Get
  24.            Set(ByVal value As Char())
  25.                m_inputSet = value
  26.            End Set
  27.        End Property
  28.  
  29.        Private m_permutationCount As Integer = 0
  30.        Public Property PermutationCount() As Integer
  31.            Get
  32.                Return m_permutationCount
  33.            End Get
  34.            Set(ByVal value As Integer)
  35.                m_permutationCount = value
  36.            End Set
  37.        End Property
  38.  
  39.        Public Function MakeCharArray(ByVal InputString As String) As Char()
  40.            Dim charString As Char() = InputString.ToCharArray()
  41.            Array.Resize(permutationValue, charString.Length)
  42.            numberOfElements = charString.Length
  43.            Return charString
  44.        End Function
  45.  
  46.        Public Sub CalcPermutation(ByVal k As Integer)
  47.            elementLevel += 1
  48.            permutationValue.SetValue(elementLevel, k)
  49.  
  50.            If elementLevel = numberOfElements Then
  51.                OutputPermutation(permutationValue)
  52.            Else
  53.                For i As Integer = 0 To numberOfElements - 1
  54.                    If permutationValue(i) = 0 Then
  55.                        CalcPermutation(i)
  56.                    End If
  57.                Next
  58.            End If
  59.            elementLevel -= 1
  60.            permutationValue.SetValue(0, k)
  61.        End Sub
  62.  
  63.        Private Sub OutputPermutation(ByVal value As Integer())
  64.            For Each i As Integer In value
  65.                Debug.Write(m_inputSet.GetValue(i - 1))
  66.            Next
  67.            Debug.WriteLine("")
  68.            PermutationCount += 1
  69.        End Sub
  70.    End Class
  71. End Class
  72.  

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.