AutoHotkey Community

It is currently May 27th, 2012, 1:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: January 6th, 2010, 2:21 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
I want to find all possible combinations of letters and digits restricted to a given length. The results of a simplified example using the letters "abc" and restricted to a length of 2 would be:
Quote:
AA
AA
AB
AC
BA
BB
BC
CA
CB
CC


I started to adapt this script of Zed Gecko:
Code:
SetBatchlines -1
#NoEnv


loop, 3 ;26 chars + 9 digits
{
   AsciNum := A_Index + 64 ;48
   if (AsciNum > 57 and AsciNum < 65)
    continue
   baselist .= Chr(AsciNum)
}


new_newlist := makelists(baselist, "")
MsgBox %list_idx% strings created:`n`n%FinalList%
;fileappend, %FinalList%, permutations.txt
Return

makelists(baselist, newlist)
{

   loop, parse, baselist
   {
      global rec_depth
      thischar := A_Loopfield
      StringReplace, newbaselist, baselist, %thischar%,, All
      new_newlist := newlist . thischar
      if (newbaselist = "")
      {
         rec_depth := 0
         Tooltip, %rec_depth%, 0, 40, 2
         newlist(new_newlist)
      }
      else
      {
         rec_depth ++
         Tooltip, %rec_depth%, 0, 40, 2
         makelists(newbaselist, new_newlist)   
      }
   }
   return new_newlist
}

newlist(newlist)
{
   global FinalList
   global list_idx
   SetFormat, float, 3.0
   list_idx ++
   FinalList := FinalList . "`n" . newlist
   tooltip %list_idx%, 0, 0, 1
   return   
}


which can produce this kind of list:

Quote:
ABC
ACB
BAC
BCA
CAB
CBA


But I'm lost as to what to do next:

1. I have no idea how to implement a restriction on the total length of the string.

2. I have no idea how to specify that the same letters can occur multiple times in the string.

3. I have used, but never written recursive functions before. Where to start?

I wanted to see if it was possible to write a script which would use the above mentioned functions together with URLDownloadToVar to find available and short domain names in certain country domains (Such as .no, .ca etc.).

If URLDownloadToVar returns 0, the script would assume the domain is available. Although this is probably not a sure-fire solution, it avoids (mis)use of online domain whois database.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2010, 9:10 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
1 & 2: Perhaps evans script is of use:
http://www.autohotkey.com/forum/topic39873.html

Just because a domain name doesn't exist doesn't mean it isn't registered so it is probably not a good solution as you'd still have to check each "valid" one to see if it is actually free.

I wouldn't hold your breath for 2-3 letter domain names:
http://www.yafla.com/dforbes/Interestin ... main_Names
but you may have luck with non TLDs

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2010, 9:17 pm 
Offline

Joined: July 25th, 2006, 9:06 am
Posts: 51
There was some nice code written by VxE that is recursive.
Code:
; Permutate -------------------------------
; creates a list of permutations from word

Permutate(set,delimeter="",trim="", presc="")
{ ; function by [VxE]
  ; returns a newline-seperated list of all
  ; unique permutations of the input set.
  ; set = word to be worked on
  ; delimiter can be used to provide a list of words
  ; trim is for trimming characters out of the word
  ; presc = use unknown
  ; Note that the length of the list will be (N!)
   d := SubStr(delimeter,1,1)
   StringSplit, m, set, %d%, %trim%
   IfEqual, m0, 1, return m1 d presc
   Loop %m0%
   {
      remains := m1
      Loop % m0-2
         x := A_Index + 1, remains .= d m%x%
      list .= Permutate(remains, d, trim, m%m0% d presc)"`n"
      mx := m1
      Loop % m0-1
         x := A_Index + 1, m%A_Index% := m%x%
      m%m0% := mx
   }
   return substr(list, 1, -1)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2010, 11:28 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
Thanks guys, but all three scripts (Zed Gecko, Evan and VxE) seem to do the same thing, namely find all permutations of a string. This is good and well, but I'm no closer to solving my script or learning about recursion in AHK. Perhaps all of this is simply above me.

hugov: I'm painstakingly aware of the slim pickings in short domain names, that's precisely why I need this kind of script to increase the odds of finding something I can use.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Leef_me, WillTroll and 29 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group