Peggy

excel table with arrary and for next loop for scheduling problems_2

6 posts in this topic

#1 ·  Posted (edited)

[Rule]
1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack

1.thumb.jpg.fbde7c98e1c9ffd7f6557dcd7ec1
2. Every person eating a fruit, and each times one person can eat the same fruit (or random fruit)
3. Last eaten fruit can not eat
4. so be scheduled
5. 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.thumb.jpg.6688381fa3a5b3b41c32c2339378
2. The second They are chose random first to eat.

3.thumb.jpg.f4d7feefb9c8e81dd9cdbce4f3e1
3. Third  They are chose random first to eat.

4.thumb.jpg.74c2575768754dab0472b90ea449
4. Fourth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too.

5.thumb.jpg.7836a56d5a33b26ed88d7ee564e1
5. Fifth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too.

 

6.thumb.jpg.64950d4f51ef58151cdac005d58d


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!!:D:D

 

 

 

 

 

 

Edited by Peggy

Share this post


Link to post
Share on other sites



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

 

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Melba23,
Thanks for your reply!!!I feel very moved!! :D


- 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, Susan

47.thumb.jpg.4ff74b560b00ddc5c1e64a4f7ff

1. Round 1: each one Random choice.(Each one can choose the same fruit)

 

48.thumb.jpg.6c6f4a914cdc841a749be657ef6

2. Round 2: each one Random choice.(each one can't eat Previous fruit Unless all eaten up)

49.thumb.jpg.255a6b2020594034b5344c98b93

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

50.thumb.jpg.1ede09792d8c69ed8043b97ba46

Thanks for your  great help!! :D

 

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.

44.thumb.jpg.03215a14ba4bff1a15ea0a57735

we hope result is  .. 

 

43.thumb.jpg.a3ae7c8c35dff59f1732562709d

Thanks for your  great help!! :D:D

Edited by Peggy

Share this post


Link to post
Share on other sites

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

 

#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?

M23

P.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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

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~!!:lol:^_^

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


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

  • Similar Content

    • 31290
      By 31290
      Hi guys, 
      Hope you are fine today
      I'm trying to restart a function by calling it back in the script:
      Here's my code so far:
      Func f_VPN() $iInputBox = InputBox("Password", "Please Enter the User's password.") If @Error = 1 Then GUICtrlSetState($fVPN, $GUI_UNCHECKED) Else ShellExecute("C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe") $hVPN = WinWait("Cisco AnyConnect Secure Mobility Client", "Ready to connect") ControlClick($hVPN, "", "Button1") $hVPN1 = WinWait("Cisco AnyConnect | SEE VPN", "Cancel") ControlSetText($hVPN1, "", "Edit2", @Username) Sleep(250) ControlSetText($hVPN1, "", "Edit3", $iInputBox) Sleep(250) ControlClick($hVPN1, "", "Button1") Sleep(5000) If ControlGetText("Cisco AnyConnect Secure Mobility Client", "", "Static2") = "Login Failed" Then ControlClick("Cisco AnyConnect Secure Mobility Client", "", "Button4") WinClose($hVPN) f_VPN() Else ShellExecute("C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe") If ControlGetText("Cisco AnyConnect Secure Mobility Client", "", "Static2") = "Connected To SEE VPN." Then ControlClick("Cisco AnyConnect Secure Mobility Client", "", "Button1") Sleep(1000) WinClose("Cisco AnyConnect Secure Mobility Client", "") ProcessClose("vpnui.exe") ; ProcessClose("explorer.exe") <<< TO UNCOMMENT IniWrite($oIniFile, "LaptopChkBox", "VPN", "1") EndIf EndIf EndFunc I'd like to the function to be restarted in the case the password provided is not correct. 
      I've googled many things but nothing very relevant.
      Any ideas over here?
      Thanks
      -31290
       
    • mazz3d
      By mazz3d
      hello  everyone,
      I'm new with AutoIT and just looking for a way to open Firefox with random window size
      i have tried too many different samples from the web, some how it works but i can't make it works with Firefox 
      MozRpel and ff.au3 installed 
      right now i can open Firefox with this code, but i still can't control the window of Firefox
      ; open firefox #include <ff.au3> _FFStart() ; open firefox with random size  
    • harvester2001
      By harvester2001
      Hi
      I need some help.
      I try ping computers from targets.txt (I have computer name in lines) if they ping I want do something and after that remove pc name from targets.txt. It`s working but problem is when I put this inside loop, because I need run script until all computers will not be removed from the list (targets.txt). I don`t know how to "refresh" array
      Please help
      #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Local $PC_list = "\targets.txt" Local $bTargets = FileReadToArray(@ScriptDir& $PC_list) Do _check_ping() ;count_lines Local $file_count_lines = _FileCountLines(@ScriptDir& $PC_list) $i = $file_count_lines ConsoleWrite("na liście "&$i & @CRLF) Until $i = 0 ; IF &i = 0 then show MsgBox MsgBox(1, "xXx", "Finish") ;PING Func _check_ping() For $sPC In $bTargets $var = Ping($sPC, 250) If $var Then ConsoleWrite($sPC &"online"& @CRLF) ;Do something ;Delete $sPC from targets.txt Local $_Array _FileReadToArray ( @ScriptDir& "\targets.txt", $_Array ) $_Array = _DeleteArrayElementWithStringInstr ( $_Array, $sPC ) _FileWriteFromArray ( @ScriptDir& "\targets.txt", $_Array, 1 ) Sleep(200) Else ConsoleWrite($sPC &"offline"& @CRLF) EndIf Next EndFunc ;DELETE LINE FROM TXT Func _DeleteArrayElementWithStringInstr ( $_Array, $_String ) Local $_Item For $_Element In $_Array If StringInStr ( $_Element, $_String ) <> 0 Then _ArrayDelete ( $_Array, $_Item ) Else $_Item+=1 EndIf Next Return ( $_Array ) EndFunc ;==> _DeleteArrayElementWithStringInstr ( )  
    • harvester2001
      By harvester2001
      Hi
      I need help, I found script to check computer model. I want use it in loop to chceck multiple pc`s (targets.txt with computer names).
      But when i try use inside loop i get error: Variable must be of type "Object" and I dont know how to fix this
      Plz help
       
      Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\scan.log" $msgBox = MsgBox(4, "Scan", "need tergets.txt") Example() Func Example() If $msgBox = 7 Then exit EndIf If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "File: targets.txt - no exist !") Exit EndIf FileOpen($targets, 0) Global $arr[1000] ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; chceck if pc is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE Local $strComputer = $arr[$i] $colItems = "" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ "0x10" + "0x20") If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Vendor: " & $objItem.Vendor & @CRLF $Output = $Output & "SN: " & $objItem.IdentifyingNumber & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "UUID: " & $objItem.UUID & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" ) Endif Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc  
       
    • mond1106
      By mond1106
      how do I break the loop if my program is stuck in it without exiting the whole program?
       
      i just want it to start from the beginning of the code here is my program
       
      While 1
      $picture = "target.png"
      $result = _ImageSearch($picture,1,$x1,$y1,0,0)
      If $result = 1 Then
         Send("{4}")
         MouseClick("left",$x1,$y1,1,1)
         Sleep(2000)

         Do
         $picture2 = "status.png"
         $result2 = _ImageSearch($picture2,1,$x1,$y1,0,0)
         
         Send("{2}")
         Send("{1}")
      Until $result2 = 1
       
       
      as you see if my program doesnt detect  or see picture2 then the loop wont stop.