There is a 3x3 square block made of 1x1 square blocks, with coins in each 1x1 block, starting from top left block you want to collect all the coins and return to top left block again, if possible provide instructions to achieve this.
- From block \$(x,y)\$ in one step you can move right(R) to \$(x,y+1)\$ ,left(L) to \$(x,y-1)\$ ,up(U) to \$(x-1,y)\$ ,down(D) to \$(x+1,y)\$ assuming the block to which we jump is not empty and is well inside our block
- We can take only one coin at a time.
- Just after performing the jump we collect 1 coin from our new position.
- Provide the route to take in form of a string, for example like RLRRDULU...
- You should collect all coins
- If there doesn't exist a solution route print/output -1
- If there exist multiple solution you are free to provide any
Each 1x1 block can have upto 69 coins
integer in each place denotes number of coins at each block 1 1 1 1 1 1 1 2 1 here DDRUDRUULL and RRDDLUDLUU both are correct (there might be more but you can print any one of your choice) 2 4 4 2 1 3 1 2 3 here DDUURDDRUULRLRDDLRUULL is a valid answer 5 5 1 5 4 5 5 2 2 here DURLRLRLRDLDUDUDUDRLRURLRLRDUDUULL is a valid answer 2 4 2 2 1 1 1 1 2 here doesn't exist a valid solution for this case so output -1 29 7 6 8 5 4 4 28 3 here doesn't exist a valid solution for this case so output -1 4 3 5 5 4 5 3 5 2 here DUDURLRDLDRULRLRDLRLRRLRUUDUDUDUDULL is valid solution 18 8 33 16 4 38 10 28 25 here DUDUDUDUDUDUDUDUDUDUDURLRLRLRLRLRLRDLDUDURLRLRDLRLRLRLRLRLRLRLRRUUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDDUDUDUDUDLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRUULL is a valid solution 69 69 69 69 69 69 69 69 69 here doesn't exist a valid solution for this case so output -1 7 5 9 21 10 68 15 3 56 here DUDUDUDUDUDUDDUDUDUDUDUDUDUDUDUDUDUDUDUDUDRRLRLRUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUUDUDUDUDUDUDUDUDUDLRLRLRLRLRLUDUDUDUDUL is a valid solution 17 65 29 16 35 69 19 68 56 here doesn't exist a valid solution for this case so output -1
This is code-golf so the goal is to minimize your source code with answers being scored in bytes, but feel free to showcase any of your approach, I will be glad to read all those.
Edit : As mentioned we are starting from top left block, so the number of coins in the top-left block is apparently not decremented when the game starts.Also, as mentioned coin in a block can be as big as 69 so your code should be able to give output in reasonable time(not more than 60 seconds or timeouts), you can test your code in last 3 examples, feel free to ask for some more examples.
Note that it is promised that coin exist in each cell.
Edit : releaxed IO as suggested, return a list or string representing the moves, you can use 4 distinct values for L,R,U,D. If there is no solution, return a consistent value distinct from any solution