AutoHotkey Community

It is currently May 26th, 2012, 8:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12 ... 28  Next
Author Message
 Post subject: Re: Moving Average
PostPosted: June 23rd, 2009, 5:48 am 
Laszlo wrote:
Last N rather than all. wrote:
Unfortunately you need to average the last N rather than all the numbers. - See other entries on the R.C. site.
rosettacode wrote:
function/class/instance that takes a number as argument and returns a simple moving average of its arguments so far


Ta! :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 8:38 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
I feel Scripts & Functions suits this topic..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 3:22 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
I was set against that idea a few weeks ago when tinku99 asked me...
I wrote:
S&F is a showcase for completed work and discussion of that work. The Rosetta thread is a combination of philosophical debate and work in progress. Its intended showcase is the Rosetta code wiki.
...but in light of Laszlo's recent activity there is an awful lot of working code here. It would seem my argument no longer holds water. SKAN, if you believe it belongs in S&F, I don't object.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 4:37 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I think this thread should remain here since, as you noted, its purpose is not directly related to that forum. I think it would be better to create a separate thread in S&F which hosts the finished RosettaCode functions.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 6:00 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
I oppose redundant posting of code, especially within the forums. From my correspondence with tinku99...
I wrote:
In my opinion, posting code of completed tasks in the Scripts & Functions forum is redundant. The purpose of completing these tasks is to post them on Rosetta. Copying each one to Scripts & Functions clutters the forum.
The same scripts should definitely not be posted here in General Chat and also in S&F.

I do believe the Rosetta codes need to be promoted as much as possible, but not by duplicating every script. Several people have done an amazing job with this project; and it was a brilliant idea by tinku99 to begin with.

:idea: I have thought for some time that something should be done with Jon's "Catalogue of Scripts" sticky topic in the S&F forum. Since Jon moved his catalogue to the wiki years ago, the only purpose of that thread is to redirect people to the wiki. I propose to do the same with that sticky topic as Titan did with the AutoHotkey.net sticky: cut it down to one post to inform users of the many working code examples on the Wiki and on Rosetta code. It should serve as an advertisement so to speak.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 7:00 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
jaco0646 wrote:
I oppose redundant posting of code, especially within the forums...the same scripts should definitely not be posted here in General Chat and also in S&F.


While I agree that redundancy is typically bad form, this thread has already constructed itself in a manner that is not conducive to the spirit of threads you would typically find in S&F so simply moving the thread would equally be bad form, IMO (danged if we do, danged if we don't).

Here's my thought along the lines of your idea: Make a sticky note in S&F that redirects to our section of the Rosetta Code Wiki and the original thread, like this:

Wiki Sticky wrote:
AutoHotKey members are participating in a programming project hosted by Rosetta Code, whose idea is "to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one language in learning another." Please go visit AutoHotKey's main page, which also contains the list of programming tasks completed in the AutoHotKey language. To see tasks which have not yet been completed, visit AutoHotKey's unimplemented task page.

If you would like to participate with other AutoHotKey members in completing some of our unimplemented tasks or on other items pertaining to the Rosetta Code project, please visit the Rosetta Code challenge thread in the General Forum.


That way the sticky can present the information with a more reader-friendly logic that the thread itself simply doesn't have while leaving the thread in its original forum and avoiding code rendundancy.

:?:

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 7:59 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
jaco0646 wrote:
in light of Laszlo's recent activity there is an awful lot of working code here. It would seem my argument no longer holds water. SKAN, if you believe it belongs in S&F, I don't object.


:(
I could not login for past few hours owing to some phpBB Critical Error and so I was unable to respond.. IMHO, the gems from Laszlo always belong to Scripts and Functions. Since sinkfaze feels otherwise, I will remember to bump and move this topic to Scripts and Functions when it fades out to the second page.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 9:36 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
@sinkfaze
I agree with everything in your latest post. That's what I propose to do.


SKAN wrote:
...the gems from Laszlo always belong to Scripts and Functions.
While I certainly agree with this statement, as sinkfaze alluded: this thread is a mess, and contains as much material that doesn't belong in S&F as useful code.

Also, even if this thread is moved to S&F, unless it is made sticky (which I strongly oppose: five stickies in one forum is more than enough) this thread won't stay visible there either. I believe that combining an explanation of Rosetta code with Jon's first post in the Catalogue thread is the most consistent and productive option. The revised thread could then be titled something like, "AutoHotkey Wiki + RosettaCode Challenges."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2009, 9:50 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
jaco0646 wrote:
Also, even if this thread is moved to S&F, unless it is made sticky ... this thread won't stay visible there either.


That was not the point. People tend to NOT CLICK General Chat topic in Forum search results. As for me, I always confine my search to "Scripts & Functions" and/or "Ask for Help"

jaco0646 wrote:
That's what I propose to do.


Anyways! I have no problem with that..


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Shell sort
PostPosted: June 23rd, 2009, 11:56 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Shell sort of comma separated lists:
Code:
MsgBox % ShellSort("")
MsgBox % ShellSort("xxx")
MsgBox % ShellSort("3,2,1")
MsgBox % ShellSort("dog,000000,xx,cat,pile,abcde,1,cat,zz,xx,z")
MsgBox % ShellSort("12,11,10,9,8,4,5,6,7,3,2,1,10,13,14,15,19,17,18,16,20,10")

ShellSort(var) {                         ; SORT COMMA SEPARATED LIST
   StringSplit a, var, `,                ; make array (length = a0)
   inc := a0
   While inc:=round(inc/2.2)             ; geometric gap sequence
      Loop % a0-inc {                    ; insertion sort:
         i := A_Index+inc, t := a%i%, j := i, k := j-inc
         While j > inc && a%k% > t
            a%j% := a%k%, j := k, k -= inc
         a%j% := t
      }
   Loop % a0                             ; construct string from sorted array
      s .= "," . a%A_Index%
   Return SubStr(s,2)                    ; drop leading comma
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 12:01 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
SKAN wrote:
I have no problem with that.
Awesome, I've done it.

SKAN wrote:
That was not the point.
You could split this topic by individually selecting all of the useful code posts and moving them to a new Scripts & Functions thread, leaving the discussion posts behind. :idea:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: FIFO
PostPosted: June 24th, 2009, 1:08 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
FIFO's, or stacks can be implemented via global arrays. Their names are passed to the stack handling functions, so many stacks can be used at any time:
Code:
push("st",2),push("st",4)   ; TEST: push 2 and 4 onto stack named "st"
While !empty("st")          ; Repeat until stack is not empty
   MsgBox % pop("st")       ; Print popped values (4, 2)
MsgBox % pop("st")          ; Empty
MsgBox %ErrorLevel%         ; ErrorLevel = 1: popped too much

push(stack,x) {             ; push x onto stack named "stack"
   Local _ ;
   _ :=  %stack%0 := %stack%0="" ? 1 : %stack%0+1
   %stack%%_% := x
}
pop(stack) {                ; pop value from stack named "stack"
   Local _ ;
   _ := %stack%0
   If (_ < 1)
      Return "", ErrorLevel := 1
   Return %stack%%_%,  %stack%0 := _-1
}
empty(stack) {              ; check if stack named "stack" is empty
   Global
   Return %stack%0<1
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Knuth shuffle
PostPosted: June 24th, 2009, 1:38 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The function for the Knuth shuffle creates the array internally from a list, and returns the shuffled list, for easy display:
Code:
MsgBox % shuffle("1,2,3,4,5,6,7,8,9")
MsgBox % shuffle("1,2,3,4,5,6,7,8,9")

shuffle(list) {                          ; shuffle comma separated list, converted to array
   StringSplit a, list, `,               ; make array (length = a0)
   Loop % a0-1 {
      Random i, A_Index, a0              ; swap item 1,2... with a random item to the right of it
      t := a%i%, a%i% := a%A_Index%, a%A_Index% := t
   }
   Loop % a0                             ; construct string from sorted array
      s .= "," . a%A_Index%
   Return SubStr(s,2)                    ; drop leading comma
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 24th, 2009, 2:00 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
A short recursive (slow) function for the Longest Common Subsequence task (based on the Python code):
Code:
MsgBox % lcs("1234","24") ; 24
MsgBox % lcs("thisisatest","testing123testing") ; tsitest


lcs(a,b) { ; Recursive Longest Common Subsequence of strings
    Return a="" || b="" ? "" : Asc(a)=Asc(b) ? SubStr(a,1,1) lcs(SubStr(a,2),SubStr(b,2))
    : StrLen(u:=lcs(a,SubStr(b,2))) > StrLen(v:=lcs(SubStr(a,2),b)) ? u : v
}

The following function uses dynamic programming, and it is much faster. It is based on the Java program posted to rosettacode:
Code:
lcs(a,b) { ; Longest Common Subsequence of strings, using Dynamic Programming
   Loop % StrLen(a)+2 {                          ; Initialize
      i := A_Index-1
      Loop % StrLen(b)+2
         j := A_Index-1, len%i%_%j% := 0
   }
   Loop Parse, a                                 ; scan a
   {
      i := A_Index, i1 := i+1, x := A_LoopField
      Loop Parse, b                              ; scan b
      {
         j := A_Index, j1 := j+1, y := A_LoopField
         len%i1%_%j1% := x=y ? len%i%_%j% + 1
         : (u:=len%i1%_%j%) > (v:=len%i%_%j1%) ? u : v
      }
   }
   x := StrLen(a)+1, y := StrLen(b)+1
   While x*y {                                   ; construct solution from lengths
     x1 := x-1, y1 := y-1
     If (len%x%_%y% = len%x1%_%y%)
         x := x1
     Else If  (len%x%_%y% = len%x%_%y1%)
         y := y1
     Else
         x := x1, y := y1, t := SubStr(a,x,1) t
   }
   Return t
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 24th, 2009, 3:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
We can find all Non Continuous Subsequences by selecting those 01 sequences, which do not consist of only one block of 1’s. It is very easy with regular expressions. At the end we have to translate 1’s to the sequence entries corresponding to their position:
Code:
n := 4                                               ; sequence length
Loop % (1<<n) - 1 {                                  ; try all 0-1 candidate sequences
   If !RegExMatch(b:=ToBin(A_Index,n),"^0*1*0*$") {  ; drop continuous subsequences
      Loop Parse, b
         t .= A_LoopField ? A_Index " " : ""         ; position -> number
      t .= "`n"                                      ; new sequences in new lines
   }
}
MsgBox % t

ToBin(n,W=16) {  ; LS W-bits of Binary representation of n
   Return W=1 ? n&1 : ToBin(n>>1,W-1) . n&1
}


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 ... 6, 7, 8, 9, 10, 11, 12 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Ragnar and 2 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