rayane888 Posted August 10, 2017 Share Posted August 10, 2017 (edited) Hello i have a array that have lot of strings text & it is random . i need to make it from long text to the short like -------------------------- yesyesyesyesyes yesyesyes yesyes yes the source is #include <Array.au3> $ss=StringSplit("yesyes|yesyesyesyes|yesyesyes|yes|yesyesyesyesyeseys",'|') _ArrayDisplay($ss, "reasult randome") Edited August 10, 2017 by rayane888 Link to comment Share on other sites More sharing options...
rayane888 Posted August 10, 2017 Author Share Posted August 10, 2017 any help ? Link to comment Share on other sites More sharing options...
Neutro Posted August 10, 2017 Share Posted August 10, 2017 (edited) Hello @rayane888 There you go: #include <Array.au3> $ss=StringSplit("yesyes|yesyesyesyes|yesyesyes|yes|yesyesyesyesyeseys",'|') _ArrayDisplay($ss, "reasult randome") _Arraysort($ss, 1) _ArrayDisplay($ss, "sorted result") Enjoy Edited August 10, 2017 by Neutro rayane888 1 Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
rayane888 Posted August 10, 2017 Author Share Posted August 10, 2017 (edited) 51 minutes ago, Neutro said: Hello @rayane888 There you go: #include <Array.au3> $ss=StringSplit("yesyes|yesyesyesyes|yesyesyes|yes|yesyesyesyesyeseys",'|') _ArrayDisplay($ss, "reasult randome") _Arraysort($ss, 1) _ArrayDisplay($ss, "sorted result") Enjoy thx but if we have diferent string not same how i do ??? like yes123yes yesvvvsdsdsdsyes yes9999yesyes like this exemple #include <Array.au3> $ss=StringSplit("yec21ds|yesyyesqyedsdd|yesye987ddyes|yexxss|yesyesg9999yesyesyeseydddddds",'|') _ArrayDisplay($ss, "reasult randome") _Arraysort($ss, 1) _ArrayDisplay($ss, "sorted result") Edited August 10, 2017 by rayane888 Link to comment Share on other sites More sharing options...
Neutro Posted August 10, 2017 Share Posted August 10, 2017 This is one way of doing it: #include <Array.au3> $ss=StringSplit("yec21ds|yesyyesqyedsdd|yesye987ddyes|yexxss|yesyesg9999yesyesyeseydddddds",'|') _ArrayDisplay($ss, "reasult randome") _ArrayColInsert($ss, 1) _ArrayDisplay($ss, "column inserted") ;put the string length of each string in the 2nd column for $i = 1 to $ss[0][0] $ss[$i][1] = StringLen($ss[$i][0]) Next _ArrayDisplay($ss, "length of all strings added") _ArraySort($ss, 1, 1, 0, 1) ;sort the second column _ArrayDisplay($ss, "sorted result by string length") _ArrayColDelete($ss, 1) ; remove second column _ArrayDisplay($ss, "final result") Basicly you add a column to your array, store the length of each string in this new column then use this column to sort the array then delete the column! rayane888 and izis89 2 Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
rayane888 Posted August 10, 2017 Author Share Posted August 10, 2017 14 minutes ago, Neutro said: This is one way of doing it: #include <Array.au3> $ss=StringSplit("yec21ds|yesyyesqyedsdd|yesye987ddyes|yexxss|yesyesg9999yesyesyeseydddddds",'|') _ArrayDisplay($ss, "reasult randome") _ArrayColInsert($ss, 1) _ArrayDisplay($ss, "column inserted") ;put the string length of each string in the 2nd column for $i = 1 to $ss[0][0] $ss[$i][1] = StringLen($ss[$i][0]) Next _ArrayDisplay($ss, "length of all strings added") _ArraySort($ss, 1, 1, 0, 1) ;sort the second column _ArrayDisplay($ss, "sorted result by string length") _ArrayColDelete($ss, 1) ; remove second column _ArrayDisplay($ss, "final result") Basicly you add a column to your array, store the length of each string in this new column then use this column to sort the array then delete the column! man you are are the best thx lot Link to comment Share on other sites More sharing options...
AspirinJunkie Posted August 10, 2017 Share Posted August 10, 2017 (edited) The alternative is to use a sorting function where you can use a user defined comparison function. In the attachement is an udf for doing this. With this the result can look like this: #include <DynArray.au3> $ss=StringSplit("yec21ds|yesyyesqyedsdd|yesye987ddyes|yexxss|yesyesg9999yesyesyeseydddddds",'|', 2) _ArrayDisplay($ss, "reasult randome") _ArraySortFlexible($ss, _MyCompare) _ArrayDisplay($ss, "sorted result") ; user defined compare function for individual sorting Func _MyCompare(ByRef $A, ByRef $B) Local $dA = StringLen($A), $dB = StringLen($B) Return $dA > $dB ? -1 : $dA < $dB ? 1 : 0 EndFunc DynArray.au3 Edited June 18, 2020 by AspirinJunkie rayane888 and Neutro 2 Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2017 Share Posted August 10, 2017 or just walk the array yourself? #include <Array.au3> $Ass=StringSplit("yec21ds|yesyyesqyedsdd|yesye987ddyes|yexxss|yesyesg9999yesyesyeseydddddds",'|' , 2) For $i = ubound($Ass) - 1 to 1 step -1 If StringLen($Ass[$i]) < StringLen($Ass[$i - 1]) Then _ArraySwap($Ass , $i , $i - 1) $i = ubound($Ass) EndIf Next _ArrayDisplay($Ass) Neutro 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
AspirinJunkie Posted August 10, 2017 Share Posted August 10, 2017 (edited) For small arrays ok. But for bigger arrays this algorithm which should be quite similar to bubble sort should be very inefficient. Edited August 10, 2017 by AspirinJunkie Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2017 Share Posted August 10, 2017 If you chose AutoIt for speed of execution, and then you included the Array UDF for its efficiency, and then without the actual data make assumptions about which method will take the fewest penalties.... I'm going to have a difficult time arguing the other side. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
AspirinJunkie Posted August 10, 2017 Share Posted August 10, 2017 keep calm. I also don't know the real data for this problem and i clearly said that for small arrays nobody need to think about a efficient algorithm. But if anyone with a similar problem reads this my statement is a hint for him that he should not wonder why the solution is really slow at bigger arrays. Especially why we have to make assumptions about the actual data we should discuss in every possible direction. Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2017 Share Posted August 10, 2017 defeatist arguments are defeatist. And "we have to make assumptions" might be their king. While you are making assumptions should the OP explore MySQL when he gets through your UDF, because yours is slower? My point was that the abstraction never ends, because everything about this language execution is slow af, comparatively. imho, the best answer in a thread is the one that the OP could write and understand themselves with their current skill set. Not necessarily the optimal solution. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
AspirinJunkie Posted August 10, 2017 Share Posted August 10, 2017 (edited) 34 minutes ago, iamtheky said: because everything about this language execution is slow af, comparatively. Make a test with such an array with 300 Elements. With your solution the user have to wait 17s. With my 0.04s. And this discrepance increases exponential with the number of elements. But i am not alowed to point at this behavoir because nobody use AutoIt for speed of execution - right? Then thanks for the clarification of what i am allowed to talk about here. Edited August 10, 2017 by AspirinJunkie izis89 1 Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2017 Share Posted August 10, 2017 (edited) Still making technical assumptions, and have now added social assumptions? literally ended with "in my humble opinion" and you took that as directive? And correct, nobody uses AutoIt in production for speed of execution (but I would like to hear a proper defense with a script that is faster than python, ruby, or bash alternatives). Make a test thread (or use any of the 50 we have ran before) and we will get a litany of solutions all within seconds of eachother. And even build edge cases where your flex sort will be slower, its not magic, nobody is doing anything special. Edited August 10, 2017 by iamtheky lost focus...as per usual ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 10, 2017 Moderators Share Posted August 10, 2017 Ok, we have provided the OP with a couple of different ways to skin the cat - awesome. How about we leave it to the OP to decide which he wants to employ, rather than continuing the pointless argument? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
iamtheky Posted August 10, 2017 Share Posted August 10, 2017 Booooo. I know the list sorting movie is the same every time, but I always begin hoping that maybe this time he doesn't shoot Old Yeller at the end and there's a badass sequel I didn't know about. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
AspirinJunkie Posted August 11, 2017 Share Posted August 11, 2017 8 hours ago, iamtheky said: but I always begin hoping that maybe this time he doesn't shoot Old Yeller at the end and there's a badass sequel I didn't know about. Then you should reconsider about your reaction on my simple hint about the behaviour on bigger numbers of elements. The statement was correct and can be a helpfull hint for other users. But everything you argue with was that a discussion of performance in AutoIt is senseless. I say that is not: It is not a difference in only some hypothetic milliseconds - it's a difference from maybe 15s vs 0.05s and even more. And this can be a difference of usable and unusable. And that's why i really wonder about your reaction to people who point at this. 10 hours ago, iamtheky said: but I would like to hear a proper defense with a script that is faster than python, ruby, or bash alternatives). Even in C++ your approach performs worster with > 500 elements than Neutro's approach in AutoIt. But better not talking about - right? Link to comment Share on other sites More sharing options...
iamtheky Posted August 11, 2017 Share Posted August 11, 2017 (edited) Again, with feeling story time ain't going to do it. Pick a data set and a sort objective and let the forum have at it. And the last quote was language and interpreter as a whole, how much slower is method x in autoit vs method x in those other languages, any other comparison is non sequitir. Am I supposed to do the Passive aggressive ending too? also, for the OP, my solution runs faster, at what point or configuration does yours start winning? (That's both rhetorical and dripping with sarcasm). Edited August 11, 2017 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
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