you might want to specify in the problem that the sequence has to be made of N unique values
sorry, my mistake; it was unclear to me at first that the sequence had to contain a permutation of the values 1:N
Thank You. I have clarified that each value must be used.
oh man, this problem is brutal. i have a solution that can solve it for values of N between 33 and 39 inclusive in under a second, but as soon as I try 40 or 41, it runs forever (or at least past the end of my patience)
It seems there is a lot of variability depending on your particular search heuristics and the particular value of N. My solution performs in under 30 seconds for 19 out of the 20 cases 31
Hello Richard, Hello Alfonso, Hello @bmtran, Is it possible to solve this kind of problem without recursion ?
In general, sure, you can easily write these sort of heuristic-search algorithms without explicitly using recursion, or you could use non-search-based approaches, such as annealing, integer linear programming, etc. Now if you are asking whether exhaustive or other polynomial-time approaches are possible/practical for this problem I am not really sure about that. I believe this problem reduces to finding a full hamiltonian cycle over an N-node graph, so the only hope of bringing this out of the NP-hard umbrella would be exploiting some properties of these particular networks arising from the properties of perfect numbers, but so far I do not see any useful trick in this regard (so in short, perhaps it is possible but I do not know how; any thoughts?)
a bit faster (median t=0.56s for 31
Reverse the Words (not letters) of a String
Number of 1s in a binary string
Make a random, non-repeating vector.
Determine if input is a perfect number
PACMAT 06 - Optimized Ghosts, Equal Speed, Inf Lives; Interactive Download
USC Fall 2012 ACM: Rover Maze
GJam 2014 China Rd A: Read Phone Number (Large)
Fix y_correct : Hack
GJam 2014 China Rd A: Maze with a Left Hand Rule
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office