 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
new_user Guest
|
Posted: Sun Dec 20, 2009 11:00 am Post subject: Pascal's triangle |
|
|
Why my script "Pascal's triangle" work before 22 row
(INTEGER VALUE is 2 byte?)
That:
| Code: |
yyy:=1
ch:=1
Gui, Add, Text,, Value:
;Gui, Add, Text,, ======================================NNC:
;Gui, Add, Text,, ======================================KKC:
Gui, Add, Edit, vFirstName ym
;Gui, Add, Edit, vNNC
;Gui, Add, Edit, vKKC
Gui, Add, Button, default, OK
Gui, Show,, paremetrs of Pascal's triangle
return
gosub, rtrt
;*******************Calculation*********************
cc(kk,nn)
{
yyy := 1
ch := 1
;c
loop, %kk%
{
aindex++
yyy := aindex * yyy
;msgbox `n LOOP_1 `n **ch = %ch% `n yyy = %yyy% `n kk = %kk% `n nn = %nn% `n aindex = %aindex%
}
ch := yyy
;msgbox `n ALOOP_1 `n ch = %ch% `n yyy = %yyy% `n kk = %kk% `n nn = %nn% `n aindex = %aindex%
nk := nn - kk
aindex := 0
yyy := 1
loop, %nk%
{
aindex++
yyy := aindex * yyy
}
ch := ch * yyy
;msgbox `n ALOOP_2 `n ch = %ch% `n yyy = %yyy%
aindex := 0
yyy := 1
loop, %nn%
{
aindex++
yyy := aindex * yyy
}
;msgbox `n ALOOP_3 `n yyy = %yyy%
;EnvDiv, yyy, ch
ch := yyy / ch
ch := Round(ch,0)
;msgbox `n ALOOP_3_ `n ch = %ch% yyy = %yyy%
return ch
}
ButtonOK:
rtrt:
Gui, Submit
Gui, Destroy
;Loop, %ArrayCount%
yyy:=0
;tstrng =% "1 `n"
nnn+++
Loop, %FirstName%
{
kk := A_index - 1
nnn++
loop, %kk%
{
kkk := A_index
;tstrng =% tstrng . cc(kk,FirstName+1) . " "
;msgbox `n kk = %kk% `n nnn = %nnn% `n
tstrng =% tstrng . cc(kkk,nnn) . " "
;msgbox %tstrng%
}
tstrng =% tstrng . "1`n 1 "
yyy := A_index * yyy
;msgbox %yyy% `n %A_index%
}
;MyListBox = % "" . Arrayt%A_Index%
;msgbox yyy = %yyy%
;msgbox triangle - `n %tstrng%
yyy:=0
yyy:=cc(3,5)
;msgbox cc(3.5) - %yyy%
;msgbox,8192 , Pascal's triangle , %tstrng%
;yyy:=cc(KKC,NNC)
;msgbox cc - %yyy%
;Gui, Add, Text,+Center -Limit +ReadOnly, %tstrng%
Gui, Add, Edit, +center, %tstrng%
Gui +Resize
Gui +HScroll
Gui +VScroll
Gui, Show,, Pascal's triangle
return
Gui, Destroy
GuiClose:
Guiescape:
ExitApp
|
|
|
| Back to top |
|
 |
UncleScrooge
Joined: 14 Apr 2009 Posts: 75 Location: Italy
|
Posted: Sun Dec 20, 2009 1:38 pm Post subject: |
|
|
to me it goes negative after 20.. anyway:
you are overcoming integer handling capability, so you have to use a trick. You gotta keep yyy under control
Try this (I took the liberty to clean up a bit...):
| Code: | Gui, Add, Text,, Value:
Gui, Add, Edit, vFirstName ym
Gui, Add, Button, default, OK
Gui, Show,, paremetrs of Pascal's triangle
return
gosub, rtrt
;*******************Calculation*********************
cc(kk,nn)
{
yyy := 1.0 ; floating point and not integer
ch := 1
loop, %kk%
yyy := a_index * yyy
ch := yyy
nk := nn - kk
yyy := 1.0 ; floating point and not integer
loop, %nk%
yyy := a_index * yyy
ch := ch * yyy
yyy := 1.0 ; floating point and not integer
loop, %nn%
yyy := a_index * yyy
ch := Round(yyy // ch) ; back to integer
return ch
}
ButtonOK:
rtrt:
Gui, Submit
Gui, Destroy
yyy:=0
nnn+++
Loop, %FirstName%
{
kk := A_index - 1
nnn++
loop, %kk%
{
kkk := A_index
tstrng =% tstrng . cc(kkk,nnn) . " "
}
tstrng =% tstrng . "1`n 1 "
yyy := A_index * yyy
}
Gui, Add, Edit, +center, %tstrng%
Gui +Resize
Gui +HScroll
Gui +VScroll
Gui, Show,, Pascal's triangle
return
Gui, Destroy
GuiClose:
Guiescape:
ExitApp |
although at abt 30 it overcomes my screen width capability and I got a 1680x1050
PS: Integer is 8 bytes, largest unsigned integer: 0xFFFFFFFFFFFFFFFF ==> 18446744073709551615, now 20! (factorial of 20) is just inside (2432902008176640000) while 21! (51090942171709440000) breaks out of the ceiling... _________________ Intel Centrino @ 2.8GHz
4 GB RAM
WIN XP SP3 |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Dec 20, 2009 5:34 pm Post subject: |
|
|
Very good trick
Thanks!! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|