Peggy Posted November 4, 2015 Posted November 4, 2015 (edited) [Rule]1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack2. Every person eating a fruit, and each times one person can eat the same fruit (or random fruit)3. Last eaten fruit can not eat4. so be scheduled5. If the previous round fruits are finished, the remaining number can pick one randomly 6. If I have more than 100 the number of Name(people), how can I to code it?Picture:1. The first time Mary eat Apple, Sam can eat Apple(or random),and Jack chose random first to eat.2. The second They are chose random first to eat.3. Third They are chose random first to eat.4. Fourth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too.5. Fifth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too. Currently only think of using arrary and for next loop to write it, but I do not know to write Detailing, want to please help me, thank you very much !!!! Thank you!! Edited November 4, 2015 by Peggy
Moderators Melba23 Posted November 5, 2015 Moderators Posted November 5, 2015 Peggy,A couple of your requirements are unclear:- Every person eating a fruit, and each times one person can eat the same fruit (or random fruit): Does this mean that in each round several pairs can eat the same fruit or that only one pair may do so?- If the previous round fruits are finished, the remaining number can pick one randomly: So those with a smaller range from which to choose just repeat choices from that range until the end of the largest range? What if there are no unique (or double) choices left in the round after all the previous selections? What do they choose then?As to doing this for 100+ people, I think that you might begin to struggle. What exactly are you doing? If we get a better idea of the purpose of all this we might be able to offer a better solution.M23 Peggy 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Peggy Posted November 9, 2015 Author Posted November 9, 2015 (edited) Hi Melba23,Thanks for your reply!!!I feel very moved!! - Every person eating a fruit, and each times one person can eat the same fruit (or random fruit):each round one person can eat the same fruit,but next time one person can't eat previous eaten fruit(Unless the previous have all finished).- If the previous round fruits are finished, the remaining number can pick one randomly:This function can be deleted, if the previous finish, behind may be left blank.(If that can to do, can be randomly selected)As shown below[Rule]1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack , Jason, Susan1. Round 1: each one Random choice.(Each one can choose the same fruit) 2. Round 2: each one Random choice.(each one can't eat Previous fruit Unless all eaten up)3. Round 3,4,5,6: And so on, each one Random choice.(each one can't eat Previous fruit Unless all eaten up,This feature is not essential) Thanks for your great help!! p.s.If name more than the amount of fruits (Ex: name x7, fruit max: 5), than someone will be blank at previous round, we hope to end with five round.we hope result is .. Thanks for your great help!! Edited November 9, 2015 by Peggy
Moderators Melba23 Posted November 9, 2015 Moderators Posted November 9, 2015 Peggy,I am afraid I am still not altogether clear about your requirements, but this seems to match your final state:3. Round 3,4,5,6: And so on, each one Random choice.(each one can't eat Previous fruit Unless all eaten up expandcollapse popup#include <Array.au3> ; Array of groups (in priority order) and possible choices Global $aData[][] = [["Mary", 5, "Apple", "Banana", "Tomato", "Watermelon", "Strawberry"], _ ["Sam", 2, "Apple", "Tomato"], _ ["Jack", 3, "Banana", "Watermelon", "Strawberry"], _ ["Jason", 2, "Banana", "Watermelon"], _ ["Susan", 6, "Watermelon", "Strawberry", "Apple", "Tomato", "Banana", "Orange"]] ; Determine the size of the display Global $iRows = 0 For $i = 0 To UBound($aData) - 1 $iRows += $aData[$i][1] Next Global $iCols = UBound($aData, $UBOUND_COLUMNS) ; Create array to hold display Global $aDisplay[$iRows][$iCols] ; Create array to hold group data Global $aGroupInfo[UBound($aData)][4] = [[0]] Local $iRow = 0 For $i = 0 To UBound($aData) - 1 If $i Then $iRow += $aData[$i - 1][1] $aGroupInfo[$i][0] = $iRow ; Start row EndIf $aGroupInfo[$i][1] = $aData[$i][1] ; Total number of choices $aGroupInfo[$i][2] = $aData[$i][1] ; Choice index Local $aChoices[$aData[$i][1]] For $j = 2 To $aData[$i][1] + 1 $aChoices[$j - 2] = $aData[$i][$j] Next _ArrayShuffle($aChoices) $aGroupInfo[$i][3] = $aChoices ; Shuffled array of choices Next ; Fill display with groups names and choices $iRow = 0 For $i = 0 To UBound($aData) - 1 For $j = 2 To $aData[$i][1] + 1 $aDisplay[$iRow][0] = $aData[$i][$j] $aDisplay[$iRow][1] = $aData[$i][0] $iRow += 1 Next Next ; Run through choice rounds For $iChoice = 2 To $iCols - 1 ; For each group in turn For $iGroup = 0 To UBound($aData) - 1 ; Get next choice from the shuffled array $sChoice = ($aGroupInfo[$iGroup][3])[$aGroupInfo[$iGroup][2] - 1] ; Check choices remain If $aGroupInfo[$iGroup][2] > 1 Then ; Move to next choice for next round $aGroupInfo[$iGroup][2] -= 1 Else ; Reset choice count and reshuffle array $aGroupInfo[$iGroup][2] = $aGroupInfo[$iGroup][1] _ArrayShuffle($aGroupInfo[$iGroup][3]) EndIf ; Find choice in the original array $iIndex = _ArraySearch($aData, $sChoice, Default, Default, Default, Default, Default, $iGroup, True) ; Add to display in correct row $aDisplay[$aGroupInfo[$iGroup][0] + $iIndex - 2][$iChoice] = $sChoice Next Next _ArrayDisplay($aDisplay, "", Default, 8)Does it do what you want? If not, what needs to be changed?M23P.S. And I am still curious as to what exactly you are doing as this algorithm is obviously not meant for fruit selection in the real world and there might be a better way to do it if we knew the overall purpose. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Peggy Posted November 11, 2015 Author Posted November 11, 2015 Hi Melba23,That is the fuction I want, thank you for helping me so much ,I'm so happy!!About this program, this is the process of class scheduling.I just say for an example:eating fruit, that will be easy to understand for you.Thank you very very much !!!!!You're the best person I've ever seen~!!
Moderators Melba23 Posted November 11, 2015 Moderators Posted November 11, 2015 Peggy,Delighted I could help. Do not hesitate to let me know if your supervisor changes the requirements again!M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now