Longest string challenge

var l = ''  # Sample longest string seen.
var a = ''  # Accumulator to save longest strings.
 
STDIN.each { |n|
    n.substr(l.len) ? (a = n; l = n)
                    : (!l.substr(n.len) && a.concat!(n))
}
 
print a

Last updated