zOs/SQL/LABYRIN5

with labyrinth (lab) as         -- das leere Labyrinth
( select 'X|XXXXXXXXXXXXXXXXX'  -- 1
      || 'X|    X     X  X  X'  -- 2
      || 'X XXX X XXX   XXX X'  -- 3
      || 'X X   X   XXX   X X'  -- 4
      || 'X XXXXXXX   XXX X X'  -- 5
      || 'X   X   X X  X    X'  -- 6
      || 'XXX X XXX XX X XX X'  -- 7
      || 'X     X   X  X    X'  -- 8
      || 'X XXXXX X XXXXXX XX'  -- 9
      || 'X       X         *'  --10
      || 'XXXXXXXXXXXXXXXXXXX'  --11
       -- 123456789 123456789
    from sysibm.sysDummy1
)
, zeilen (Z) as                 -- Anzahl Zeilen
( select 1 from sysibm.sysDummy1
  union all select z+1 from zeilen where z < 11
)
, suche (lab, pos, sta, len) as -- Suche einen Weg
( select lab, 21, 'ok', 0       -- Start: das leere Labyrinth
    from labyrinth
                                -- Schritt a1: probiere nach rechts
  union all select lab, pos+ 1, 'p>', len+1  -- probiere nach rechts
     from suche
     where sta = 'ok' and len < 999
                                -- Schritt a2: probiere nach unten
  union all select lab, pos+19, 'p|', len+1
     from suche
     where sta = 'ok' and len < 999
                                -- Schritt b: markiere Schritt falls ok
  union all select
      left(lab, pos-1) || substr(sta, 2) || substr(lab, pos+1) ,
      pos, 'ok', len+1
    from suche
    where sta like 'p%' and substr(lab, pos, 1) = ' '  and len < 999
)
                                -- Zeilen der Labyrinthe anzeigen
select substr(lab, 19 * z - 18, 19), len
    from suche,zeilen
    where sta = 'ok'
    order by lab, z