Programming 3 luck

Put your programming skills to the test in these challenges.

Re: Programming 3 luck

Hey everyone. I really, really enjoyed doing this one. While my solution is not as fast as others report, my script's times were fair considering I used PHP. The minimal time my script can take is 1-2 seconds, and the absolute maximal time that it takes is just above 100 seconds on my machine, with a fair average of around 30 seconds. Looking back at my progress through out the entire course of solving it, I can see some stumbling blocks that once I over came, I was able to see a clear path to the end. As such, I have a few tips based on those moments, which should be vague enough to not be spoilers, yet still be helpful enough to help others overcome the same obstacles quicker.

#1 - the absolute most important thing is making sure to gather every bit of information you possibly can from the example serial numbers. it is vital to understand that "a significant portion" of all data, is given to you, freely, for no effort at all, meaning you have to guess less of the entire string.

#2 - after you have gathered all possible information from the examples, the next most important thing is understanding the algorithm code. what exactly is it doing? how could you go about brute forcing it? based on the code, what inferences can you draw that will help you brute force the code without trying every possible combination? I can say with 100% certainty that you do not have to try every possible combination.

#3 - a vital key to solving the whole thing, for me at least, was finally realizing that you truly only must solve the code and the "starting point". All other data that seems like it needs to be known, is just a sink hole. There is one piece of other data in particular, that it seems like you have to know; however, after closer inspection, and a little thinking/experimenting, this data can accurately be guessed, on the fly, if: the proper starting point is known and all "known data" is taken into account.

#4 - once you think you have a solution that could work, use the algorithm to encode around 2 serial numbers word of data, and use that to test the accuracy of your code. based on how your code works, you should also try to test the upward and lower timeframes for your script to solve an entire set of serial numbers. if you are still outside of the 120 second limit, then you probably need some tweaking. like I said, at maximum, my solution will run at about 100 seconds, well under the limit.

#5 - remember that you should be able to determine if your results are correct without asking the server. ergo, DO NOT BRUTE FORCE THE SERVER. this is not really a stumbling block to overcome, but more a reminder to not be a prat.

That is it for the actual challenge. I also have some general notes about creating a programmatic approach to this challenge as whole:

- if you are outputting debug in your script (like me), remember that printing it directly to your terminal has a significant overhead. try piping the output to a log file, and then checking the logfile afterwards. while piping it to my terminal I was only able to get a bandwidth of around 250k transactions in around 100 seconds; however piping it to a log file, I was able to get nearly 3 million transactions in the same time.

- since you may be on the edges of time for the challenge, you may realize that you have very little time to copy and paste the code from the challenge into your script, and the result from your script back into the challenge. if that is the case, consider wrapping your script in another script that imitates your browser, fetches the challenge, submits it to your script, and then takes the result of your script and submits it as the solution. you could alternatively just make it all one script. it is really up to you.

- finally, PHP is a scripting language, and thus obviously slow, at least in comparison to something like C which can be compiled; however, do not let this fact deter you from using it, or any other scripting language to solve this problem. I mean it. you could use practically any language to solve this problem, so long as you understand how to use the language, and you understand how to solve the problem using that language. mine is PHP, and at max it runs 100 seconds. if that is not enough proof, then im not sure what is.

I really hope this helps someone, but even if it doesn't, I really had fun doing this one.

Loushou
loushou
New User

Posts: 1
Joined: Thu Dec 18, 2014 12:02 am
Blog: View Blog (0)

Previous