elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


  Mostrar Mensajes
Páginas: 1 ... 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ... 55
211  Programación / .NET (C#, VB.NET, ASP) / Re: tomar valores de una cadena numerica y agrupar en variables independientes en: 18 Marzo 2015, 07:53 am
 ;-) ;-) ;-) ;-) ;-) ;-) ;-) y yo solito era muy facil jejejje

Código
  1. Dim Re3 As New Random
  2.        Dim ReAsult2255e As IEnumerable(Of Integer) =
  3.           (splits(0).Concat(splits(2).
  4.           Distinct.
  5.           Select(Function(Value As Integer)
  6.                      Return If(Value < MAX, Value, Rand.Next(1, MAX))
  7.                  End Function)))
  8.  
  9.        Dim seAlecctedValues231 As IEnumerable(Of Integer) = ReAsult2255e
  10.        Dim liste3 As List(Of Integer) = ReAsult2255e.Take(11).ToList
  11.  
  12.        liste3.Sort()
  13.        ListBox6.Items.AddRange(liste3.Cast(Of Object).ToArray)


212  Programación / .NET (C#, VB.NET, ASP) / Re: tomar valores de una cadena numerica y agrupar en variables independientes en: 17 Marzo 2015, 17:50 pm
Eso es una simple partición, que no concuerda en absoluto con las colecciones que estás generando en el primer código que mostraste, donde utilizas el operador Mod para filtrar la secuencia y, claro está, da un resultado muy diferente al que has hecho referencia ahora:

¿Entonces?.



En el primer caso, es decir, partir la colección en colecciones de 4 partes (cosa que ya te mostré cómo hacerlo) y rellenar con "ceros" los elementos restantes de la última "parte", es tan sencillo cómo esto:

Código
  1. Public Class Form1
  2.  
  3.    Private Sub Test() Handles MyBase.Shown
  4.  
  5.        Dim values As IEnumerable(Of Integer) =
  6.            {
  7.                1, 2, 3, 4,
  8.                5, 6, 10, 11,
  9.                14, 15, 54, 57,
  10.                58, 60, 63, 64,
  11.                65, 67
  12.            }
  13.  
  14.        Dim splits As IEnumerable(Of IEnumerable(Of Integer)) =
  15.            SplitIntoParts(collection:=values, amount:=4,
  16.                           fillEmpty:=True)
  17.  
  18.        Me.ListBox1.Items.AddRange(splits(0).Cast(Of Object).ToArray)
  19.        Me.ListBox2.Items.AddRange(splits(1).Cast(Of Object).ToArray)
  20.        Me.ListBox3.Items.AddRange(splits(2).Cast(Of Object).ToArray)
  21.  
  22.    End Sub
  23.  
  24.    ''' <remarks>
  25.    ''' *****************************************************************
  26.    ''' Snippet Title: Split Collection Into Parts
  27.    ''' Code's Author: Elektro
  28.    ''' Date Modified: 16-March-2015
  29.    ''' Usage Example:
  30.    ''' Dim mainCol As IEnumerable(Of Integer) = {1, 2, 3, 4, 5, 6, 7, 8, 9}
  31.    ''' Dim splittedCols As IEnumerable(Of IEnumerable(Of Integer)) = SplitColIntoParts(mainCol, amount:=4, fillEmpty:=True)
  32.    ''' splittedCols.ToList.ForEach(Sub(col As IEnumerable(Of Integer))
  33.    '''                                 Debug.WriteLine(String.Join(", ", col))
  34.    '''                             End Sub)
  35.    ''' *****************************************************************
  36.    ''' </remarks>
  37.    ''' <summary>
  38.    ''' Splits an <see cref="IEnumerable(Of T)"/> into the specified amount of elements.
  39.    ''' </summary>
  40.    ''' <typeparam name="T"></typeparam>
  41.    ''' <param name="collection">The collection to split.</param>
  42.    ''' <param name="amount">The target elements amount.</param>
  43.    ''' <param name="fillEmpty">If set to <c>true</c>, generate empty elements to fill the last secuence's part amount.</param>
  44.    ''' <returns>IEnumerable(Of IEnumerable(Of T)).</returns>
  45.    Public Shared Function SplitIntoParts(Of T)(ByVal collection As IEnumerable(Of T),
  46.                                                ByVal amount As Integer,
  47.                                                ByVal fillEmpty As Boolean) As IEnumerable(Of IEnumerable(Of T))
  48.  
  49.        Dim newCol As IEnumerable(Of List(Of T)) =
  50.            (From index As Integer
  51.            In Enumerable.Range(0, CInt(Math.Ceiling(collection.Count() / amount)))
  52.            Select collection.Skip(index * amount).Take(amount).ToList).ToList
  53.  
  54.        If fillEmpty Then
  55.  
  56.            Do Until newCol.Last.Count = amount
  57.                newCol.Last.Add(Nothing)
  58.            Loop
  59.  
  60.        End If
  61.  
  62.        Return newCol
  63.  
  64.    End Function
  65.  
  66. End Class

EDITO:
Una actualización de la función:

Código
  1.    Public Shared Function SplitIntoParts(Of T)(ByVal collection As IEnumerable(Of T),
  2.                                                ByVal amount As Integer,
  3.                                                ByVal fillEmpty As Boolean) As IEnumerable(Of IEnumerable(Of T))
  4.  
  5.        Return From index As Integer In Enumerable.Range(0, CInt(Math.Ceiling(collection.Count() / amount)))
  6.               Select If(Not fillEmpty,
  7.                         collection.Skip(index * amount).Take(amount),
  8.                         If((collection.Count() - (index * amount)) >= amount,
  9.                            collection.Skip(index * amount).Take(amount),
  10.                            collection.Skip(index * amount).Take(amount).
  11.                                                            Concat(From i As Integer
  12.                                                                   In Enumerable.Range(0, amount - (collection.Count() - (index * amount)))
  13.                                                                   Select DirectCast(Nothing, T))))
  14.  
  15.    End Function

Saludos



Funciona bien ya te habías preocupado no ? era justo lo que queria hacer ya que me deja mucho campo para mi investigacion :)  ahora estoy tratando de mejorarlo con un codigo que me diste te muestro y como te lo paso se que no funciona pero es para la idea de relleñar las variables cuando no hay mas numeros  con los numeros aleatorios dentro del rango


tu funcion

Código
  1. Select(Function(Value As Integer)
  2.                      Return If(Value < MAX, Value, Rand.Next(1, MAX))
  3.                  End Function))


donde creo deberia ir ;(

Código
  1. Dim values As IEnumerable(Of Integer) =
  2.            {
  3.                1, 2, 3, 4,
  4.                5, 6, 10, 11,
  5.                14, 15, 54, 57,
  6.                58, 60, 61, 64,
  7.                65, 67, 71, 75
  8.            }
  9.        Dim Re3 As New Random
  10.        Dim splits As IEnumerable(Of IEnumerable(Of Integer)) =
  11.            SplitIntoParts(collection:=values, amount:=4,
  12.                           fillEmpty:=True)
  13.  
  14.  
  15.        Me.ListBox1.Items.AddRange(splits(0).Cast(Of Object).ToArray)
  16.        Me.ListBox2.Items.AddRange(splits(1).Cast(Of Object).ToArray)
  17.        Me.ListBox3.Items.AddRange(splits(2).Cast(Of Object).ToArray)  


ya he tratado yo jejeje pero a la final el ordenador me dijo Veta a tomar por el c,, Viejo inutil


luis

213  Programación / .NET (C#, VB.NET, ASP) / Re: tomar valores de una cadena numerica y agrupar en variables independientes en: 16 Marzo 2015, 18:46 pm
Diossssssssssss elektro

no te suena algo de esto ?

a=1
b=2
a+b= 3

Jejejjje es Broma  lo probare y te cuento ya que seguro que alguna pega tendre :(

luis
214  Programación / .NET (C#, VB.NET, ASP) / Re: tomar valores de una cadena numerica y agrupar en variables independientes en: 16 Marzo 2015, 16:25 pm
Funciona bien pero a medida que los números del arreglo se hace mas largo estos resultados se vuelven inestables y ya no me sigue la secuencia .

simplemente quiero asignar los primero 4 números del arreglo a Variable  (A)  desde el quinto numero a variable (B)  y asi sucesivamente realmente son posiciones  en fox se hacia con el ( largo ) pero aca a pesar de que tengo la mañana viendo y re viendo no entiendo la sintexis

Arreglo NÚMEROS = (1, 2, 3, 4, 5, 6, 10, 11, 14, 15,  54, 57, 58, 60, 63, 64, 65, 67,)

Esta seria la salida

A=01, 02, 03, 04,
B=05, 06, 10, 11,
C=14, 15,  54, 57
D=58, 60, 63, 64
E= 65, 67, 00  00 <---aca me las arreglo con un pedazo de código tuyo :) para completar


Luis



 

215  Programación / .NET (C#, VB.NET, ASP) / tomar valores de una cadena numerica y agrupar en variables independientes en: 16 Marzo 2015, 13:02 pm
Estaba trabajando este código pero después de escribir la ostia a medida que alargo los números estos se quedan cortos ;(

yo lo que busco es pasar los números de la cadena por orden de menor a mayor en grupos de cuatro en cada variable pero necesito saber los nombres de las variable

ejemplo
variable a=(valor de 1 2 3 4)
variable b=(valor de 5 6 10 11 )

Código
  1. Dim numbers() As Integer = {1, 2, 3, 4, 5, 6, 10, 11, 14, 15,  54, 57, 58, 60, 63, 64, 65, 67, 68, 69, 70, 71, 75, 76, 77, 79, 80}
  2.  
  3.  
  4.    Dim evensQuery = From num In numbers
  5.                         Where num Mod 2 = 0
  6.                         Select num
  7.  
  8.        Dim selectedValues As IEnumerable(Of Integer) = evensQuery.Take(4)
  9.        ListBox1.Items.AddRange(selectedValues.Cast(Of Object).ToArray)
  10.  
  11.        '----------------------------------------2
  12.        Dim ll = From num In numbers
  13.                Where num Mod 2 = 1
  14.                Select num
  15.  
  16.        Dim selected2Values As IEnumerable(Of Integer) = ll.Take(4)
  17.        ListBox2.Items.AddRange(selected2Values.Cast(Of Object).ToArray)
  18.  
  19.        '---------------------------------------------------------3
  20.        Dim ll1 = From num In numbers
  21.                Where num Mod 3 = 0
  22.                Select num
  23.  
  24.        Dim selected222Values As IEnumerable(Of Integer) = ll1.Take(4)
  25.        ListBox3.Items.AddRange(selected222Values.Cast(Of Object).ToArray)


Luis
216  Programación / .NET (C#, VB.NET, ASP) / Re: Problema de ordenamiento en: 13 Marzo 2015, 15:14 pm
Pero lo complicas demasiado, en realidad no tiene más misterio que utilizar la clausula 'Order By' ( o la extensión '.OrderBy' ) cómo te sugerí al principio.

Así:
Código
  1. Dim selecctedValues23aa As IEnumerable(Of Integer) =
  2.    From value As Integer In Result22aa55e
  3.    Take 11
  4.    Order By value Ascending

O así:
Código
  1. Dim selecctedValues23aa As IEnumerable(Of Integer) =
  2.    Result22aa55e.
  3.    Take(11).
  4.    OrderBy(Function(value As Integer)
  5.               Return value
  6.            End Function)

Saludos


Hola
Lo puse a si al principio y me dio error no me acuerdo bien pero algo como " la funcion no devuelve xxxx " no me acuerdo mas y si tuve que modificar algo ya que no me contaba " take"  y lo resolvi de esta forma y ahora va de perlas :)

Código
  1. Dim liste As List(Of Integer) = selecctedValues23aa.Take(11).ToList
  2.        liste.Sort()

Luis







217  Programación / .NET (C#, VB.NET, ASP) / Re: Problema de ordenamiento en: 13 Marzo 2015, 10:13 am
Listo ya funciona tarde unos dias porque estaba en otras cosas tenias razón Elektro fue fácil
ya me estoy metiendo de lleno en linq: hasta me parece facil jejejej

Código
  1. Dim Re As New Random
  2.        Dim Result22aa55e As IEnumerable(Of Integer) =
  3.              (
  4.                  (Result1.Concat(Result2).Concat(Result3).
  5.            Distinct.
  6.            Select(Function(Value As Integer)
  7.                       Return If(Value < MAX, Value, Rand.Next(25, MAX))
  8.                   End Function))
  9.         )
  10.        Dim selecctedValues23aa As IEnumerable(Of Integer) = Result22aa55e.Take(11)
  11.        Dim liste As List(Of Integer) = selecctedValues23aa.ToList
  12.        liste.Sort()
  13.        ListBox3.Items.AddRange(liste.Cast(Of Object).ToArray)  

Hasta la siguiente pregunta :)

Luis


218  Programación / .NET (C#, VB.NET, ASP) / Re: Problema de ordenamiento en: 11 Marzo 2015, 15:06 pm
Si, fíjate bien:
Lo suyo es que entiendas esa "cosa" a la que te estás refiriendo, o al menos su utilización.

Saludos

Jejeje pues npi por ahora y te cuento tendría que hacerlo 20 veces que son las rutinas que tengo en el codigo la que puse arriba, pensaba que con una cosa corta lo podria arreglar jejje

Luis
219  Programación / .NET (C#, VB.NET, ASP) / Re: Problema de ordenamiento en: 11 Marzo 2015, 14:42 pm
Utilizando las extensiones LINQ:
IEnumerable.OrderBy

(Lee el ejemplo en Vb.Net que hay en esa misma página)

Saludos!

Te refieres a esta cosa :)

Código
  1. Structure Pet
  2.        Public Name As String
  3.        Public Age As Integer
  4.    End Structure
  5.  
  6.    Sub OrderByEx1()
  7.        ' Create an array of Pet objects.
  8.        Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
  9.                             New Pet With {.Name = "Boots", .Age = 4}, _
  10.                             New Pet With {.Name = "Whiskers", .Age = 1}}
  11.  
  12.        ' Order the Pet objects by their Age property.
  13.        Dim query As IEnumerable(Of Pet) = _
  14.            pets.OrderBy(Function(pet) pet.Age)
  15.  
  16.        Dim output As New System.Text.StringBuilder
  17.        For Each pt As Pet In query
  18.            output.AppendLine(pt.Name & " - " & pt.Age)
  19.        Next
  20.  
  21.        ' Display the output.
  22.        MsgBox(output.ToString())
  23.    End Sub
  24.  
  25.    ' This code produces the following output:
  26.    '
  27.    ' Whiskers - 1
  28.    ' Boots - 4
  29.    ' Barley - 8

luis



220  Programación / .NET (C#, VB.NET, ASP) / Problema de ordenamiento en: 11 Marzo 2015, 14:11 pm
He probado y reprobado ordenar la salida en este codigo de menor a mayor y siempre me da error en ejecucion probando todas las variables y probando en diseño del listbox en false o true y me sigue fallando.

Código
  1. Dim Re As New Random
  2. Dim Result22aa55e As IEnumerable(Of Integer) =
  3.              (
  4.                  (Result1.Concat(Result2).Concat(Result3).
  5.            Distinct.
  6.            Select(Function(Value As Integer)
  7.                       Return If(Value < MAX, Value, Rand.Next(0, MAX))
  8.                   End Function))
  9.         )
  10.  
  11.        Dim selecctedValues23aa As IEnumerable(Of Integer) = Result22aa55e.Take(11)
  12.  
  13.        '  Array.Sort(selecctedValues23aa)
  14.        ' ListBox3.Sorted = True
  15.  
  16.      Me.ListBox3.Items.AddRange(selecctedValues23aa.Cast(Of Object).ToArray)  

el code funciona bien pero me muestra los numeros desordenados

Luis

Páginas: 1 ... 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ... 55
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines