Otra duda con combinatorias de numeros :(
luis456:
Hola chicos aca os traigo otra de mis chapuzas de combinatorias :
introduzco ejemplo estos números " 1, 2 , 3 , 5 , 7 " necesito formar con estos números el 12 , 13 , 15 , 17 ,21 ,23 , 25, 27 etc etc menos 51 osea todo lo que tenga el 5 adelante o el 7,
lo de la limitación de los números tengo la idea con esta rutina :
Código
Return If(Value < MAX, Value, Rand.Next(0, MAX))
Adonde tengo la pega es con este :)
Código
'--combis para reparar nesecita un boton y un trxbox TRABAJANDO EN ELLO AHORA
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
' Dim intCol As IEnumerable(Of Integer) = {2, 3, 4, 7}
Dim intCol As IEnumerable(Of Integer) = (Result1) '<---aca convierto las variables que trae los numeros pueden ser del 1 al 9
' lo que nesecito es formar combinaciones pares y que no pase del numero 50
Dim pairsCol As IEnumerable(Of String) =
From value1 As Integer In intCol
From value2 As Integer In intCol
Select String.Join(Environment.NewLine, (
From value3 As Integer In intCol
Where (value1 <> value2) AndAlso
(value1 <> value3) AndAlso
(value2 <> value3)
Select String.Format("{0:00}, {1:00}, {2:00}",
value1, value2, value3)))
For Each pairs As String In pairsCol
For Each line As String In pairs.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray
' MsgBox(pairs.Count)
' MsgBox(line.Count)
Me.ListBox3.Items.Add(line)
Next line
Next pairs
End Sub
si alguno sabria como modificarlo me ayudaria mucho
saludos
Luis
Optimus_73:
Buenas, he hecho un pequeño programa en javascript. Supongo que no sera muy complicado codificarlo en .Net. Los bucles anidados son un poco marroneros pero es lo mejor que se me ha ocurrido con un tipado fuerte. Espero que te sirva ;)
Código:
let input = [1, 2, 3, 5, 7];
let output = new Array();
for(let i = 0; i < input.length; i++){
for(let j = 0; j < input.length; j++){
if(input[i] != input[j] && input[i] < 5){
output.push(input[i] * 10 + input[j]);
}
}
}
console.log(output); //[12, 13, 15, 17, 21, 23, 25, 27, 31, 32, 35, 37]
luis456:
Cita de: Optimus_73 en 9 Marzo 2020, 21:38 pm
Buenas, he hecho un pequeño programa en javascript. Supongo que no sera muy complicado codificarlo en .Net. Los bucles anidados son un poco marroneros pero es lo mejor que se me ha ocurrido con un tipado fuerte. Espero que te sirva ;)
Código:
let input = [1, 2, 3, 5, 7];
let output = new Array();
for(let i = 0; i < input.length; i++){
for(let j = 0; j < input.length; j++){
if(input[i] != input[j] && input[i] < 5){
output.push(input[i] * 10 + input[j]);
}
}
}
console.log(output); //[12, 13, 15, 17, 21, 23, 25, 27, 31, 32, 35, 37]
Gracias todo aporte vale ,lo convertiré y te cuento ;)
saludos
Luis
luis456:
Hola bueno como os comente en un post anterior trabajo fuera de casa y este portatil no da para mucho el codigo en java echo por Optimus_73 lo he tenido que pasar primero a c
Código
using System.Collections.Generic;
let input = new List() {1, 2, 3, 5, 7};
let output = new Array();
for (let i = 0; i < input.length; i++)
{
for (let j = 0; j < input.length; j++)
{
if (input[i] != input[j] && input[i] < 5)
{
output.push(input[i] * 10 + input[j]);
}
}
}
console.log(output); //[12, 13, 15, 17, 21, 23, 25, 27, 31, 32, 35, 37]
y despues a Visual net
pero con este portatil vamos muy mal ya que es LENTOOOO y no me deja trabajar bien
ya veremos cuando llegue el fin de semana :silbar: :silbar: :silbar:
Código
Imports System.Collections.Generic
Dim input As let = new List()
Dim 2, 3, 5, 7 As 1,
Dim output As let = new Array()
For i As let = 0 To input.length-1
For j As let = 0 To input.length-1
If input(i) <> input(j) AndAlso input(i) < 5 Then
output.push(input[i] * 10 + input[j])
End if
Next
Next
console.log(output) '[12, 13, 15, 17, 21, 23, 25, 27, 31, 32, 35, 37]
saludos
Luis
**Aincrad**:
Cita de: luis456 en 11 Marzo 2020, 06:48 am
Código
Imports System.Collections.Generic
Dim input As let = new List()
Dim 2, 3, 5, 7 As 1,
Dim output As let = new Array()
For i As let = 0 To input.length-1
For j As let = 0 To input.length-1
If input(i) <> input(j) AndAlso input(i) < 5 Then
output.push(input[i] * 10 + input[j])
End if
Next
Next
console.log(output) '[12, 13, 15, 17, 21, 23, 25, 27, 31, 32, 35, 37]
Let? (output As let ) , bueno , correccion :
Código
Dim input As Integer() = {1, 2, 3, 5, 7}
Dim output As New List(Of Integer)
For i As Integer = 0 To input.Length - 1
For j As Integer = 0 To input.Length - 1
If input(i) <> input(j) AndAlso input(i) < 5 Then
Dim result As Integer = (input(i) * 10 + input(j))
output.Add(result)
End If
Next j
Next i
Navegación
[#] Página Siguiente