The Little Guy Posted January 6, 2011 Share Posted January 6, 2011 I was thinking how can I make a script that will build strings incrementing through each letter starting with "a" and ending with "zzzzzz" or what ever ending length I want such as 12. So if your were to output everything, you could find the words: "dog" "spider" "superman" "hippo" etc What would be the best way to do this, so I don't have to have a loop that is 500 blocks deep to show a word that is 500 letters example a ... z aa ab ac ... az ba bb bc ... ... aaa aab aac Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/ Share on other sites More sharing options...
trq Posted January 7, 2011 Share Posted January 7, 2011 Sorry, but its not at all clear what your wanting to do. Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1155966 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 Maybe this example will help. Just follow the pattern: a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be ... aaa aab aac aad aae aaf .... aba abb abc abd ..... aaaa aaab aaac .... abaa abab abac .... basically it walks its way through every string combination possible (using a looping method) with a string no longer than the defined max length and displaying them all on the screen (CLI). so, if there was a string max length of 10 and only using a-z lowercase there is a maximum of 141,167,095,653,376 combinations (26^10) Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1155992 Share on other sites More sharing options...
trq Posted January 7, 2011 Share Posted January 7, 2011 The computer running the program will be dead before it finishes. You've got the number 9and obviously the time), work out how long it will take to finish if 1 iteration took 1 hundredth of 1 second. What exactly do you hope to achieve by doing this? Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156018 Share on other sites More sharing options...
MMDE Posted January 7, 2011 Share Posted January 7, 2011 poor whatever he outputs this to... and sounds like bruteforce of some sort to me o.O Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156021 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 What exactly do you hope to achieve by doing this? Not really anything, I just want to make something like this. Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156030 Share on other sites More sharing options...
QuickOldCar Posted January 7, 2011 Share Posted January 7, 2011 Well I could see wanting to generate maybe words or numbers at random. But like the above persons said expect the server to just puke,exhaust, time out or w/e else with trying that many. It's just too many to produce. Now maybe if did in itsy bitsy steps and started saving either to text files or a database, then maybe you can. I sat here writing up something you can at least play with to try to suit your needs. Maybe it can give you some ideas, the end result I limited it to just showing words with length of 3, so if changed that to 2 or 1 would see the others. <?php $positions = 1; $i = 0; for ($i = 0;$i<$positions;$i++) { foreach ( range('a','z') as $alphabet) { $the_alphabet[] = $alphabet; } } if (++$i == $positions) break; foreach($the_alphabet as $k1 =>$v1){ $words[]=$v1; foreach($the_alphabet as $k2 => $v2){ $words[]=$v2; $words[]="$v1$v2"; foreach($the_alphabet as $k3 => $v3){ $words[]=$v3; $words[]="$v1$v2$v3"; $words[]="$v1$v3$v2"; } } } $words = array_unique($words); sort($words); foreach($words as $word){ $word_length = strlen($word); if ($word_length == 3) { //try 2 or 1 echo "$word<br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156050 Share on other sites More sharing options...
sasa Posted January 7, 2011 Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; not tested Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156193 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; not tested haha! I thought you were being sarcastic but it actually works! Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156233 Share on other sites More sharing options...
Pikachu2000 Posted January 7, 2011 Share Posted January 7, 2011 I never would have thought that would work either. Interesting. That could come in handy in the future. Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156234 Share on other sites More sharing options...
ignace Posted January 7, 2011 Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; Haha! If that only really worked Try: for($i= 'a'; $i < 'z'; $i++) echo $i; And now run: for($i= 'a'; $i <= 'z'; $i++) echo $i; Produces suddenly the double number of results (and orders incorrectly) The answer lies in it's implementation Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156286 Share on other sites More sharing options...
Anti-Moronic Posted January 7, 2011 Share Posted January 7, 2011 or maybe: for($color = 'white'; $color < 'black'; $color++) echo $color; Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156303 Share on other sites More sharing options...
BlueSkyIS Posted January 7, 2011 Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; not tested output: abcdefghijklmnopqrstuvwxyzaaabacadaeafagahaiajakalamanaoapaqarasatauavawaxayazbabbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzcacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczdadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzeaebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezfafbfcfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzgagbgcgdgegfggghgigjgkglgmgngogpgqgrgsgtgugvgwgxgygzhahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhziaibicidieifigihiiijikiliminioipiqirisitiuiviwixiyizjajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzkakbkckdkekfkgkhkikjkkklkmknkokpkqkrksktkukvkwkxkykzlalblcldlelflglhliljlklllmlnlolplqlrlsltlulvlwlxlylzmambmcmdmemfmgmhmimjmkmlmmmnmompmqmrmsmtmumvmwmxmymznanbncndnenfngnhninjnknlnmnnnonpnqnrnsntnunvnwnxnynzoaobocodoeofogohoiojokolomonooopoqorosotouovowoxoyozpapbpcpdpepfpgphpipjpkplpmpnpopppqprpsptpupvpwpxpypzqaqbqcqdqeqfqgqhqiqjqkqlqmqnqoqpqqqrqsqtquqvqwqxqyqzrarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzsasbscsdsesfsgshsisjskslsmsnsospsqsrssstsusvswsxsysztatbtctdtetftgthtitjtktltmtntotptqtrtstttutvtwtxtytzuaubucudueufuguhuiujukulumunuoupuqurusutuuuvuwuxuyuzvavbvcvdvevfvgvhvivjvkvlvmvnvovpvqvrvsvtvuvvvwvxvyvzwawbwcwdwewfwgwhwiwjwkwlwmwnwowpwqwrwswtwuwvwwwxwywzxaxbxcxdxexfxgxhxixjxkxlxmxnxoxpxqxrxsxtxuxvxwxxxyxzyaybycydyeyfygyhyiyjykylymynyoypyqyrysytyuyvywyxyyyzzazbzczdzezfzgzhzizjzkzlzmznzozpzqzrzsztzuzvzwzxzy Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156311 Share on other sites More sharing options...
Anti-Moronic Posted January 7, 2011 Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; not tested output: abcdefghijklmnopqrstuvwxyzaaabacadaeafagahaiajakalamanaoapaqarasatauavawaxayazbabbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzcacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczdadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzeaebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezfafbfcfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzgagbgcgdgegfggghgigjgkglgmgngogpgqgrgsgtgugvgwgxgygzhahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhziaibicidieifigihiiijikiliminioipiqirisitiuiviwixiyizjajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzkakbkckdkekfkgkhkikjkkklkmknkokpkqkrksktkukvkwkxkykzlalblcldlelflglhliljlklllmlnlolplqlrlsltlulvlwlxlylzmambmcmdmemfmgmhmimjmkmlmmmnmompmqmrmsmtmumvmwmxmymznanbncndnenfngnhninjnknlnmnnnonpnqnrnsntnunvnwnxnynzoaobocodoeofogohoiojokolomonooopoqorosotouovowoxoyozpapbpcpdpepfpgphpipjpkplpmpnpopppqprpsptpupvpwpxpypzqaqbqcqdqeqfqgqhqiqjqkqlqmqnqoqpqqqrqsqtquqvqwqxqyqzrarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzsasbscsdsesfsgshsisjskslsmsnsospsqsrssstsusvswsxsysztatbtctdtetftgthtitjtktltmtntotptqtrtstttutvtwtxtytzuaubucudueufuguhuiujukulumunuoupuqurusutuuuvuwuxuyuzvavbvcvdvevfvgvhvivjvkvlvmvnvovpvqvrvsvtvuvvvwvxvyvzwawbwcwdwewfwgwhwiwjwkwlwmwnwowpwqwrwswtwuwvwwwxwywzxaxbxcxdxexfxgxhxixjxkxlxmxnxoxpxqxrxsxtxuxvxwxxxyxzyaybycydyeyfygyhyiyjykylymynyoypyqyrysytyuyvywyxyyyzzazbzczdzezfzgzhzizjzkzlzmznzozpzqzrzsztzuzvzwzxzy I knew it'd work, see Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156313 Share on other sites More sharing options...
BlueSkyIS Posted January 7, 2011 Share Posted January 7, 2011 yep. the color one, not so much. Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156314 Share on other sites More sharing options...
Pikachu2000 Posted January 7, 2011 Share Posted January 7, 2011 Yeah, I just played around with it, but it's buggy as all hell. Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156316 Share on other sites More sharing options...
QuickOldCar Posted January 7, 2011 Share Posted January 7, 2011 no, is no zz Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156318 Share on other sites More sharing options...
ignace Posted January 7, 2011 Share Posted January 7, 2011 for($i= 'a'; $i <'zz'; $i++) echo $i; not tested output: abcdefghijklmnopqrstuvwxyzaaabacadaeafagahaiajakalamanaoapaqarasatauavawaxayazbabbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzcacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczdadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzeaebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezfafbfcfdfefffgfhfifjfkflfmfnfofpfqfrfsftfufvfwfxfyfzgagbgcgdgegfggghgigjgkglgmgngogpgqgrgsgtgugvgwgxgygzhahbhchdhehfhghhhihjhkhlhmhnhohphqhrhshthuhvhwhxhyhziaibicidieifigihiiijikiliminioipiqirisitiuiviwixiyizjajbjcjdjejfjgjhjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzkakbkckdkekfkgkhkikjkkklkmknkokpkqkrksktkukvkwkxkykzlalblcldlelflglhliljlklllmlnlolplqlrlsltlulvlwlxlylzmambmcmdmemfmgmhmimjmkmlmmmnmompmqmrmsmtmumvmwmxmymznanbncndnenfngnhninjnknlnmnnnonpnqnrnsntnunvnwnxnynzoaobocodoeofogohoiojokolomonooopoqorosotouovowoxoyozpapbpcpdpepfpgphpipjpkplpmpnpopppqprpsptpupvpwpxpypzqaqbqcqdqeqfqgqhqiqjqkqlqmqnqoqpqqqrqsqtquqvqwqxqyqzrarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzsasbscsdsesfsgshsisjskslsmsnsospsqsrssstsusvswsxsysztatbtctdtetftgthtitjtktltmtntotptqtrtstttutvtwtxtytzuaubucudueufuguhuiujukulumunuoupuqurusutuuuvuwuxuyuzvavbvcvdvevfvgvhvivjvkvlvmvnvovpvqvrvsvtvuvvvwvxvyvzwawbwcwdwewfwgwhwiwjwkwlwmwnwowpwqwrwswtwuwvwwwxwywzxaxbxcxdxexfxgxhxixjxkxlxmxnxoxpxqxrxsxtxuxvxwxxxyxzyaybycydyeyfygyhyiyjykylymynyoypyqyrysytyuyvywyxyyyzzazbzczdzezfzgzhzizjzkzlzmznzozpzqzrzsztzuzvzwzxzy I knew it'd work, see Now explain why it does this Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156336 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 I decided to try and throw some symbols, upper case letters and lower case letters in there as well... Doesn't work too well: $start = 32; $fin = 126; $depth = 1; $i = $start; while(true){ $opt = ''; for($d=0;$d<=$depth;$d++){ $opt .= chr($i); if($d == $depth){ $depth++; break; } } echo $opt."\n"; $i++; } Oh, and btw if you don't want it to end: $i = 'a'; while($i){ echo $i."\n"; $i++; } Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156337 Share on other sites More sharing options...
QuickOldCar Posted January 7, 2011 Share Posted January 7, 2011 Well here's the best way by far. I guess can even do sets of the 26 letters as well, something like show single letters, then show 2 letters, then show 3 letters and so on , but just do them in ranges so don't have to produce what you don't need. <?php $how_many_you_want = 50000;//each number will add an extra line/sequential alphabet string function seqAlphabet($numbers) { $alphabet = ''; while($numbers >= 1) { $numbers = $numbers - 1; $alphabet = chr(($numbers % 26)+97) . $alphabet; $numbers = $numbers / 26; } return $alphabet; } $string_position = range('1',$how_many_you_want); foreach ($string_position as $position) { echo seqAlphabet($position) . "<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156348 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 Using this: $i = 'a'; $c = 1; while(true){ echo $c.'. '.$i."\n"; if($i == 'ryan') exit; $i++; $c++; } This is how long it took to find my name 333308. ryan Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156352 Share on other sites More sharing options...
Anti-Moronic Posted January 7, 2011 Share Posted January 7, 2011 Now explain why it does this I am totally baffled at what is going on. To be honest I can't even understand a-z, but a-zz, a-zzzzzz?? what the hell is going on? :S Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156356 Share on other sites More sharing options...
Anti-Moronic Posted January 7, 2011 Share Posted January 7, 2011 Using this: $i = 'a'; $c = 1; while(true){ echo $c.'. '.$i."\n"; if($i == 'ryan') exit; $i++; $c++; } This is how long it took to find my name 333308. ryan See how long it takes to find my name: Dromodor Kastalian Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156358 Share on other sites More sharing options...
The Little Guy Posted January 7, 2011 Author Share Posted January 7, 2011 Using this: $i = 'a'; $c = 1; while(true){ echo $c.'. '.$i."\n"; if($i == 'ryan') exit; $i++; $c++; } This is how long it took to find my name 333308. ryan See how long it takes to find my name: Dromodor Kastalian It doesn't handle spaces Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156361 Share on other sites More sharing options...
Anti-Moronic Posted January 7, 2011 Share Posted January 7, 2011 Using this: $i = 'a'; $c = 1; while(true){ echo $c.'. '.$i."\n"; if($i == 'ryan') exit; $i++; $c++; } This is how long it took to find my name 333308. ryan See how long it takes to find my name: Dromodor Kastalian It doesn't handle spaces That's ok. You can just use my native first name: dromodorialmakirvahumvete Link to comment https://forums.phpfreaks.com/topic/223623-building-strings/#findComment-1156382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.