Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 generating least positive integer (mod function) help
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
apomb




PostPosted: Thu Apr 08, 2010 5:18 pm   Post subject: RE:generating least positive integer (mod function) help

Sorry, ya TheGuardian is right...

Thank you TheGuardian for clearing that up for me.
Sponsor
Sponsor
Sponsor
sponsor
XXX111




PostPosted: Thu Apr 08, 2010 6:35 pm   Post subject: Re: generating least positive integer (mod function) help

Thanks apomb and guardian for your excellent help
Brightguy




PostPosted: Thu Apr 08, 2010 7:31 pm   Post subject: Re: generating least positive integer (mod function) help

XXX111 @ Thu Apr 08, 2010 4:44 pm wrote:
I almost have the code completed except for one small problem. The program now generates all the possible integers, but is there any way to stop after the first one (also the lowest) and have it display?

Well, actually, you shouldn't have to stop. Since 7,8,9 are coprime (they share no prime divisors) the solution between 1 and 504 will be unique. Remember you want an x that satisfies each constraint, not just one.
Zren




PostPosted: Thu Apr 08, 2010 8:24 pm   Post subject: Re: generating least positive integer (mod function) help

Exit works for FOR loops just as good as normal loops.

Turing:
var n : int := 1
loop
    exit when %Insert conditions here%
    exit when n > maxint
    n += 1
end loop
put n

for i : 1 .. maxint
    if %Insert conditions here% then
        put i
        exit
    end if
end for


Oh and 504 isn't a proper exit strategy since we're not talking about x rem y = 0 (aka a factor). Your just lucky that the answer is slightly below this though. Then again there might be a theory that says every combination of below that sum will have each combination of remainders...

@Brightguy: is that what your Chinese remainder theorem was pointing at?
Brightguy




PostPosted: Thu Apr 08, 2010 9:18 pm   Post subject: Re: generating least positive integer (mod function) help

Zren @ Thu Apr 08, 2010 8:24 pm wrote:
Then again there might be a theory that says every combination of below that sum will have each combination of remainders...

I'm having difficulty parsing this, but yes, the Chinese remainder theorem is the essential theory. It saves you the trouble of checking every possible case by giving you a formula for the answer:

4*8*9*(1/(8*9) mod 7)+5*7*9*(1/(7*9) mod 8)+6*7*8*(1/(7*8) mod 9) mod 7*8*9

However, this requires computing modular inverses, which may not be part of the high school curiculum.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 20 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: