(preso da hackerforum.devil.it)
Scrivere un programma che elenchi senza ripetizioni i caratteri comuni in due parole:
la mia in ruby
Scrivere un programma che elenchi senza ripetizioni i caratteri comuni in due parole:
la mia in ruby
Codice:
#!/usr/bin/ruby
print "type the first world: "
w0=gets.chomp
print "Type the second word: "
w1=gets.chomp
a=Array.new
puts "Common Chars:"
w0.each_byte{|c| if w1=~Regexp.new(c.chr) and (a.include?(c.chr)==false) then a.push(c.chr) end}
if(a.length>0) then a.each_index{|cc| puts cc.to_s+": "+a[cc]} else puts "No matches" end