zOs/SQL/LABYRIN4
with labyrinth (lab) as -- das leere Labyrinth byrinth
( 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 a: probiere nach rechts
union all select lab, pos+ 1, 'pr', len+1
from suche
where sta = 'ok' and len < 999
union all select -- Schritt b: markiere Schritt falls ok
left(lab, pos-1) || '>' || 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), sta, len
from suche,zeilen
order by lab, sta, z