Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2004, 00:00
taos's Avatar
taos taos is offline
The Art Of Silence
 
Join Date: Aug 2004
Location: In front of my screen
Posts: 580
Rept. Given: 65
Rept. Rcvd 54 Times in 19 Posts
Thanks Given: 69
Thanks Rcvd at 137 Times in 36 Posts
taos Reputation: 54
carac2 = carac2 + resultat[cpt3] ;
????
the original value of resultat[cpt3] is...?
You can try with simple values to test how it works.
Reply With Quote
  #2  
Old 11-25-2004, 00:50
Michel Michel is offline
Friend
 
Join Date: Sep 2004
Location: France
Posts: 66
Rept. Given: 2
Rept. Rcvd 6 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
Michel Reputation: 6
Don't you think the while-loop may become infinite ?

Nevertheless I sujest you, if you want reverse only few values, to write a bruteforce loop comparing the result with the value you want to reverse.
Reply With Quote
  #3  
Old 11-25-2004, 11:32
volodya
 
Posts: n/a

while(carac2!=0)
{
carac2 = carac2 + resultat[cpt3] ;
resultat[cpt3] = carac2 % 100 ;
carac2 = carac2 div 100 ;
cpt3++ ;
}


Are you sure you did it well?
carac2 = carac2 div 100 - I'm assuming I see the division, rigth? Then go study math - the division will never give you 0 (in the integers ring) - and you check for 0 in while loop - endless cycle.
Reply With Quote
  #4  
Old 11-25-2004, 16:06
dyn!o's Avatar
dyn!o dyn!o is offline
Friend
 
Join Date: Nov 2003
Location: Own mind
Posts: 214
Rept. Given: 1
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 8
Thanks Rcvd at 0 Times in 0 Posts
dyn!o Reputation: 1
Probably Djneo posted a strict PDL description than a real pseudo code logic (sorry, but the posted idea itsn't logic for me).

Personally I think the problem is not only in the last condition (while loop) but whole presented code. What about cpt3 and cpt4 values? They are actually doing nothing.

That's all from me in this thread since Startrek related problems are far too much for my poor brain .
Reply With Quote
  #5  
Old 11-25-2004, 18:02
Michel Michel is offline
Friend
 
Join Date: Sep 2004
Location: France
Posts: 66
Rept. Given: 2
Rept. Rcvd 6 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
Michel Reputation: 6
cpt3 and cpt4 are pointers.
cpt4 has no problems, but cpt3 well because of the while loop.
What's the upper limit of cpt3 ?

Last edited by Michel; 11-25-2004 at 20:16.
Reply With Quote
  #6  
Old 11-26-2004, 02:15
dyn!o's Avatar
dyn!o dyn!o is offline
Friend
 
Join Date: Nov 2003
Location: Own mind
Posts: 214
Rept. Given: 1
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 8
Thanks Rcvd at 0 Times in 0 Posts
dyn!o Reputation: 1
cpt3 and cpt3 don't play any role because cpt2 won't reach 0 value. If you ask what is the limit of cpt3 then it doesn't have any. It should be set to 0 on each "while" condition execution but the code is a little bit strange and it goes into endless loop.
Reply With Quote
  #7  
Old 11-26-2004, 22:56
Mkz Mkz is offline
Friend
 
Join Date: Jan 2002
Posts: 98
Rept. Given: 0
Rept. Rcvd 2 Times in 2 Posts
Thanks Given: 5
Thanks Rcvd at 25 Times in 17 Posts
Mkz Reputation: 2
Quote:
Originally Posted by volodya

while(carac2!=0)
{
carac2 = carac2 + resultat[cpt3] ; (1)
resultat[cpt3] = carac2 % 100 ; (2)
carac2 = carac2 div 100 ; (3)
cpt3++ ;
}


Are you sure you did it well?
carac2 = carac2 div 100 - I'm assuming I see the division, rigth? Then go study math - the division will never give you 0 (in the integers ring) - and you check for 0 in while loop - endless cycle.
There's something here I don't understand...
Let's assume carac2 enters the loop with 1000.
After line 1, let's say 1050.
Line 2 will produce 50, line 3 will produce 10.
In the second iteration, line 1 might give 67 (added 57 this time), line 2 = 57, line 3 = ..... 0.

Each iteration adds a (small) amount to carac2, then shifts it right by 2 decimal places, eventually resulting in 0. Does it not?
Reply With Quote
  #8  
Old 11-27-2004, 00:05
volodya
 
Posts: n/a
In the second iteration, line 1 might give 67 (added 57 this time), line 2 = 57, line 3 = ..... 0.

DAMN... DAMN... DAMN ONE MORE TIME. It is me who should go and study comp.sci. This is the integer arithmetic... Fuck.

OK,
carac2 = carac2 + resultat[cpt3] ; (1) - you say, for example, carac2 will be 67. OK. Fine.
Then:
resultat[cpt3] = carac2 % 100 ; (2)
the operation "%" in C/C++ is the same as mod in number theory.
So, 67 mod 100 = 67 - not 57 as you are trying to say if I understood you properly, of course...
Then:
carac2 = carac2 div 100 -> carac2 = 67/100 - this is normally not 0, of course, BUT this is computer arithmetic and the result is rounded up, so it will be floor(67/100) which is 0 indeed. So you are partially right and I'm wrong. My bad.
Reply With Quote
  #9  
Old 11-29-2004, 18:42
Mkz Mkz is offline
Friend
 
Join Date: Jan 2002
Posts: 98
Rept. Given: 0
Rept. Rcvd 2 Times in 2 Posts
Thanks Given: 5
Thanks Rcvd at 25 Times in 17 Posts
Mkz Reputation: 2
Of course line (2) will result in 67, my mistake
67 % 100 -> 67
67 / 100 -> 0 (integer)

Now one other strange thing in the algo - where do the "resultat[cpt3]" values come from?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help identify crypto The Old Pirate General Discussion 5 12-27-2014 04:15


All times are GMT +8. The time now is 20:09.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )