Problem 42291. GJam 2015 Rd1B: Counter Culture
This Challenge is derived from GJam 2015 Rd 1B: Counter Culture. Fastest completion - 5 minutes.
Determine minimum sequence length to reach a number. Sequence starts at 1 and the next is either +1 or the number's reverse with trailing zeros removed. (eg 2300 is followed by 2301 or 32)
Input: N, a value from 1 to 1,000,000
Output: L, minimum length of sequence to reach N
Examples: Small Case 1<=N<=1000000
N=5, L=5 [1 2 3 4 5] L=N is true thru 19 N=23, L=15 [1:12 21 22 23]
Theory: The small case can be solved with brute force or semi-brute force using storage of past calculations. All values are processed at each depth level. Duplicates from [N+1 and flip] are purged. A fast reversal function is essential. Direct summation works well. The large case N limit is 1E14 making even semi-brute force with storage unlikely.
Additional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. The Test Suite, at the bottom, contains a full GJam Matlab solution.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
443 Solvers
-
Return the first and last characters of a character array
9484 Solvers
-
Find the elements of a matrix according to a defined property.
84 Solvers
-
273 Solvers
-
241 Solvers
More from this Author308
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!