Results 1 to 7 of 7

Thread: How to solve as quick as possible

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    How to solve as quick as possible

    I have struggeled with this for a long but here it is:
    there are only 16 teams and 4 groups of 4
    i had 4 listboxes and tried it with a random
    but there may only 4 teams in a group( so in a listbox)
    how can i do this?

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: How to solve as quick as possible

    You will need to be much clearer about what you are asking. What you posted doesn't really give anyone enough information to try and help. Explain what you are trying to acheive in small steps. Perhap post what you have done so far.
    Please remember next time...elections matter!

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: How to solve as quick as possible

    Are you trying to randomly assign 16 teams to 4 groups of 4 teams and then display the groups in 4 listboxes?
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: How to solve as quick as possible

    exactly funnydexter,

    16 teams, there are 4 groups, and in each group there must be 4 teams. I want those in 4 listboxes, compeletly random

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: How to solve as quick as possible

    Depending on what teams are, take a look at this example:
    Code:
    Imports System
    Imports System.Linq
    Public Module Module1
    	'Declare a new random
    	Private r As New Random()
    
    	Public Sub Main()
    		'Create a group of numbers from 1 - 16
    		Dim exclusive_numbers() As Integer = Enumerable.Range(1, 16).OrderBy(Function(n) r.Next(1, 17)).ToArray
    		Dim group1(3), group2(3), group3(3), group4(3) As Integer
    		
    		'Set the first four exclusive numbers to group1, second four exclusive numbers to group2, etc...
    		For x As Integer = 1 To 4
    			group1(x - 1) = exclusive_numbers(x - 1)
    			group2(x - 1) = exclusive_numbers(x + 4 - 1)
    			group3(x - 1) = exclusive_numbers(x + 8 - 1)
    			group4(x - 1) = exclusive_numbers(x + 12 - 1)
    		Next
    	
    		Console.WriteLine("Group1")
    		For Each item As Integer In group1
    			Console.WriteLine("   Team: " & item.ToString())
    		Next
    	
    		Console.WriteLine("Group2")
    		For Each item As Integer In group2
    			Console.WriteLine("   Team: " & item.ToString())
    		Next
    
    		Console.WriteLine("Group3")
    		For Each item As Integer In group3
    			Console.WriteLine("   Team: " & item.ToString())
    		Next
    
    		Console.WriteLine("Group4")
    		For Each item As Integer In group4
    			Console.WriteLine("   Team: " & item.ToString())
    		Next
    
    	End Sub
    
    End Module
    Last edited by dday9; Mar 12th, 2015 at 02:19 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: How to solve as quick as possible

    here's an alternative:

    Code:
    Public Class Form1
    
        Dim r As New Random
        Dim teams() As String = Enumerable.Range(1, 16).OrderBy(Function(x) r.NextDouble).Select(Function(x) "Team " & x.ToString).ToArray
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Items.AddRange(teams.Take(4).ToArray)
            ListBox2.Items.AddRange(teams.Skip(4).Take(4).ToArray)
            ListBox3.Items.AddRange(teams.Skip(8).Take(4).ToArray)
            ListBox4.Items.AddRange(teams.Skip(12).Take(4).ToArray)
        End Sub
    
    End Class

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: How to solve as quick as possible

    Thank you, i'll try it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width