Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are solutions for each starting position:</p> <pre><code>Start 1: (2, 0, -1) Reds=1 Blues=0 Red B ==&gt; (3, -1, -2) Reds=1 Blues=0 Red B ==&gt; (4, -2, -3) Reds=1 Blues=0 Red D ==&gt; (4, 0, -2) Reds=0 Blues=2 Blue A ==&gt; (2, 0, -1) Reds=0 Blues=1 Blue A ==&gt; (0, 0, 0) Reds=0 Blues=0 Start 2: (3, 1, -1) Reds=2 Blues=0 Red A ==&gt; (3, -1, -2) Reds=1 Blues=0 Red B ==&gt; (4, -2, -3) Reds=1 Blues=0 Red D ==&gt; (4, 0, -2) Reds=0 Blues=2 Blue A ==&gt; (2, 0, -1) Reds=0 Blues=1 Blue A ==&gt; (0, 0, 0) Reds=0 Blues=0 </code></pre> <p>Found instantly by the following C# program that does a random walk and gives up after a small number of moves.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SO8683939 { struct State { public int V1; public int V2; public int V3; public int Reds; public int Blues; public int Tokens { get { return Reds + Blues; } } public string Description; public State(int v1, int v2, int v3, int reds, int blues) { V1 = v1; V2 = v2; V3 = v3; Reds = reds; Blues = blues; Description = null; } public State Add(State other) { State sum; sum.V1 = V1 + other.V1; sum.V2 = V2 + other.V2; sum.V3 = V3 + other.V3; sum.Reds = Reds + other.Reds; sum.Blues = Blues + other.Blues; sum.Description = null; return sum; } public override string ToString() { var detail = string.Format("({0}, {1}, {2}) Reds={3} Blues={4}", V1, V2, V3, Reds, Blues); if (Description != null) { return Description + ": " + detail; } return detail; } } class Program { static void Main(string[] args) { var start1 = new State(2, 0, -1, 1, 0) { Description = "Start 1" }; var start2 = new State(3, 1, -1, 2, 0) { Description = "Start 2" }; var end = new State(0, 0, 0, 0, 0); var redA = new State(0, -2, -1, -1, 0) { Description = "Red A" }; var redB = new State(1, -1, -1, 0, 0) { Description = "Red B" }; ; var redC = new State(2, 0, -1, 1, 0) { Description = "Red C" }; ; var redD = new State(0, 2, 1, -1, 2) { Description = "Red D" }; ; var redOptions = new[] { redA, redB, redC, redD }; var blueA = new State(-2, 0, 1, 0, -1) { Description = "Blue A" }; var blueB = new State(-1, 1, 1, 0, 0) { Description = "Blue B" }; var blueC = new State(0, 2, 1, 0, 1) { Description = "Blue C" }; var blueD = new State(2, 0, -1, 2, -1) { Description = "Blue D" }; var blueOptions = new[] { blueA, blueB, blueC, blueD }; var startingPosition = start1; var maxSolutionLength = 5; var rand = new Random(); var path = new List&lt;State&gt;(); while (true) { var current = startingPosition; path.Clear(); //Console.WriteLine("Starting"); //Console.WriteLine(current); while (true) { State selected; if (current.Reds == 0) { selected = blueOptions[rand.Next(4)]; } else if (current.Blues == 0) { selected = redOptions[rand.Next(4)]; } else { if (rand.NextDouble() &lt; 0.5) { selected = blueOptions[rand.Next(4)]; } else { selected = redOptions[rand.Next(4)]; } } //Console.WriteLine(selected); path.Add(selected); current = current.Add(selected); //Console.WriteLine(current); if (current.Equals(end)) { Console.WriteLine("Success!"); var retrace = startingPosition; Console.WriteLine(retrace); foreach (var selection in path) { retrace = retrace.Add(selection); Console.WriteLine("{0} ==&gt; {1}", selection.Description, retrace); } Console.ReadLine(); break; } else if (current.Tokens == 0) { // fail //Console.WriteLine("Fail"); break; } else if (path.Count &gt;= maxSolutionLength) { // fail //Console.WriteLine("Fail"); break; } } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload