|
|
Silkroad Online
|
|
Silkroad Forums
|
|
Affiliates
|



|
|
View unanswered posts | View active topics
|
Page 1 of 1
|
[ 6 posts ] |
|
| Author |
Message |
|
NuclearSilo
|
Post subject: Strange problem with algorithm Posted: Wed Aug 13, 2008 9:26 pm |
|
| Forum God |
 |
 |
Joined: Aug 2006 Posts: 8834 Location: Age of Wushu
|
I made a script to reduce a fraction using PGCD method (in english GCD, greatest common divisor), basing on this: PGCD(a,b) = PGCD(b,a-b) Quote: $text = InputBox("","") $array = _StringSplit($text,"/") $a = $array[0] $b = $array[1] MsgBox(0,"","pgcd de " & $a & " et " & $b & " est") If $a = $b Then MsgBox(0,"","res = 1") EndIf
While $a <> $b If $a > $b Then $a = $a - $b Else $b = $b - $a EndIf WEnd $pgcd = $a MsgBox(0,"",$a) $array[0] /= $a $array[1] /= $b $res = $array[0] / $array[1] If IsInt($res) Then MsgBox(0,"",$res) Else MsgBox(0,"",$array[0] & "/" & $array[1]) EndIf The main code is in bold. When i execute it, the result is like this: 4/8 -> 1/2 10/5 -> 2 24/30 -> 4/5 But the strange thing is if i divide something (less than 100) to 100, the script will be an endless loop, trapped inside the bold area. And when comepare it says that number is greater than 100. Any idea? 
_________________ Playing Age of Wushu, dota IMBA
|
|
| Top |
|
 |
|
CloudStrider
|
Post subject: Re: Strange problem with algorithm Posted: Wed Aug 13, 2008 10:27 pm |
|
| Advanced Member |
 |
 |
Joined: Jul 2008 Posts: 2125 Location: Away
|
NuclearSilo wrote: I made a script to reduce a fraction using PGCD method (in english GCD, greatest common divisor), basing on this: PGCD(a,b) = PGCD(b,a-b) Quote: $text = InputBox("","") $array = _StringSplit($text,"/") $a = $array[0] $b = $array[1] MsgBox(0,"","pgcd de " & $a & " et " & $b & " est") If $a = $b Then MsgBox(0,"","res = 1") EndIf
While $a <> $b If $a > $b Then $a = $a - $b Else $b = $b - $a EndIf WEnd $pgcd = $a MsgBox(0,"",$a) $array[0] /= $a $array[1] /= $b $res = $array[0] / $array[1] If IsInt($res) Then MsgBox(0,"",$res) Else MsgBox(0,"",$array[0] & "/" & $array[1]) EndIf The main code is in bold. When i execute it, the result is like this: 4/8 -> 1/2 10/5 -> 2 24/30 -> 4/5 But the strange thing is if i divide something (less than 100) to 100, the script will be an endless loop, trapped inside the bold area. And when comepare it says that number is greater than 100. Any idea?  I suck at that, but good luck Silo.
_________________
penfold1992 wrote: durka durka muhammad gihad allah 10k plys. thats all i hear :S
 Mad props to Verfo for the sig, ty!
|
|
| Top |
|
 |
|
LaloHao
|
Post subject: Re: Strange problem with algorithm Posted: Wed Aug 13, 2008 11:40 pm |
|
| Loyal Member |
 |
 |
Joined: Nov 2007 Posts: 1987 Location: Mexico
|
Quote: $text = InputBox("","") $array = _StringSplit($text,"/") $a = $array[0] $b = $array[1] MsgBox(0,"","pgcd de " & $a & " et " & $b & " est") If $a = $b Then MsgBox(0,"","res = 1") EndIf
While $a <> $b If $a > $b Then $a = $a - $b Else $b = $b - $a EndIf WEnd $pgcd = $a MsgBox(0,"",$a) $array[0] /= $a $array[1] /= $b $res = $array[0] / $array[1] If IsInt($res) Then MsgBox(0,"",$res) Else MsgBox(0,"",$array[0] & "/" & $array[1]) EndIf Try Code: $text = InputBox("","") $array = _StringSplit($text,"/") $a = $array[0] $b = $array[1] MsgBox(0,"","pgcd de " & $a & " et " & $b & " est: ")
While ($a % $b) != 0 $c = $b; $b = $a % $b; $a = $c; WEnd MsgBox(0,"",$b) Dont know if it'll work. BTW what language is that? AutoIT?
_________________
 Visit the Artist Corner to browse my drawings
Last edited by LaloHao on Thu Aug 14, 2008 12:01 am, edited 1 time in total.
|
|
| Top |
|
 |
|
Motorola
|
Post subject: Re: Strange problem with algorithm Posted: Wed Aug 13, 2008 11:42 pm |
|
| Casual Member |
 |
 |
Joined: Jul 2008 Posts: 55 Location: Work..
|
|
| Top |
|
 |
|
CloudStrider
|
Post subject: Re: Strange problem with algorithm Posted: Wed Aug 13, 2008 11:44 pm |
|
| Advanced Member |
 |
 |
Joined: Jul 2008 Posts: 2125 Location: Away
|
|
LOL! LOL!
Motor man that was some funny stuff, That gets picture of the year in my books, except maybe some pictures in the Hot or Not thread.
_________________
penfold1992 wrote: durka durka muhammad gihad allah 10k plys. thats all i hear :S
 Mad props to Verfo for the sig, ty!
|
|
| Top |
|
 |
|
PB_and_J
|
Post subject: Re: Strange problem with algorithm Posted: Thu Aug 14, 2008 12:28 am |
|
| Ex-Staff |
 |
 |
Joined: Jan 2006 Posts: 2639 Location: 4 hour jack sessions with stallowned
|
|
icealya pic > silo pic
_________________
|
|
| Top |
|
 |
|
Page 1 of 1
|
[ 6 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 20 guests |
|
You cannot post new topics in this forum You cannot 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
|
|