3
$\begingroup$

How many different routes of length 10 units (each side is 1 unit) are there to traverse from lower left corner (point A) to top right corner (point B) in a rectangle with 2 rows and 4 column cells each without moving on the sides repeatedly?

You can use any knowledge to answer this (I have some Math Olympiad background). Total length from A to B is 6 units (2U's [Ups] and 4R's [Rights]). So for the additional 10 - 6 = 4 units of lengths we need them in pairs (since they need to cancel out). How to count further? Any help is appreciated. Thank you

Image added Image added

$\endgroup$
5
  • $\begingroup$ By the "sides" you mean the periphery of the grid ? $\endgroup$ Commented Apr 4 at 3:50
  • $\begingroup$ Oh I added the picture for ease $\endgroup$
    – Jonny Boy1
    Commented Apr 4 at 4:13
  • $\begingroup$ No edge can be traversed twice, correct? $\endgroup$
    – mjqxxxx
    Commented Apr 4 at 4:40
  • $\begingroup$ Is the interpretation that you can't retrace your path on any segment on the boundary segments, whereas you can do so freely on all other segments correct ? If so, confirm, else tell what exactly "without moving on the sides repeatedly" means. $\endgroup$ Commented Apr 4 at 6:26
  • $\begingroup$ Oh I think we cannot retrace any line segment (on the boundary or otherwise). We can retrace a point only. In other words no edge can be traversed twice, that's right. $\endgroup$
    – Jonny Boy1
    Commented Apr 4 at 8:38

2 Answers 2

0
$\begingroup$

This question is a classic example of the fact that

Sometimes, even the smartest way of counting may also not be smart enough

I've solved it with brute force

enter image description here

enter image description here

enter image description here enter image description here

(PS: I'm not sure if I've committed any error; feel free to point out if you find any. Also, if anybody knows a better way to calculate, do let me know. I'll be grateful.)

$\endgroup$
3
  • $\begingroup$ This was one hell of a question $\endgroup$
    – Fredrick
    Commented Apr 11 at 10:41
  • 1
    $\begingroup$ verified your answer with a python script. 66 is correct. i also shared the pyhon script in a answer so others can build on it. $\endgroup$
    – mond
    Commented Apr 11 at 16:17
  • $\begingroup$ Thank you @mond $\endgroup$
    – Fredrick
    Commented Apr 11 at 16:27
0
$\begingroup$

The answer 66 seems correct. A brute force python search also resulted in 66

import itertools as it
import numpy as np
H=4
V=2
detours=["LLRR", "LDRU", "DDUU"]
combi=[list("RRRRUU")+list(detour) for detour in detours]

# so we create all permuations of the 3 combinations of normal moves and de-tours
# this would create many duplicates but since we use set comprehension
# each possible move will be there only once.
# certainly not the most efficient way but 
# only takes fractions of a seconds anyways

moves={move for move in it.chain(*[it.permutations(p) for p in combi])}
print("total number of moves to consider",len(moves))


def pos(pin,move):
  """
    pin position in (x,y) pair
    move a letter indicating the move direction
    returns a tuple of (x,y,hidx,vidx,mv)
    where x y is the position after move
    hidx and vidx is the index of the horizontal and
    vertical nodes that is touched and
    mv is either 'H' or 'V'
  """
  x,y=pin
  hindex,vindex=x,y
  mv='H'
  match move:
    case 'R':
        hindex=x
        x+=1
    case 'L':
        x-=1
        hindex=x
    case 'U':
        vindex=y
        y+=1
        mv='V'
    case 'D':
        y-=1
        vindex=y
        mv='V'
    case _: assert False,"illegal direction"
  pout=(x,y,hindex,vindex,mv)
  return pout

def domoves(m):
    """
      do the moves in list m
      returns a tuple (xmax,xmin,ymax,ymin,edgemax,m)
      with the minimum and maximum x and y positions to see if
      we left the field
      and the maximum number edges we traversed
      so should be 1 in order not to move twice on an edge
    """
    hedge=np.zeros((H,V+1))
    vedge=np.zeros((H+1,V))
    x,y,hidx,vidx=0,0,0,0
    xmax=0
    xmin=0
    ymax=0
    ymin=0
    for move in m:
        x,y,hidx,vidx,mv=pos((x,y),move)
        xmax=max(x,xmax)
        xmin=min(x,xmin)
        ymax=max(y,ymax)
        ymin=min(y,ymin)
        if xmax <= H and xmin >= 0 and ymax <= V and ymin >=0:
            if mv=='H':
                hedge[hidx,vidx] += 1
            else:
                vedge[hidx,vidx] += 1
    hmax=np.max(hedge)
    vmax=np.max(vedge)
    edgemax=max(hmax,vmax)
    assert x==H and y==V
    return (xmax,xmin,ymax,ymin,edgemax,m)

mres=[domoves(mv) for mv in moves]
mvalid=[m for xmax,xmin,ymax,ymin,emax,m in mres if xmax <= H and xmin >= 0 and ymax <= V and ymin >= 0 and emax == 1]
print(len(mvalid))

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .