Jump to content

Sorting List of Names into 2 or more lists without duplication

Recommended Posts

Hi all, just looking to get some assistance with a tricky one:

I have a list of 100 names with duplicates.

I need to sort that list into evenly split sub-lists (2 or more, up to 5) whilst making sure the same name is never repeated in the same sub-list.


Master list:

Steve Koprowski
Treasa Hartranft
Trisha Mattie
Trisha Mattie
Teddy Wheat
Preston Jetter
Adrianne Manders
Preston Jetter
Shawnna Ullrich
Nicolette Ruffner
Aurelio Kells
Steve Koprowski
Marylyn Gilder
Nicolette Ruffner


Sorted into two sub-lists (no duplicates in any sub-list):

Steve Koprowski Nicolette Ruffner
Treasa Hartranft Steve Koprowski
Nicolette Ruffner Trisha Mattie
Trisha Mattie Preston Jetter
Adrianne Manders Shawnna Ullrich
Preston Jetter Aurelio Kells
Marylyn Gilder Teddy Wheat

Sorted into three sub-lists (no duplicates in any sub-list):

Steve Koprowski Nicolette Ruffner Preston Jetter
Treasa Hartranft Steve Koprowski Shawnna Ullrich
Nicolette Ruffner Trisha Mattie Aurelio Kells
Trisha Mattie Marylyn Gilder Teddy Wheat
Adrianne Manders Preston Jetter  
Link to post
Share on other sites

If you put the names into an array, you can use the _ArrayUnique function to eliminate duplicates.

After that, you could use _ArrayExtract to create new arrays (lists) the sizes you want (Array Size / 2, Array Size /3, etc.)

Link to post
Share on other sites

I want the duplicates to remain, they just cannot be repeated in the split lists. I.e. each person is only allocated to unique sub-lists. Anyway I think I figured out how to do it. The trick is to allocate all dupes randomly (but without repeating in the same sub-list) first. Then allocate the rest of the non-dupes to fill the rest of the sub lists.



Link to post
Share on other sites

The following method divides the master list into 3 sublists. If you have 4 identical names in the master list and you divide it to 3 sublists, you cannot avoid duplicate in one of the sublists.

#include <Array.au3>

$sMaster = "Steve Koprowski"
$sMaster &= @CR & "Treasa Hartranft"
$sMaster &= @CR & "Trisha Mattie"
$sMaster &= @CR & "Trisha Mattie"
$sMaster &= @CR & "Teddy Wheat"
$sMaster &= @CR & "Preston Jetter"
$sMaster &= @CR & "Adrianne Manders"
$sMaster &= @CR & "Preston Jetter"
$sMaster &= @CR & "Shawnna Ullrich"
$sMaster &= @CR & "Nicolette Ruffner"
$sMaster &= @CR & "Aurelio Kells"
$sMaster &= @CR & "Steve Koprowski"
$sMaster &= @CR & "Marylyn Gilder"
$sMaster &= @CR & "Nicolette Ruffner"

$aMaster = StringSplit($sMaster, @CR)

_ArraySort($aMaster, 0, 1)

Dim $aList1[1], $aList2[1], $aList3[1]

For $i = 1 To $aMaster[0]
    If Mod($i, 3) = 1 Then
        _ArrayAdd($aList1, $aMaster[$i])
        $aList1[0] += 1
    ElseIf Mod($i, 3) = 2 Then
        _ArrayAdd($aList2, $aMaster[$i])
        $aList2[0] += 1
        _ArrayAdd($aList3, $aMaster[$i])
        $aList3[0] += 1



Edited by CYCho
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...