AutoHotkey Community

It is currently May 27th, 2012, 2:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 417 posts ]  Go to page Previous  1 ... 9, 10, 11, 12, 13, 14, 15 ... 28  Next
Author Message
 Post subject:
PostPosted: February 2nd, 2010, 5:33 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
some things that have been done but not posted:
Loading 3D Animated Data & OpenGL --> http://de.autohotkey.com/forum/viewtopic.php?t=3977
Mandelbrot --> http://www.autohotkey.com/forum/viewtopic.php?t=43429

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2010, 6:08 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
infogulch wrote:
I have issue with the current moving average code. The code itself is excellent; however, I think its not ideal for the purpose of rosettacode. Keeping static copies of the different values inside the function doesn't conform to the spirit of the objective imo, and is not universal (i.e. it couldn't be used in a library).
Well, you don't even need a function:
Code:
avg := i := 0
MsgBox % avg += (3-avg)/++i
MsgBox % avg += (8-avg)/++i
MsgBox % avg += (16-avg)/++i
MsgBox % avg += (53-avg)/++i


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2010, 6:24 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Laszlo wrote:
Well, you don't even need a function:
You are absolutely correct.
...

Actually:
Quote:
Create a stateful function/class/instance that takes a number as argument and returns a simple moving average of its arguments so far.
Note that the moving average has a period and numbers beyond the period must be dropped from the calculation of the average.

I didn't read the goal correctly, so I misinterpreted moving average for cumulative average. I don't have any issues anymore, sorry. :P

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 6th, 2010, 6:17 pm 
Offline

Joined: February 6th, 2010, 5:17 pm
Posts: 57
Print a Multiplication Table
Code:
SendMode, Input
Run, Notepad.exe,, Max
WinWaitActive, ahk_class Notepad
size = 12
x = 0
y = -1
Loop, % size + 2 {
   If (y = -1)
      Send, % format("X|")
   Else If (y = 0)
      Send, % format("|", "-")
   Else Send, % format(y . "|")
   Loop, %size% {
      x += 1
      If (y = -1)
         Send, % format(x)
      Else If (y = 0)
         Send, % format("", "-")
      Else If (x < y)
         Send, % format("")
      Else Send, % format(x * y)
   }
x = 0
y += 1
Send, {Enter}
}

format(str, fill = " ") {
   global size
   While, (StrLen(str) <= StrLen(size * size + 1))
      str := fill . str
   Return, str
}

I was trying to make the table look like the Perl example, but when I tried to put a "+" where the two lines intersected, my format() function apparently interpreted it as an operator instead of just a character in a string. I haven't figured out how to fix that yet, but a pipe will work. It works fine for the required 12x12 table, but turning it up to about 32x32 can cause some weird things to happen (looks like possibly a buffer getting filled up?). I've also considered making a version to display it in a AutoHotkey GUI and possibly another one to make it put the numbers into OpenOffice Calc.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2010, 7:47 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Nice! You can write it little shorter:
Code:
size = 24
Loop % size + 2 {
   t .= (y:=A_Index-2)<0 ? format("X|") : y=0 ? "`n" format("+", "-") : "`n" format(y . "|")
   Loop %size%
      t .= y<0 ? format(A_Index) : y=0 ? format("", "-") : A_Index<y ? format("") : format(A_Index * y)
}

Gui Font, s10, Courier New
Gui Add, Text,,%t%
Gui Show

format(str, fill = " ") {
   Global size
   VarSetCapacity(f, n:=StrLen(size*size)+1-StrLen(str), Asc(fill))
   Return SubStr(f,1,n) str
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: bitmap storage tasks
PostPosted: February 9th, 2010, 3:05 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
I have fixed basic bitmap storage, read a ppm, and write a ppm using AutoHotkey_L45


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Root Mean Square
PostPosted: April 17th, 2010, 12:08 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
I have contributed the following (so far unsolved task):
Code:
MsgBox, % RMS(1, 10)

RMS(a, b) { ; Root Mean Square
    n := b - a + 1
    Loop, %n%
        Sum += (a + A_Index - 1) * (a + A_Index - 1)
    Return, Sqrt(Sum / n)
}

As this is my first contribution to Rosetta, I would appreciate if anybody was kind enough to check if it's OK, please.
Here is the link: Averages/Root mean square

Wolf

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 1:52 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
And another one: Take notes on the command line
Code:
Notes := "Notes.txt"

If 0 = 0 ; no arguments
{
    If FileExist(Notes) {
        FileRead, Content, %Notes%
        MsgBox, %Content%
    } Else
        MsgBox, %Notes% does not exist
    Goto, EOF
}

; date and time, colon, newline (CRLF), tab
Date := A_DD "/" A_MM "/" A_YYYY
Time := A_Hour ":" A_Min ":" A_Sec "." A_MSec
FileAppend, %Date% %Time%:`r`n%A_Tab%, %Notes%

; command line parameters, trailing newline (CRLF)
Loop, %0%
    FileAppend, % %A_Index% " ", %Notes%
FileAppend, `r`n, %Notes%

EOF:

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 3:00 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Here's an alternative.
Code:
If 0 = 0  ;no arguments
{
 Run, %comspec% /k type Notes.txt
 ExitApp
}
FormatTime, var
var .= "`n" A_Tab
Loop, %0%
 var .= %A_Index% A_Space
FileAppend, %var%`n, Notes.txt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 3:04 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
And another one: Averages/Pythagorean means
Code:
A := ArithmeticMean(1, 10)
G := GeometricMean(1, 10)
H := HarmonicMean(1, 10)

If G Between %H% And %A%
    Result := "True"
Else
    Result := "False"

MsgBox, %A%`n%G%`n%H%`n%Result%

ArithmeticMean(a, b) {
    n := b - a + 1
    Loop, %n%
        Sum += (a + A_Index - 1)
    Return, Sum / n
}

GeometricMean(a, b) {
    n := b - a + 1
    Prod := 1
    Loop, %n%
        Prod *= (a + A_Index - 1)
    Return, Prod ** (1 / n)
}

HarmonicMean(a, b) {
    n := b - a + 1
    Loop, %n%
        Sum += 1 / (a + A_Index - 1)
    Return, n / Sum
}

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 3:26 am 
Offline

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
@jaco0646: Nice one!

Wolf

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 4:39 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
RMS: wolf_II's code is correct, but we can make it a little more general. This version computes the RMS of 1..10 arbitrary numbers:
Code:
MsgBox % RMS(1) ; 1
MsgBox % RMS(3,4) ; 3.535534
MsgBox % RMS(1,2,3,4,5,6,7,8,9,10) ; 6.204837

RMS(a0,a1="",a2="",a3="",a4="",a5="",a6="",a7="",a8="",a9="") { ; Root Mean Square of 1..10 arguments
    s := a0*a0
    Loop 10
       If (a%A_Index% = "")
          Return Sqrt(s/A_Index)
       Else s += a%A_Index% ** 2
}
Another version computes the RMS of a comma separated list of numbers
Code:
MsgBox % RMS("1") ; 1
MsgBox % RMS("3,4") ; 3.535534
MsgBox % RMS("1,2,3,4,5,6,7,8,9,10") ; 6.204837

RMS(a) { ; Root Mean Square of list of numbers
    s := 0, n := 0
    Loop Parse, a, `,
       s += A_LoopField ** 2, n++
    Return Sqrt(s/n)
}
You can also use AHK arrays, and pass the array name as a parameter, but it is not nice, because the array has to be global and must not conflict with local variables.

The same ideas work for the other mean variants, too.


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

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
@Laszlo:
Laszlo wrote:
wolf_II's code is correct
Thank you for checking.

rosettacode.org wrote:
Compute the Root mean square of the numbers 1..10.
rosettacode.org also wrote:
Compute all three of the Pythagorean means of the set of integers 1 through 10.

I consider at present my published code sufficiently generalized for the given task. I will of course change it, if requested. I am nevertheless grateful for the comments so far, as I can learn from them.

I like especially the elegance of jaco0646's version that uses FileAppend only once. But I prefer MsgBox over a console popping up. While I am at it, let me say that I thought this would be a good place to show that AHK has got a GOTO command, although it is the first time I have ever used it.

I have done the following minor change to RMS:
Code:
Sum += (a + A_Index - 1) * (a + A_Index - 1) ; previously (performance)
Sum += (a + A_Index - 1) ** 2                ; now        (elegance)

Wolf

_________________
Wolf

Schön wär's, wenn's schön wär!


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

Joined: October 18th, 2007, 9:21 pm
Posts: 343
Location: Saarland, Germany
@All:

From the list AutoHotkey examples needing attention I found Fork (not working on my PC, author unknown to me):
Code:
instancenum = %1%+1
MsgBox, 4, Fork Process, %instancenum% number: run another?
IfMsgBox, Yes
   Run, %A_ScriptFullName% %instancenum%
ExitApp

I want to replace with:
Code:
If 0 = 0 ; no arguments
    InstanceNum = 1
Else
    InstanceNum = %1%

MsgBox, 4, Fork Process, Number %InstanceNum%:  Run another?
InstanceNum += 1
IfMsgBox, Yes
    Run, "%A_AhkPath%" "%A_ScriptFullPath%" %InstanceNum%


I herewith put my suggestion up for discussion, if you please.

Wolf

_________________
Wolf

Schön wär's, wenn's schön wär!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2010, 7:08 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
wolf_II wrote:
my published code sufficiently generalized for the given task
My suggestions make the function generally useful. There is a simple closed form expression for the RMS of the integers from b to a, so there is no need for a loop, but you might need to compute the RMS of some measurement results.
Code:
a := 10, b := 1 ; RMS of integers from b to a
MsgBox % Sqrt((a*(1+a)*(1+a+a)-(b-1)*b*(b+b-1))/6/(a-b+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 ... 9, 10, 11, 12, 13, 14, 15 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 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