
happyuser
Members-
Posts
18 -
Joined
-
Last visited
happyuser's Achievements

Seeker (1/7)
0
Reputation
-
Yes you are right, the code is wrong. Line 9 should be $j=Int(random($i-1,52))+1 because int truncates (we need an integer between 1 and 52). That way it seems to be OK with no double.
-
What do you think of such a code to deal? #include <Array.au3> global $set[1] for $i=1 to 52 _ArrayAdd($set,$i); Next ;_ArrayDisplay($set,"") for $i=1 to 52 $j=int(random($i-1,52)) $prev=$set[$j] for $k=$j to 1+$i Step -1 $set[$k]=$set[$k-1] Next $set[$i]=$prev Next _ArrayDisplay($set,"") It operates a simple permutation over [1..52]. You have no more to do than give a correspondance between [1..52] and the cards. I don't know if it is really uniformly random but I imagine it is if random is uniform over (min..max). Regards
-
Array and finding consecutive numbers
happyuser replied to nitekram's topic in AutoIt General Help and Support
@SmOke_N The code is some posts above. Here is a revised version. const $tab[23]=[2,13,3,4,6,7,8,10,3,4,5,6,9,1,2,3,5,6,7,8,9,9,11] $l=0 $m=1 $t1=$tab[0] #length of earched serie $nb=5 #return if not found $id=-1 for $i=1 to ubound($tab)-1 $m=$m*abs($tab[$i]-$t1) if $m=1 then If $l==$nb-2 Then $id=$i-$nb+1 ExitLoop EndIf $l=$l+1 Else $m=1 $l=0 EndIf $t1=$tab[$i] Next ConsoleWrite(@crlf&"The index begining the serie is "&$id) if $id>=0 Then ConsoleWrite(@crlf&"The first element is "&$tab[$id]&@CRLF) EndIf After a closer look at pretended C code, I think that it does not do what it is supposed to. It should consider OK the following sequence : (12,10,3,2,3) because differences between two consecutive elements are always less than 2! -
Array and finding consecutive numbers
happyuser replied to nitekram's topic in AutoIt General Help and Support
@SmOkeN What I meant is you have two nested for loops (for $i / for $n) but one would have been sufficient. Nevertheless, one should go and look at the code produced to know about efficiency that's sure. @nitekram My code returns 9 but if you use $tab[$id] you would get the first terme of the serie Regards -
Array and finding consecutive numbers
happyuser replied to nitekram's topic in AutoIt General Help and Support
Smart code but rather inefficient. You go through table $i_consec times . Once would be enough. Once you have found two consecutive elements whose difference is not 1 it's useless to come back to $i+1. You can progress from the point you are in order to find a sequence. Hence my code. Perheaps efficiency is no longer a challenge.. -
Array and finding consecutive numbers
happyuser replied to nitekram's topic in AutoIt General Help and Support
Try something like : const $tab[12]=[2,13,3,4,6,7,8,10,3,4,5,6] $l=0 $m=1 $t1=$tab[0] #length of serie - 1 $nb=2 #return if not found $id=-1 for $i=1 to ubound($tab)-1 $m=$m*abs($tab[$i]-$t1) if $m=1 then If $l==$nb Then $id=$i-$nb ExitLoop EndIf $l=$l+1 Else $m=1 $l=0 EndIf $t1=$tab[$i] Next ConsoleWrite("The index begining the serie is "&$id) -
You have to keep control over msg loop of main :instead of that Do $msg = GUIGetMsg() ;Reads the status of the Checkboxes and sets a variable to either 1 for checked or 4 for not checked ;This HAS to be included before the UNTIL statement .. $status5 = GUICtrlRead($APP5_CHKBOX) $status6 = GUICtrlRead($APP6_CHKBOX) Until $msg = $EXIT Or $msg = $START If $msg = $EXIT Then Exit ;Checks the status of the Checkboxes and calls the application function(s) if the checkbox is enabled If $status1 = 1 Then Call("One_Service_register") ... If $status6 = 1 Then Call("Three_Service_Unregister") You should have something like While 1 $msg = GUIGetMessage() If GUICtrlRead($APP5_CHKBOX) = $GUI_CHECKED then procedure1 Endif .. If $msg = $EXIT then ExitLoop Wend
-
How to remove everything but "x"
happyuser replied to Aeterna's topic in AutoIt General Help and Support
Be more precise, the question is not clear. Do you want to keep all lines begining by P or B or do you want to keep only B and P? Do you want to keep the structure of lines (CR/LF )? Try something like While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If $line[1]='B' or $line[1]='P' then FileWriteLine($g,$line) Wend It should produce a new file with lines begining by P or B only. -
No, I mean : func recursiv_func($x) if condition1 then return func2 else if condition2 then return func3 else return recursiv_func(phi($x)) endif endif where phi($x) insures that the algorithm converges for example phi($x)=$x-1 and recursiv_func(1) is a known constant. See example of fac(x) where fac is called recursively except when x=1 for which fac(x)=1.
-
The model of recursivity is computing of function fac. Here is a example of programming fac with recursivity and it works. #include <constants.au3> #include <GUIConstantsEx.au3> GUICreate("My GUI Button",300,100); will create a dialog box that when displayed is centered $label = GUICtrlCreateLabel("0.00",10,10,200) $pg=GUICtrlCreateProgress(10,30,200,-1,0x01) $Button_1 = GUICtrlCreateButton("Run .EXE", 10, 50, 100) GUISetState() ; will display an dialog box with 2 button While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $f=fac(10) guictrlsetdata($label,$f) EndSelect WEnd Func fac($i) if $i=1 then return 1 Else return $i*fac($i-1) EndIf EndFunc What you can see is that there is a test that insures that recursivity is not infinite. $i decreases and at last, when it is equal to 1 the recursivity stops. You have to insure that in your case, this is true. You could code your problem like that : func 1 if cond 1 then res 1 else if cond 2 then res 2 else func 1 endfunc That sort of recursivity works providing that it is never, in any case, infinite. Regards
-
Converting console output to progress information
happyuser replied to Rarst's topic in AutoIt General Help and Support
May I interfere with your topic? I think I have some clue. I was trying to create a progress bar to follow execution of an external child task. I got nothing before exit of task and, at that moment, I got all output at once. I read your post and tried your code with avdump. Run on some 2 Go of avi file, it is rather long and I noticed what you describe, erratic output in he progress bar. I had the idea to redefine the output of my former task and to make it very verbose. I output blabla and once every sec or so output x% x ranging from 1 to 100. I read the output and extract x. Then I discovered that the progress bar is smooth and translates every progress % by %. I think that the output or the function read buffers data until the volume is large enough. Hence the big loop times you noticed. The solution would be to find how to oblige data not to be bufferized that way. Regards -
Hi, I have the same sort of question (see http://www.autoitscript.com/forum/index.php?showtopic=84017 ). I want to show a progress bar but it doesn't work. I have tried the example up here. Same behaviour. The task runs in the background, the copy is effective but nothing is visible in the progress bar. I suspect that the StdoutRead never returns before completing of external task even with the switch "peek" (3rd parameter). It returns at the end with the total output of external task. Not what I need. Does someone of the development team can address such a problem? Thank you. Regards
-
Hello, I'm looking in the same direction and was puzzled by the help example. Do I understand well your suggested code if I say that the second parameter (TRUE) in StdoutRead is peek parameter? While ProcessExists($foo) $line = StdoutRead($foo, True) $line2 = StderrRead($foo, True) WEnd In such circumstances, the code should not wait until end of child process but poll stdout for new char. I cannont obtain such a behaviour. My code (exemple below) is supposed to receive output from child while child is running, enabling to control the progress and showing it in a progress bar. Unfortunately, the code waits until child exits and prevents me from monitoring the progress. I get stdout only once when child exits. Do you know why? Local $Button_1, $msg GUICreate("My GUI Button"); will create a dialog box that when displayed is centered $Button_1 = GUICtrlCreateButton("Run .EXE", 10, 30, 100) $prg=GUICtrlCreateProgress(10,60,200,20) $in=GUICtrlCreateInput("",10,90,200,20) GUISetState() $tst=0 ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 $tst=Run('test.exe','',0,$STDOUT_CHILD) EndSelect if $tst<>0 Then While ProcessExists($tst) $line = StdoutRead($tst, True) GUICtrlSetData($prg,strlen($line)) WEnd EndIf WEnd
-
Use of $STDOUT_CHILD (SOLVED)
happyuser replied to happyuser's topic in AutoIt General Help and Support
Tank you I check all those ref A day later.. I found that data coming from console output if buffered and delivered by StdoutRead when buffer is full. My task was not enough verbose to fill the buffer and nothing happened til end of task. I have formatted every output of the task in order to fill the buffer (255 char). Now every output triggers the read and the progress bar runs smoothly from 0% to 100%. -
Use of $STDOUT_CHILD (SOLVED)
happyuser replied to happyuser's topic in AutoIt General Help and Support
If I understand well what is said in help file, it should work the way I need, the external task running while its output is monitored by the parent script. Let's read the article relative to StdOutRead : "If StdoutRead is called with a third argument other than zero, StdoutRead will "peek at" the stream rather than actually reading from it, and return the characters that could be read from the stream. When run as a "peek" StdoutRead always returns immediately. Note that any characters are still present on the stream after a peek and will be returned on the next read operation." While waiting for a message from my window, the script should query for output from child allowing to check the progress through periodic output. Would you agree or what did I miss?