views:

286

answers:

2

Assuming a 3 dimensional irregular matrix where y = 1.5(x) and z = .5(y).

Further assuming an object starts at 0,0,0 and must move positively in at least two dimensions, and must move in all three dimensions (x+1, y+1, z-1 is okay, x+1, y+1, z=z is not). It may move any number of "spaces", but must move the same number in all directions.

The object is allowed to wraparound (x(max +1) = x(0)).

Move said object from its starting position to (0, max(y), .5(max(z))) For z, round up for fractions (end point in 4, 6, 3 matrix becomes 0, 6, 2)

Input is an Integer (X).

Output is the list of moves you would make (extra credit for showing the number of spaces you moved)

Sample Input/Output:

X = 4
Y = 6 //(4 * 1.5)
Z = 3 // 6 / 2

0, 0, 0 //Start
2, 5, 2 // (+2, -2, +2)
1, 2, 2 // (+4, +4, +4)
3, 4, 0 // (+2, +2, -2)
1, 6, 2 // (-2, +2, +2)
3, 3, 3 // (-3, -3, -3)
1, 5, 1 // (-2, +2, -2)
0, 6, 2 // (-1, +1, -1)
7 Moves.
A: 

Mathematica - Not Golfed

Just to see if we can get the ball rolling

... and trying to understand the problem ....

f[x_] := (
   (* Init code *)
   xmax = x;
   ymax = 3 Round[xmax]/2;
   zmax = Round[ymax]/2;
   xobj = 0;
   yobj = ymax;
   zobj = Ceiling[zmax/2];
   p = Join[Permutations[{1, 1, -1}], {{1, 1, 1}}];
   Print["X = ", xmax, "\nY = ", ymax, "\nZ = ", zmax];

   (* Loop *)
   i = 0; 
   pos = {0, 0, 0}; 
   k = "Start";
   While[
    (npos= {Mod[pos[[1]], xmax+1], Mod[pos[[2]], ymax+1], Mod[pos[[3]], zmax+1]}) 
             != {xobj, yobj, zobj}, 
      i++;
      Print[npos, " // ", k];
      pos= npos+ (k= RandomInteger[{1,xmax}] p[[RandomInteger[{1, Length[p]}]]]);
   ];
   Print[npos, " // ", k];
   Print[i, " Moves"];
   );

Invoke with

 f[4]

Sample Output

X = 4
Y = 6
Z = 3
{0,0,0} // Start
{3,4,3} // {3,-3,3}
{0,0,2} // {-3,3,3}
{2,3,1} // {-3,3,3}
{0,6,2} // {3,3,-3}
4 Moves

alt text

Not sure if I'm following the rules ...

belisarius
I'm not sure anyone knows the rules, not even OP
Callum Rogers
+1  A: 

Lua, 68 Characters

The long version below always solves the problem with one move by searching for the first all positive move that will solve problem.

x=...
y,z=x*3/2,x*3/4
a,b,c=0,y,math.ceil(z/2)
x,y,z=x+1,y+1,z+1
for i=1,math.huge do
  if (x*i)%y==b and (x*i)%z==c then x=x*i break end
end
print("0,0,0\n0,"..b..","..c.."//+"..x..",+"..x..",+"..x.."\n1 move.")

Output for x = 12:

0,0,0
0,18,5//+455,+455,+455
1 move.

Output for x = 1000:

0,0,0
0,1500,375//+557424868,+557424868,+557424868
1 move.

Seems like the search could be replaced with some simple algebraic equation. But why stop there? Rules are easier to bend in golfing then doing the actual work.

So, assuming that there is always a single 1 move answer, and that I do not have to disclose the "number of spaces you moved", here is the 68 character golfed answer:

x=...print("0,0,0\n0,"..(x*3/2)..","..math.ceil(x*3/8).."\n1 move.")
gwell
Interesting ... you proved the problem is worthless :)
belisarius