Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # This program is a filter.
- # Input file should be fed
- # into standard input.
- # Remove character at index from string
- def puncture( string, index )
- substring1 = string[0,index]
- substring2 = string[index+1,string.length-index-1]
- return substring1 + substring2
- end
- # Read stdin file into array
- codes = Array.new
- i = 0
- while codes[i] = gets
- i = i + 1
- end
- # Next line removes ending
- # blank line if there is one
- # because it tends to cause
- # problems later on.
- codes.pop if codes[-1].nil?
- codes.each{ |code| code.strip! }
- # Create hash table for each position
- hashes = Array.new(26)
- 0.upto(25) do |i|
- hashes[i] = Hash.new
- codes.each do |code|
- p = puncture( code, i )
- hashes[i][p] = Array.new unless hashes[i].key?(p)
- hashes[i][p].push( code )
- end
- end
- # Find keys with multiple values
- 0.upto(25) do |i|
- hashes[i].each do |p|
- if p[1][1]
- puts puncture( p[1][0], i );
- end
- end
- end
Add Comment
Please, Sign In to add comment