: 2array 2 compress ; : bi* '_ set dip _ execute ; : bi@ dup bi* ; : comb "" split ; : concat "" join ; : dip swap '_ set execute _ ; : first 0 extract swap drop ; : flip comb reverse concat ; : contains swap 'comb bi@ length do # create a matrix. 1 - "dup 1 1 compress rotate" dip dup 0 == if break then loop drop length compress swap drop "length 1 -" bi@ rot 0 0 "'2array dip" '2array bi* swap 2array slice reverse : concat.(*) concat ; 'concat "'concat. apply" bi* eq 1 1 compress index collapse length if expand drop else drop 0 then ; # r: position. : end-with 'flip bi@ start-with ; : start-with 'comb bi@ length rot swap iota subscript 'concat bi@ eq ; "rosettacode" "rosetta" start-with . # 1 "rosettacode" "taco" contains . # 5 "rosettacode" "ocat" contains . # 0 "rosettacode" "edoc" end-with . # 0 "rosettacode" "code" contains . # 7