10038 Jolly Jumper Solution
Here's my Jolly Jumper solution. It was accepted by UVA online judge. It may not be the best solution but at least its readable.
My Algorithm is designed to fail quickly. As it calculates each sequence number it checks against three simple rules
- The sequence(n) number cannot be 0
- The sequence(n) number cannot be equal or greater than the input(numbers in my code). If there are 4 numbers then the sequence should contain the numbers 1,2,3
- There cannot be duplicates.
My solutions took 0.304 seconds to execute. Compared to the best, my solution is rather slow. The best solutions were written in C++ and ANSI C. Their run time was a flat 0. It would be rather interesting to see if I could get an even faster run time. The only problem is that I'm using Java which is going to be slow from the get go. On the bright side I am one of 9546 users that have solved this problem.
My solution came as a result of refactoring. My original solution did not fail early. Instead it gathered all sequence numbers, sorted a list and then checked that it had the correct numbers. My original solution had an execution time of about 0.36 well my new solution executed at about 0.304. Although my solution isn't the fastest's I do enjoy its readability.
The problem can be found here
My solution came as a result of refactoring. My original solution did not fail early. Instead it gathered all sequence numbers, sorted a list and then checked that it had the correct numbers. My original solution had an execution time of about 0.36 well my new solution executed at about 0.304. Although my solution isn't the fastest's I do enjoy its readability.
The problem can be found here
0 comments:
Post a Comment