Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

C++: #include <iostream>
#include <vector>

using namespace std;
const int X = 1000;
const int Y = 10;
bool g[Y][X][Y][X];

struct State {
    int x;
    int y;
    int dir;
};
int dirx[] = {1, 0, -1, 0};
int diry[] = {0, 1, 0, -1};
string ans = "";

vector<int> inputLine() {
    string s;
    vector<int> a;
    cin >> s;
    for(char c : s) {
        a.push_back(c - '0');
    }
    return a;
}

string toString(int dir) {
    switch(dir) {
    case 0:
        return "R";
    case 1:
        return "D";
    case 2:
        return "L";
    case 3:
        return "U";
    }
}

struct State at(struct State st) {
    for(int i=0;i<4;i++) {
        int ndir = (st.dir + i) % 4;
        int nx = st.x + dirx[ndir];
        int ny = st.y + diry[ndir];
        if(0 <= nx && 0 <= ny && g[st.y][st.x][ny][nx]) {
            // printf("nx: %d, ny: %d, ndir: %d\n", nx, ny, ndir);
            ans += toString(ndir);
            int nndir = (ndir+3)%4;
            int nnx = nx + dirx[nndir];
            int nny = ny + diry[nndir];
            if(0 <= nnx && 0 <= nny && g[ny][nx][nny][nnx]) {
                // print("dirx: %d, diry: %d\n", dirx[ndir
                // printf("nnx: %d, nny: %d, nndir: %d\n", nnx, nny, nndir);
                return (State){nx, ny, nndir};
            }else {
                return (State){nx, ny, ndir};
            }
        }
    }
}

int main() {
    vector<vector<int>> a;
    for(int i=0;i<9;i++) {
        a.push_back(inputLine());
    }
    for(int i=0;i<Y;i++) {
        for(int j=0;j<X;j++) {
            for(int k=0;i<Y;i++) {
                for(int l=0;j<X;j++) {
                    g[i][j][k][l] = false;
                }
            }
        }
    }
    for(int i=0;i<4;i++) {
        for(int j=0;j<a[0].size();j++) {
            if(a[2*i][j] == 1) {
                g[i][j][i][j+1] = true;
                g[i][j+1][i][j] = true;
            }
        }
        for(int j=0;j<a[1].size();j++) {
            if(a[2*i+1][j] == 1) {
                g[i][j][i+1][j] = true;
                g[i+1][j][i][j] = true;
            }
        }
    }
    for(int j=0;j<a[0].size();j++) {
        if(a[8][j] == 1) {
            g[4][j][4][j+1] = true;
            g[4][j+1][4][j] = true;
        }
    }
    auto st = at((State){0, 0, 0});
    while(st.x != 0 || st.y != 0) {
        // printf("x: %d, y: %d, dir: %d\n", st.x, st.y, st.dir);
        st = at(st);
        // cout << st.dir << endl;
    }
    // printf("x: %d, y: %d, dir: %d\n", st.x, st.y, st.dir);
    cout << ans << endl;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6]={0};
  for(int i=0; i<9; i++){
    if(i%2 == 0){
      for(int j=0,a; j<4; j++){
	scanf("%1d",&a);
	field[i/2][j+1]+=4*a;
	field[i/2+1][j+1]+=a;
      }
    }
    else{
      for(int j=0,a; j<5; j++){
	scanf("%1d",&a);
	field[i/2+1][j]+=2*a;
	field[i/2+1][j+1]+=8*a;
      }
    }
  }
  int x=0,y=1,d=2;
  for(;;){
    if(d == 1){
      if(!(field[x][y]&2)){d = 2;y++;}
      else if(field[x][y]&1){cout <<"U";d = 8;}
      else{cout <<"U";x--;}
    }
    else if(d == 2){
      if(!(field[x][y]&4)){d = 4;x++;}
      else if(field[x][y]&2){cout <<"R";d = 1;}
      else{cout <<"R";y++;}
    }
    else if(d == 4){
      if(!(field[x][y]&8)){d = 8;y--;}
      else if(field[x][y]&4){cout <<"D";d = 2;}
      else{cout <<"D";x++;}
    }
    else if(d == 8){
      if(!(field[x][y]&1)){d = 1;x--;}
      else if(field[x][y]&8){cout <<"L";d = 4;}
      else{cout <<"L";y--;}
    }
    if(x == 0 && y == 1 && d == 2) break;
  }
  cout <<endl;
  return 0;
}