Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Strange problem with algorithm
PostPosted: Wed Aug 13, 2008 9:26 pm 
Forum God
User avatar
Offline

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
 Profile  
 
 Post subject: Re: Strange problem with algorithm
PostPosted: Wed Aug 13, 2008 10:27 pm 
Advanced Member
User avatar
Offline

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

Image Image
Mad props to Verfo for the sig, ty!


Top
 Profile  
 
 Post subject: Re: Strange problem with algorithm
PostPosted: Wed Aug 13, 2008 11:40 pm 
Loyal Member
User avatar
Offline

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?

_________________
Image
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
 Profile  
 
 Post subject: Re: Strange problem with algorithm
PostPosted: Wed Aug 13, 2008 11:42 pm 
Casual Member
User avatar
Offline

Joined: Jul 2008
Posts: 55
Location: Work..
Image

_________________
Image
Click here to rub my wiener!
Free Sex In Return!


Top
 Profile  
 
 Post subject: Re: Strange problem with algorithm
PostPosted: Wed Aug 13, 2008 11:44 pm 
Advanced Member
User avatar
Offline

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

Image Image
Mad props to Verfo for the sig, ty!


Top
 Profile  
 
 Post subject: Re: Strange problem with algorithm
PostPosted: Thu Aug 14, 2008 12:28 am 
Ex-Staff
User avatar
Offline

Joined: Jan 2006
Posts: 2639
Location: 4 hour jack sessions with stallowned
icealya pic > silo pic

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group