AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 28  Next
Author Message
 Post subject:
PostPosted: June 18th, 2009, 5:18 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I meant, buggy codes are posted in other languages. The 99 bottles of beer challenge provides several examples. If you find my functions acceptable, post it, with a url to here.

Code:
SubStr("6-----4---2-4---2-4---6-----2",Mod(k,30),1)
This is added to k to get the next trial divisor, not divisible by 2, 3 or 5, as the comment next to function header tells. It is very easy to verify. Start with e.g. k = 7. The SubStr expression tells that the next divisor is 4 larger, k = 11. For k = 11 the SubStr expression tells the next divisor is 2 larger, 13, and so on. We get into a cycle of length 8, so we don’t need entries for never encountered k (mod 30) values, indicated by “-“ in the haystack.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 18th, 2009, 10:47 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Count how many of n random throws in a square falls into an inscribed circle. It yields an estimate of pi.
Code:
MsgBox % MontePi(10000)   ; 3.154400
MsgBox % MontePi(100000)  ; 3.142040
MsgBox % MontePi(1000000) ; 3.142096

MontePi(n) {
   Loop %n% {
      Random x, -1, 1.0
      Random y, -1, 1.0
      p += x*x+y*y < 1
   }
   Return 4*p/n
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 12:13 pm 
Am going through the posting so far to cleanup syntax-wise (indentation and casing). It looks like the syntax-coloring for AutoHotkey stopped working. :?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 1:26 pm 
Ok, one request: if you post something to the Rosetta Code site, please use proper indentation and casing.

Quote:
msgbox -> MsgBox
return -> Return
if -> If
while -> While
instr() -> InStr()

etcet...


And please use an indentation of 2 spaces per "tab"

TY


Report this post
Top
  
Reply with quote  
 Post subject: syntax and casing
PostPosted: June 19th, 2009, 2:11 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Thanks for cleaning up the casing and indentation.

Please add autohotkey as a language on your user page, see first post for instructions.

We could write a little robot to fix the casing and indentation...
I will try to get the highlighting back online, once i update the lexer a little.


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

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Hi,

I created an ambiguous function that matches RosettaCode's AMB challenge. But I don't know how to add it to the page. :-/

http://www.autohotkey.com/forum/viewtopic.php?p=275987#275987

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 3:48 pm 
Well, it may not equal the examples of most other languages (they are usually lowercase), but it does confirm with the documentation casing. The fact that AutoHotkey is case-insensitive and generally very "forgiving" could be explained on the language page.

I suggest lowercase for variables and proper mixed case for keywords. I also suggest using descriptive variable names, even if the tendency is to create short code, I think the site is a proper outlet to clarify what is going on in the code, not necessarily provide the fastest and most condensed code. One could add variations if applicable, sure, but per default please some consistency.

To make the syntax-coloring stand out more, it helps to avoid using variable names that are also AutoHotkey keywords.

Just my 2 €cts


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 4:03 pm 
How about a "disclaimer" like this one? http://www.rosettacode.org/wiki/FizzBuzz#AutoHotkey


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 4:06 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
hmm, yeah i think that would be good for most ahk scripts posted on RosettaCode. But I lowercased mine anyway. xD

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Mode of lists of numbers
PostPosted: June 19th, 2009, 4:08 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Mode of a list of numbers is the number, which occurs the most frequently in the list. This function sorts and scans the list once to find the Mode. The delimiter can be given in the second parameter, default to space.
Code:
MsgBox % Mode("")
MsgBox % Mode("1 2 3")
MsgBox % Mode("1 2 0 3 0.0")
MsgBox % Mode("0.1 2.2 -0.1 0.22e1 2.20 0.1")

Mode(a, d=" ") { ; the number that occurs most frequently in a list delimited by d (space)
   Sort a, ND%d%
   Loop Parse, a, %d%
      If (V != A_LoopField) {
         If (Ct > MxCt)
            MxV := V, MxCt := Ct
         V := A_LoopField, Ct := 1
      }
      Else Ct++
   Return Ct>MxCt ? V : MxV
}

Another approach was to convert the numbers to variable names (e.g. by appending “v” and replacing “.” with “_”), and count in these variables the number of time the corresponding value occurs. We’d have difficulties with equal numbers written differently, like 10, 10.0, 1.0e1, therefore the list has to be first scanned and the numbers converted to uniform notation, e.g. with “SetFormat FastFloat, 0.16e” and adding 0 to each, making the function slow and complicated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 4:14 pm 
@infogulch: I added your code.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 4:16 pm 
Online

Joined: March 27th, 2008, 2:14 pm
Posts: 700
thanks, n-l-i-d
:D

Edit: what about the Tasks Not Implemented in AutoHotkey ?

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 4:55 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
infogulch wrote:
Can someone post my functions, too?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 5:10 pm 
I added all of Laszlo's functions, apart from the MontePi, couldn't find that one... :?


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

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Heh, we're gonna need a full-time Rosetta Code updater just to add stuff posted here. ;)
I looked at editing them, but couldn't figure out how to do it. :(

Here's another one: Forward Difference
Code:
list := "90,47,58,29,22,32,55,5,55,73"

msgbox % forwardDiff(list, 9, True) ; returns every step on a new line
msgbox % forwardDiff(list, 5) ; returns only the final result

forwardDiff(list, depth=1, append = False, sep=",")
{
   Loop, Parse, list, % sep
   {
      If (lastVal != "")
         newList .= A_LoopField - lastVal . sep
      lastVal := A_LoopField
   }
   newList := SubStr(newList, 1, -1)
   If ((depth -= 1) && newList != "")
      return (append ? newList "`n" : "" ) forwardDiff(newList, depth, sep, append)
   return newList
}


I tried to format it nice, but it can be reformatted.

Edit: oh, and what about Laszlo's MD5?

_________________
Scripts - License


Last edited by infogulch on June 19th, 2009, 5:15 pm, edited 1 time in total.

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, 2, 3, 4, 5, 6, 7, 8 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: tidbit, tomoe_uehara and 6 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