AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Challenge: translate rosettacode - Was promoting autohotkey
Goto page Previous  1, 2, 3, 4, 5, 6 ... 10, 11, 12  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Thu Jun 18, 2009 5:18 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Thu Jun 18, 2009 10:47 pm    Post subject: Monte Carlo Simulation for pi Reply with quote

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
}
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 12:13 pm    Post subject: Reply with quote

Am going through the posting so far to cleanup syntax-wise (indentation and casing). It looks like the syntax-coloring for AutoHotkey stopped working. Confused
Back to top
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 1:26 pm    Post subject: Reply with quote

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
Back to top
tinku99



Joined: 03 Aug 2007
Posts: 309
Location: Houston, TX

PostPosted: Fri Jun 19, 2009 2:11 pm    Post subject: syntax and casing Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Fri Jun 19, 2009 3:17 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 3:48 pm    Post subject: Reply with quote

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
Back to top
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 4:03 pm    Post subject: Reply with quote

How about a "disclaimer" like this one? http://www.rosettacode.org/wiki/FizzBuzz#AutoHotkey
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Fri Jun 19, 2009 4:06 pm    Post subject: Reply with quote

hmm, yeah i think that would be good for most ahk scripts posted on RosettaCode. But I lowercased mine anyway. xD
_________________

Scripts
- License
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Fri Jun 19, 2009 4:08 pm    Post subject: Mode of lists of numbers Reply with quote

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.
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 4:14 pm    Post subject: Reply with quote

@infogulch: I added your code.
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Fri Jun 19, 2009 4:16 pm    Post subject: Reply with quote

thanks, n-l-i-d
Very Happy

Edit: what about the Tasks Not Implemented in AutoHotkey ?
_________________

Scripts
- License
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4515
Location: Boulder, CO

PostPosted: Fri Jun 19, 2009 4:55 pm    Post subject: Reply with quote

infogulch wrote:
what about the Tasks Not Implemented in AutoHotkey ?
Can someone post my functions, too?
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Fri Jun 19, 2009 5:10 pm    Post subject: Reply with quote

I added all of Laszlo's functions, apart from the MontePi, couldn't find that one... Confused
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 378

PostPosted: Fri Jun 19, 2009 5:11 pm    Post subject: Reply with quote

Heh, we're gonna need a full-time Rosetta Code updater just to add stuff posted here. Wink
I looked at editing them, but couldn't figure out how to do it. Sad

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 Fri Jun 19, 2009 5:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6 ... 10, 11, 12  Next
Page 5 of 12

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group