Minimum number of moves from a to b

  • Context: Undergrad 
  • Thread starter Thread starter BiGyElLoWhAt
  • Start date Start date
  • Tags Tags
    Metric Minimum
Click For Summary

Discussion Overview

The discussion revolves around finding the minimum number of moves required to transition from one point to another on a number line, given specific allowed step sizes and constraints. Participants explore various approaches to solving this problem, which involves both theoretical and practical considerations, including potential algorithms and the implications of move order.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant suggests that the problem can be approached using a metric with a proper distance function, although they express uncertainty about this method.
  • Another participant proposes exploring all options through an A* search or similar methods, noting that if constraints are not too complex, a largest target position can be determined to limit the search space.
  • A question is raised about whether the order of moves affects the outcome, leading to a discussion about the implications of move symmetry and the greatest common divisor (GCD) of the move set.
  • One participant shares their findings on specific configurations of moves within an 8x8 grid, indicating the number of positions reachable with different move counts.
  • Concerns are expressed about encountering overflow errors in a recursive approach, with a participant detailing their method of checking allowed moves from the starting position.
  • Another participant mentions the challenge of handling moves that are two spaces apart and reflects on the inefficiency of nested recursion in their programming approach.
  • A participant introduces the concept of modular arithmetic, noting that their specific moves relate to multiples of 9 and suggesting a connection between the allowed moves and the finite field used.
  • One participant outlines a systematic approach to iteratively explore positions and determine optimal paths, emphasizing the efficiency of the method in computational terms.

Areas of Agreement / Disagreement

Participants express a range of views on the best approach to solving the problem, with no consensus reached on a definitive method. Some agree on the utility of exploring all options, while others highlight the complexity introduced by constraints and move order.

Contextual Notes

Participants mention various limitations, including the complexity of constraints, the potential for overflow errors in recursive methods, and the challenges of efficiently exploring the solution space. The discussion also touches on the implications of move order and the relationship between moves and modular arithmetic.

Who May Find This Useful

This discussion may be of interest to those studying combinatorial optimization, algorithm design, and mathematical problem-solving, particularly in the context of constrained movement on a number line or grid.

BiGyElLoWhAt
Gold Member
Messages
1,637
Reaction score
138
Hi, I think this is a topology question, but I'm honestly not 100% sure. Feel free to move.

On a number line, I am trying to find the minimum number of moves to get from one point to another, given certain allowed step sizes. For example, My allowed steps might be +/-2, +/-3, and I want to move from 0 to 1. my shortest number of moves would be 2 in this case, +3->-2 or -2->+3. Now say I want to move from a->b. How would I go about figuring out the shortest number of moves?
My actual problem also has constraints on the moves as well, some places I can't execute more than one of the moves. Think about it as a finite 2D space projected onto a line. So I have an nxm grid numbered 0 through n*m-1 and I'm not allowed to leave the grid. If I'm looking at a position along the left hand side, I can't, for example, use -3. I'm just curious about how I should go about solving this problem, so I'm not giving the actual example, but in case you're curious, it's a 2d space mapped to a 1d space, and the set of moves are +/- (6,10,15,17) with constraints, like position 0 can only move 10 and 17. No negative positions are allowed, however I don't think that is all that important, since there is a symmetric move (3-2 vs -2+3 in the original example).

My guess is that it can be solved using a metric with the proper distance function for each point. However that doesn't feel quite right. If I am not clear, I can attempt to clarify. I'm more looking for the approach to the solution rather than the solution itself, so let's stick with +/-(2,3) for our moves, and arbitrary constraints if that works for whoever is reading this to help.

Thanks in advance.
 
Physics news on Phys.org
In general this can be a very difficult problem, but if you only have a very limited set of moves you can simply explore all options. Do an A* search or something similar if the problem gets too complex for a simple recursion.

As long as everything is symmetric, let's say b>a. For a given a, if your constraints are not too obscure, there is a largest b, b0 where the ideal solution does not include a positive step of the largest possible value. You only have to explore the range up to there. Larger b are constructed by simply adding more of the largest possible step and using a solution found previously for smaller b for the rest.

With +-2 and 3, this b0 is just 4 above a:
  • +1 is +3 -2
  • +2 is +2
  • +3 is +3
  • +4 is +2 +2
  • everything beyond that is repeated +3 until you get one of the previous three cases.
 
  • Like
Likes   Reactions: BiGyElLoWhAt
Does the order of the moves matter, i.e., if I do +3 followed by -2 , is this the same as doing -2 and then +3 ?
EDIT: If this is so and forward- , backward- moves are allowed for all, then it comes down to GCD of the set of moves dividing the number of moves you want to do.
 
The order doesn't matter as long as the moves are permitted. I have figured it out for 8x8 and there are 4 spots with 2 moves, 20 with 4, 16 with 6, and 24 with 8.

With regards to mfb's response, perhaps 3 and 2 were bad choices, because that gives you the option of moving 1 space with 2 moves. The issue I'm running into is I'm getting overflow errors, presumably because it can't find a correct set of moves, let alone the minimum set. My current method is recursive, but it's not that good, because I haven't figured out what exactly to program.
I first check to see if I can get from a to b with a move allowed from a. If I can't I check to see if I can get to a spot that is an allowed move from b with a move from a. It's worth mentioning that if a move is allowed from c to d, the negative of that move is allowed from d to c, always
 
This works for spaces that are 2 moves apart, I'm just not sure how to handle it from there. With nested recursion, I can only check 1 move at a time (if I follow that move to it's possible moves). I remember something in java class where it was a tree, like a family tree. I can do that, but that doesn't seem like a fast way to do it (order n! If I'm not mistaken.
 
One more thing that I've noticed, out of the 8 possible moves, each one takes you +/-(1,3) away from a multiple of 9. So, in my specif case, i have +/-(6,10,15,17) and if we work in Finite field 9 (modular arithmetic), each one of those has an associated +/-(1 or 3) associated with it. That was actually the first thing I noticed. For a different size 2d space, the finite field would be different, as well as the allowed moves, but I think one can be derived from the other, so it's not 2 independent pieces of information. Correct me if I'm wrong, but that shouldn't be useful.
 
With your specific example:
Make a list from 0 to 300. 0 is your starting position and 300 > 15*17 should be well above b0.

We know how to reach 0 optimally, we don't know it for anything else.
First iteration: Loop over all positions, if you know how to reach them optimally add/subtract each possible step, if you reach a legal position that hasn't been explored yet store how you got there, otherwise do nothing. After this iteration you know how to reach 0,6,10,15,17 optimally.
Second iteration: Same as above. From 0 you don't learn anything new, but from 6 you learn how to reach 12, 16, 21 and 23, from 10 you learn how to reach 4, (16), 20, 25 and 27, from 15 you get 9,5,32, and from 17 you get 11,7,2,34.

You should be done after ~17 iterations, checking 300 numbers each (5100 quick checks), and 300 times you have to add/subtract 4 different values each (2400 quick checks), with 300 updates. A computer can do that in fractions of a second.
 
  • Like
Likes   Reactions: BiGyElLoWhAt

Similar threads

  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K