#!/usr/bin/ruby # Translation of: https://rosettacode.org/wiki/Amb#Perl var w = [ "the|,that|,a|", "frog|,elephant|,thing|", "walked|,treaded|,grows|", "slowly|,quickly|", ]; for (w.map{'{'+_+'}'}->join.glob) { |i| i.gsub!('|', ' ') ~~ /\w+?(\w) \1\w+?(\w) \2\w+?(\w) \3\w+/ && (i.say); }