Problem 54780. Trap a knight
Solution Stats
Problem Comments
-
2 Comments
my solution (using brute force) is giving the right answer (on the test cases I checked) but it's failing in Cody due to time constraints. I hate it when it does that.
in test case - 5, tic-toc is giving me 5s. I might be able to optimize the code a little more but I am not sure that would be enough. I think it's failing on the loop test cases due to runtime.
is it necessary to use loop cases as they tend to take a long time? why not just random settings?
First off, why doesn't the MATLAB GUI find spiral when you search for it? I spent a lot of time building this myself before going on the internet for it.
Second, sorting a list and keeping the indices (second output argument from sort())is much faster than repeated finds when you're in the tens of thousands of finds and tens of thousands of array elements.
Solution Comments
Show commentsGroup

Sequences and Series VI
- 16 Problems
- 3 Finishers
- Compute a determinant
- Determine whether the input is an anagram number
- Generate the Figure-Figure sequence
- Determine whether a number is practical
- Count the peaceful queens
- Flip the parity of digits in a decimal expansion
- Trap a knight
- Count estrangements
- List numbers that are not squares
- List the nth term of Rozhenko’s inventory sequence
- Count the unitary divisors of a number
- Sum the unitary divisors of a number
- Compute the unitary totient of a number
- Compute the Lagarias Riemann Hypothesis sequence
- Compute the largest number with a given integer complexity
- Compute the Tetris sequence
Problem Recent Solvers5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!