fork download
  1. def is_valid_string( s )
  2. brackets = %w[ () [] {} ]
  3. brackets.none? { |b| s.include?( b ) }
  4. end
  5.  
  6. test_strings = [ 'hello (world)!', 'hello ()', 'test {}' ]
  7.  
  8. test_strings.each do |s|
  9. is_valid = is_valid_string( s )
  10. puts "#{s} -> #{ is_valid ? 'valid' : 'not valid' }"
  11. end
Success #stdin #stdout 0s 6252KB
stdin
Standard input is empty
stdout
hello (world)! -> valid
hello () -> not valid
test {} -> not valid