AutoHotkey Community

It is currently May 26th, 2012, 6:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9 ... 28  Next
Author Message
 Post subject:
PostPosted: June 19th, 2009, 5:14 pm 
@infogulch: added :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 5:26 pm 
If you want to contribute yourself, here is the MediaWiki code

Code:
=={{Header|AutoHotkey}}==
{{AutoHotkey case}}
Source: [http://www.autohotkey.com/forum/topic44657.html AutoHotkey forum] by yournick
<lang autohotkey>
Your code here
</lang>


Make sure you put it in the right alphabetical order in the page with the other languages.

HTH


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 5:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
n-l-i-d wrote:
I added all of Laszlo's functions, apart from the MontePi, couldn't find that one... :?
Monte Carlo Simulation
infogulch wrote:
what about Laszlo's MD5?
It could be posted there, too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 6:03 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
infogulch wrote:
Bottom of Unimplemented Page wrote:
And remember that this list is not entirely live; It's updated periodically by ImplSearchBot, currently every four hours.
Oh.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject: disclaimers
PostPosted: June 19th, 2009, 6:26 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Quote:
Note: AutoHotkey is case-insensitive. Keywords are capitalized and variables lowercased for clarity and consistency with the documentation.

This disclaimer is unnecessary on the task pages.
It may be more appropriate on the main autohotkey page or its talk page: here or here

looks light syntax highlighting is back online.
I have also updated the geshi lexer: here, and passed it on to rosettacode. Hopefully they will update it soon.

46 more tasks till the 200 tasks / top 10 milestone !


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Combinations
PostPosted: June 19th, 2009, 6:57 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
We can write a single line function to list all (n,t) combinations, and sort the result with another function.
Code:
MsgBox % Comb(1,1)
MsgBox % Comb(3,3)
MsgBox % Comb(3,2)
MsgBox % Comb(2,3)
MsgBox % Comb(5,3)

CR(n,t) { ; List all n choose t combinations of 1..n, recursively
   Return t<1 || t>n ? "" : n=1 ? 1 : CR(n-1,t) (n-1<t ? "" : "`n") RegExReplace(CR(n-1,t-1),"`am)$",t=1 ? n : " " n)
}

Comb(n,t) { ; List all n choose t combinations of 1..n, lexicographically
   c := CR(n,t)
   Sort c
   Return c
}

It is kind of cheating, so here is a traditional, iterative version (although combinations are listed in reverse order). I posted it earlier to the AHK Forum.
Code:
Comb(n,t) { ; Generate all n choose t combinations of 1..n, lexicographically
   IfLess n,%t%, Return
   Loop %t%
      c%A_Index% := A_Index
   i := t+1, c%i% := n+1

   Loop {
      Loop %t%
         i := t+1-A_Index, c .= c%i% " "
      c .= "`n"     ; combinations in new lines
      j := 1, i := 2
      Loop
         If (c%j%+1 = c%i%)
             c%j% := j, ++j, ++i
         Else Break
      If (j > t)
         Return c
      c%j% += 1
   }
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 19th, 2009, 7:17 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
There are half a dozen tasks related to list manipulation on rosetta: data structures
If someone wants to take a hack at these, could use: Laszlo's list manipulation library

I started an ask for help thread for Doubly linked list, based on code by rulfzid: discussion.
related:
ahkdll: improvements to numget, numput
If I can build in memory management versions of numget, numput; it may allow for more efficient scripted implementations of compound data structures such as arrays and lists.


Last edited by tinku99 on June 19th, 2009, 7:23 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 19th, 2009, 7:23 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The Common number base formatting task asks about language support of output of numbers in different bases. Calls to the Windows standard runtime dll might qualify:
Code:
MsgBox % BC("FF",16,3) ; -> 100110 in base 3 = FF in hex = 256 in base 10

BC(NumStr,InputBase=8,OutputBase=10) {
  Static S = 12345678901234567890123456789012345678901234567890123456789012345
  DllCall("msvcrt\_i64toa","Int64",DllCall("msvcrt\_strtoui64","Str",NumStr,"Uint",0,"UInt",InputBase,"CDECLInt64"),"Str",S,"UInt",OutputBase,"CDECL")
  Return S
}


The same code can be posted to the common number base parsing task, too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Number base conversion
PostPosted: June 19th, 2009, 7:46 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
For the Number base conversion task we could post shorter (single line) recursive functions:
Code:
MsgBox % ToBase(29,3)
MsgBox % ToBase(255,16)

MsgBox % FromBase("100",8)
MsgBox % FromBase("ff",16)

ToBase(n,b) { ; n >= 0, 1 < b <= 36
   Return (n < b ? "" : ToBase(n//b,b)) . ((d:=mod(n,b)) < 10 ? d : Chr(d+87))
}

FromBase(s,b) { ; convert base b number s=strings of 0..9,a..z, to AHK number
   Return (L:=StrLen(s))=0 ? "":(L>1 ? FromBase(SubStr(s,1,L-1),b)*b:0) + ((c:=Asc(SubStr(s,0)))>57 ? c-87:c-48)
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Random Numbers
PostPosted: June 19th, 2009, 9:07 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Normally distributed random numbers of given mean and standard deviation by Box-Muller method:
Code:
Loop 40
   R .= RandN(1,0.5) "`n"  ; mean = 1.0, standard deviation = 0.5
MsgBox %R%

RandN(m,s) { ; Normally distributed random numbers of mean = m, std.dev = s by Box-Muller method
   Static i, Y
   If (i := !i) { ; every other call
      Random U, 0, 1.0
      Random V, 0, 6.2831853071795862
      U := sqrt(-2*ln(U))*s
      Y := m + U*sin(V)
      Return m + U*cos(V)
   }
   Return Y
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 9:13 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Column Aligner. With left, center, and right options.

Center was a pain in the butt. :x

:roll:

Code:
lines =
(
|$|$|$|$|$|$|$|$|$|$|$|
Given$a$text$file$of$many$lines,$where$fields$within$a$line$
are$delineated$by$a$single$'dollar'$character,$write$a$program
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
column$are$separated$by$at$least$one$space.
Further,$allow$for$each$word$in$a$column$to$be$either$left$
justified,$right$justified,$or$center$justified$within$its$column.
)


MsgBox % ColumnJustify(lines, "r")


ColumnJustify(lines, lcr = "l", del="$")
{
   Loop, Parse, lines, `n, `r
      Loop, Parse, A_LoopField, %del%
         c%A_Index% := c%A_Index% > StrLen(A_LoopField) ? c%A_Index% : StrLen(A_LoopField)
         , max := max > c%A_Index% ? max : c%A_Index%
   blank := Fill( " ", max )
   Loop, Parse, lines, `n, `r
   {
      Loop, Parse, A_LoopField, %del%
         out .= (A_Index = 1 ? "" : " ")
         . (lcr = "l"
            ? SubStr(A_LoopField blank, 1, c%A_Index%)
         : lcr = "r"
            ? SubStr(blank A_LoopField, -c%A_Index%+1)
         : SubStr(blank A_LoopField blank
         , (Ceil((max * 2 + StrLen(A_LoopField))/2) - Ceil(c%A_Index%/2) + 1)
         , c%A_Index%))
      out .= "`n"
   }
   return out
}


Fill(chr, len)
{
   static y
   if !y
      VarSetCapacity(x, 64), VarSetCapacity(x, 0), y := True
   return x, VarSetCapacity(x, len, Asc(chr))
}


Edit: Oops. Found an error, center isn't working right. Pls hold...
Edit Again: Fixed, sry bout that.

Edit: Here's another version that separates the different alignments into different loops. It's probably faster, and definately easier for people to read (e.g. on rosettacode) but it's longer.. >_>
Code:
lines =
(
|$|$|$|$|$|$|$|$|$|$|$|
Given$a$text$file$of$many$lines,$where$fields$within$a$line$
are$delineated$by$a$single$'dollar'$character,$write$a$program
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
column$are$separated$by$at$least$one$space.
Further,$allow$for$each$word$in$a$column$to$be$either$left$
justified,$right$justified,$or$center$justified$within$its$column.
)


MsgBox % ColumnJustify(lines, "l")


ColumnJustify(lines, lcr = "l", del="$")
{
   Loop, Parse, lines, `n, `r
      Loop, Parse, A_LoopField, %del%
      {
         If ((t := StrLen(A_LoopField)) > c%A_Index% )
            c%A_Index% :=  t
         If (t > max)
            max := t
      }
   blank := Fill( " ", max )
   If (lcr = "l") ;left-justify
      Loop, Parse, lines, `n, `r
         Loop, Parse, A_LoopField, %del%
            out .= (A_Index = 1 ? "`n" : " ") SubStr(A_LoopField blank, 1, c%A_Index%)
   Else If (lcr = "r") ;right-justify
      Loop, Parse, lines, `n, `r
         Loop, Parse, A_LoopField, %del%
            out .= (A_Index = 1 ? "`n" : " ") SubStr(blank A_LoopField, -c%A_Index%+1)
   Else If (lcr = "c") ;center-justify
      Loop, Parse, lines, `n, `r
         Loop, Parse, A_LoopField, %del%
            out .= (A_Index = 1 ? "`n" : " ") SubStr(blank A_LoopField blank
               , (Ceil((max * 2 + StrLen(A_LoopField))/2) - Ceil(c%A_Index%/2) + 1)
               , c%A_Index%)
   return SubStr(out, 2)
}


Fill(chr, len)
{
   static y
   if !y
      VarSetCapacity(x, 64), VarSetCapacity(x, 0), y := True
   return x, VarSetCapacity(x, len, Asc(chr))
}

_________________
Scripts - License


Last edited by infogulch on February 2nd, 2010, 8:18 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Power Set
PostPosted: June 19th, 2009, 11:00 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The Power Set task can also be solved with a single line recursive function, although the result will not be sorted. We touch up the data before and after for a nicer look.
Code:
MsgBox % PowerSet("")
MsgBox % PowerSet("-")
MsgBox % PowerSet("a bb")
MsgBox % PowerSet("4,1,2,3,4,5",",")

PS(s,d=" ") { ; The power set of a list s, separated by d (space), with extra delimiters
   Return s="" ? "{}" : (p:=InStr(s,d)) ? (w:=PS(SubStr(s,p+1),d)) "`n" RegExReplace(w,"}",d SubStr(s,1,p-1) "}") : "{}`n{" s "}"
}
PowerSet(s,d=" ") { ; The power set of a list s, separated by d (space)
   Sort s, RUD%d%   ; Sort input for nicer output, remove duplicates
   P := PS(s,d)
   StringReplace P, P, {%d%, {, All
   Return P
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Probabilistic Choice
PostPosted: June 19th, 2009, 11:37 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Here is a straightforward implementation of the Probabilistic Choice task:
Code:
s1 := "aleph",   p1 := 1/5.0                       ; Input
s2 := "beth",    p2 := 1/6.0
s3 := "gimel",   p3 := 1/7.0
s4 := "daleth",  p4 := 1/8.0
s5 := "he",      p5 := 1/9.0
s6 := "waw",     p6 := 1/10.0
s7 := "zayin",   p7 := 1/11.0
s8 := "heth",    p8 := 1-p1-p2-p3-p4-p5-p6-p7
n := 8, r0 := 0, r%n% := 1                         ; auxiliary data

Loop % n-1
   i := A_Index-1, r%A_Index% := r%i% + p%A_Index% ; cummulative distribution

Loop 1000000 {
   Random R, 0, 1.0
   Loop %n%                                        ; linear search
      If (R < r%A_Index%) {
          c%A_Index%++
          Break
      }
}
                                                   ; Output
Loop %n%
   t .= s%A_Index% "`t" p%A_Index% "`t" c%A_Index%*1.0e-6 "`n"
Msgbox %t%

The result:
Code:
---------------------------
aleph  0.200000   0.199960
beth   0.166667   0.166146
gimel  0.142857   0.142624
daleth 0.125000   0.124924
he     0.111111   0.111226
waw    0.100000   0.100434
zayin  0.090909   0.091344
heth   0.063456   0.063342
---------------------------


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Zig Zag
PostPosted: June 20th, 2009, 3:54 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The script for the Zig Zag task was modeled after the Common Lisp code, with formatted output:
Code:
n = 5                           ; size
v := x := y := 1                ; initial values
Loop % n*n {                    ; for every array element
   a_%x%_%y% := v++             ; assign the next index
   If ((x+y)&1)                 ; odd diagonal
      If (x < n)                ; while inside the square
         y -= y>1, x++          ; move right-up
      Else y++                  ; on the edge increment y, but not x: to even diagonal
   Else                         ; even diagonal
      If (y < n)                ; while inside the square
         x -= x>1, y++          ; move left-down
      Else x++                  ; on the edge increment x, but not y: to odd diagonal
}

Loop %n% {                      ; generate printout
   x := A_Index                 ; for each row
   Loop %n%                     ; and for each column
      t .= a_%x%_%A_Index% "`t" ; attach stored index
   t .= "`n"                    ; row is complete
}
MsgBox %t%                      ; show output


Edit 20090620: minor simplifications


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Anagrams
PostPosted: June 20th, 2009, 2:33 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Anagrams:
Code:
MsgBox % anagrams("able")

anagrams(word) {
   Static dict
   IfEqual dict,, FileRead dict, unixdict.txt ; file in the script directory
   w := sort(word)
   Loop Parse, dict, `n, `r
      If (w = sort(A_LoopField))
         t .= A_LoopField "`n"
   Return t
}

sort(word) {
   a := RegExReplace(word,".","$0`n")
   Sort a
   Return a
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], tidbit, tomoe_uehara and 10 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