![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() ![]() |
SMAC #1 [05-08] - Mobile (Beginner) and "n Reach k" (Junior)
Attached to this post is the test data for both problems.
Mobile (Junior) This solution required the ability to follow instructions and write a stable primality test. If using Python, you need to be careful about how large of a range you create with range(). Alternatives, such as xrange() and while loops, do exist. Note: For this problem, it was left unclear what should happen if n=0. The "correct" solution converts 0 to 0. However, no test data exploits alternate behaviour. Here is Jessehk's solution, written in Python (modified slightly for backwards compatibility): Python Syntax (Toggle Plain Text)
And here is the official solution: C Syntax (Toggle Plain Text)
"n Reach k" (Junior) This solution required you to write a recursive function. For each state, you need to branch off to all possible states. When you reach the end of recursion (the base case), you store the maximum n thus far. After taking all possible routes, the maximum value of n is the value of nRk. To score full points, the primality test must be careful to not exhaustively try modulating by all values, or else it might run over time. Wikipedia has some efficient algorithms for primality tests. Ooble implemented a very good primality test that runs very quickly even in Python. Here is his solution, also written in Python. This code by itself will not run. Functions that do I/O work were included in a separate module, and have therefore been left out. Python Syntax (Toggle Plain Text)
And here is the official solution: C Syntax (Toggle Plain Text)
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: May 2008
Posts: 2
Rep Power: 0
![]() |
Re: SMAC #1 [05-08] - Mobile (Beginner) and "n Reach k" (Junior)
For test case #9 the solution you have is a negative number, I thought the file must be wrong or corrupted somehow, so I copied your code and compiled it and I got the same negative number, how can a negative number be the maximum or am I mistaken somehow
Edit: nvmd I posted this before looking at the test case and cant delete the post now |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
Re: SMAC #1 [05-08] - Mobile (Beginner) and "n Reach k" (Junior)
Yeah, don't be afraid to ask about things like that. There's a good chance I did make a mistake somewhere from rushing about.
I've got some good problems brewing for this month. They are less typical, and more plot based. I will try my best to get them posted by Friday or Saturday.
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
![]() |
| Bookmarks |
| Tags |
| smac beginner solutions, smac junior solutions |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|