rrandom Posted November 22, 2007 Share Posted November 22, 2007 Hi all, I use pifast (http://numbers.computation.free.fr/Constants/PiProgram/pifast.html) to compute digits of pi, phi and e I want to modify the resulting text doc as the following: 1415926535 8979323846 2643383279 5028841971 6939937510 : 50 5820974944 5923078164 0628620899 8628034825 3421170679 : 100 ... should become 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 ... (no breaks, no formatting, just digit by digit) As pifast can compute a huge amount of digits, I need a fast solution to modify the resulting text file. Is Autoit a good way to solve this problem? Thank you r rAndom Link to comment Share on other sites More sharing options...
MerkurAlex Posted November 22, 2007 Share Posted November 22, 2007 Tada #include <array.au3> #include <file.au3> $file=fileopendialog("What file should i modify?",@scriptdir,"All files(*.*)") $files=filesavedialog("Where should i save the new file to?",@scriptdir,"All files(*.*)") $fos=fileopen($files,1) $fo=fileopen($file,0) $folines=_filecountlines($file) for $i=1 to $folines $fline=filereadline($fo,$i) $nspaces=stringreplace($fline,chr(32),"") $array=stringsplit($nspaces,"") $search=_arraysearch($array,":",0,$array[0]) do sleep(10) until not $search=0 $newstring=stringleft($nspaces,$search-1) filewrite($fos,$newstring) next fileclose($fo) fileclose($fos) oh my gosh now im just making code for people :/ not sure if this is the fastest way to do it but it works for me. [quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote] Link to comment Share on other sites More sharing options...
rrandom Posted November 22, 2007 Author Share Posted November 22, 2007 Hi EagleClaw, Oh my god, I´m just posting a question and you´re making the code for me (and others). :-) Thank you very much. I´ll give it a try and see how many seconds it´ll take for 1.000.000 digits. Have a nice day rraNDom Link to comment Share on other sites More sharing options...
rrandom Posted November 22, 2007 Author Share Posted November 22, 2007 Your script is working as desired, but it´s so sloooooow. ;-) Any modifications and other ideas are welcome. It has not at all to be Autoit. If you know an other tool to do the job, please tell me. On the other hand it would be interesting if somebody can tell, if and where Autoit is running into limits. Best wishes rr and oM Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2007 Share Posted November 22, 2007 Hi EagleClaw, Oh my god, I´m just posting a question and you´re making the code for me (and others). :-) Thank you very much. I´ll give it a try and see how many seconds it´ll take for 1.000.000 digits. Have a nice day rraNDom Try this: #include <array.au3> $ret = "" $filename = FileOpenDialog ("Open...", "", "Text Documents (*.txt)") $file = FileOpen ($filename, 0) $old = FileRead ($file) FileClose ($file) $file = FileOpen ($filename, 2) $split1 = StringSplit ($old, ":" & @CR & @LF & @CRLF) For $i = 1 to $split1[0] Step 3 $ret &= $split1[$i] Next $ret = StringStripWS ($ret, 8) FileWrite ($file, $ret) FileClose ($file) Lets see which is faster. Add this to the test script below the fileopendialouge (). $timer = TimerInit () and this at the very bottom. MsgBox (0, "", Round (TimerDiff ($timer)/60, 2) & " seconds") So it ends up looking like: #include <array.au3> $ret = "" $filename = FileOpenDialog ("Open...", "", "Text Documents (*.txt)") $timer = TimerInit () $file = FileOpen ($filename, 0) $old = FileRead ($file) FileClose ($file) $file = FileOpen ($filename, 2) $split1 = StringSplit ($old, ":" & @CR & @LF & @CRLF) For $i = 1 to $split1[0] Step 3 $ret &= $split1[$i] Next $ret = StringStripWS ($ret, 8) FileWrite ($file, $ret) FileClose ($file) MsgBox (0, "", Round (TimerDiff ($timer)/60, 2) & " seconds") Tell us how it goes Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
rrandom Posted November 22, 2007 Author Share Posted November 22, 2007 Hi Bert, that´s really fast, very fast, perfect fast. :-) But there is a detail wrong. Let me repeat the output structure of the pifast.exe: To give better orientation in the crowd of digits, the output textfile is structured in the following way: ----------------------------------------------------------------------------------- 1415926535 8979323846 2643383279 5028841971 6939937510 : 50 5820974944 5923078164 0628620899 8628034825 3421170679 : 100 8214808651 3282306647 0938446095 5058223172 5359408128 : 150 4811174502 8410270193 8521105559 6446229489 5493038196 : 200 4428810975 6659334461 2847564823 3786783165 2712019091 : 250 4564856692 3460348610 4543266482 1339360726 0249141273 : 300 7245870066 0631558817 4881520920 9628292540 9171536436 : 350 7892590360 0113305305 4882046652 1384146951 9415116094 : 400 3305727036 5759591953 0921861173 8193261179 3105118548 : 450 0744623799 6274956735 1885752724 8912279381 8301194912 : 500 9833673362 4406566430 8602139494 6395224737 1907021798 : 550 6094370277 0539217176 2931767523 8467481846 7669405132 : 600 0005681271 4526356082 7785771342 7577896091 7363717872 : 650 1468440901 2249534301 4654958537 1050792279 6892589235 : 700 4201995611 2129021960 8640344181 5981362977 4771309960 : 750 5187072113 4999999837 2978049951 0597317328 1609631859 : 800 5024459455 3469083026 4252230825 3344685035 2619311881 : 850 7101000313 7838752886 5875332083 8142061717 7669147303 : 900 5982534904 2875546873 1159562863 8823537875 9375195778 : 950 1857780532 1712268066 1300192787 6611195909 2164201989 : 1000 3809525720 1065485863 2788659361 5338182796 8230301952 : 1050 0353018529 6899577362 2599413891 2497217752 8347913151 : 1100 5574857242 4541506959 5082953311 6861727855 8890750983 : 1150 8175463746 4939319255 0604009277 0167113900 9848824012 : 1200 8583616035 6370766010 4710181942 9555961989 4676783744 : 1250 9448255379 7747268471 0404753464 6208046684 2590694912 : 1300 9331367702 8989152104 7521620569 6602405803 8150193511 : 1350 2533824300 3558764024 7496473263 9141992726 0426992279 : 1400 6782354781 6360093417 2164121992 4586315030 2861829745 : 1450 5570674983 8505494588 5869269956 9092721079 7509302955 : 1500 ---------------------------------------------------------------------------------- There are always 5 times 10 digits in a row. At the end of the row, the position of the last digit is given. (line 1 ends with ":50") One bloc contains 10 rows and there is a blank row between the blocs. The digit counters (:50, :100, ...) gets continously larger (100, 1000, 10000, 100000 ... and so on) Bert, your code is incorporation the counter digits into the result. It seems to be tricky to code Autoit to realize the increasing of the counter an cuts it out at the right point. Any ideas and help is very welcome. Thank you for your interest in this case. Best wishes rRa ndom Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2007 Share Posted November 22, 2007 (edited) How does this go for you? #include <array.au3> $ret = "" $filename = FileOpenDialog ("Open...", "", "Text Documents (*.txt)") $timer = TimerInit () $file = FileOpen ($filename, 0) $old = FileRead ($file) FileClose ($file) $file = FileOpen ($filename, 2) $split1 = StringSplit ($old, ":" & @CR & @LF & @CRLF) $multi = 10 For $i = 1 to $split1[0] Step 3 If $i = $multi Then $i += 3 $multi +=10 EndIf $ret &= $split1[$i] Next $ret = StringStripWS ($ret, 8) FileWrite ($file, $ret) FileClose ($file) MsgBox (0, "", Round (TimerDiff ($timer)/60, 2) & " seconds") *Not Tested* EDIT: Code... Just edit how much you plus $i by to fix it up to work perfect Edited November 22, 2007 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
rrandom Posted November 22, 2007 Author Share Posted November 22, 2007 Hello Bert, tested: The first 150 digits run perfect. But from 151 on I get the following 200250300550600 and afterwards the digits seem to be scrambled. :-( Any ideas? rrando M p.s. your code: the 1.000.000 digits took my standard system 16.82 seconds :-) Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2007 Share Posted November 22, 2007 Maybe this... Could also be faster? #include <array.au3> #include <file.au3> Dim $aArray $ret = "" $filename = FileOpenDialog ("Open...", "", "Text Documents (*.txt)") _FileReadToArray ($filename, $aArray) $file = FileOpen ($filename, 2) For $i = 1 to $aArray[0] $split1 = StringSplit ($aArray[$i], ":") _ArrayDisplay ($split1) $ret &= $split1[1] Next $ret = StringStripWS ($ret, 8) FileWrite ($file, $ret) FileClose ($file) You could also do it with regexp... I don't want to To hard at 10pm... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
rrandom Posted November 22, 2007 Author Share Posted November 22, 2007 (edited) Hi again Bert, I get an error message: Line12 _ArrayDisplay ($split) As to display the array isn´t needed, I erased this part of code. Everything works fine. :-) But the operation time increased up to 30 seconds. So what? ;-) Thanks rrAND om Edited November 22, 2007 by rrandom Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2007 Share Posted November 22, 2007 Hi again Bert,I get an error message:Line12 _ArrayDisplay ($split)As to display the array isn´t needed, I erased this part of code.Everything works fine. :-)But the operation time increased up to 30 seconds. So what? ;-) ThanksrrAND omIf you can work out the regexp, the string spilt by the line (@CRLF & @CR & @LF), and just return the first string from the reg. It is even possible to reg the whole thing. *I think* Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
BrettF Posted November 22, 2007 Share Posted November 22, 2007 Hi Bert,Is this:$file = FileOpen ($filename, 0)$old = FileRead ($file)FileClose ($file),so fast thet you can't "derrange" another app trying to access $file (to rewrite it)?thanksNot sure. I'd say it depends on file size... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 22, 2007 Moderators Share Posted November 22, 2007 Don't have time to work out a complete regexp for it... $sString would just be FileRead() ... I used ClipGet() when I copied your example text$sString = ClipGet() $aSRE = StringRegExp($sString, "(?s)([\d+\s\d+]+)\s:\s+\d+(?m:$|\r\n\r*\n*)", 3) $sHold = "" For $i = 0 To UBound($aSRE) - 1 Step 2 $sHold &= StringStripWS($aSRE[$i] & $aSRE[$i + 1], 8) & @CRLF Next $sHold = StringTrimRight($sHold, 2) $AA = StringSplit($sHold, @CRLF, 1) _ArrayDisplay($AA)$AA was just to show you in an array, you would use this if you just wanted the strings. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MerkurAlex Posted November 22, 2007 Share Posted November 22, 2007 Well i hope you find your soution i wrote my code at about 4am so im suprised it works. [quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote] 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