Skip to content

Instantly share code, notes, and snippets.

@dwiash
Created October 26, 2010 12:05
Show Gist options
  • Select an option

  • Save dwiash/646788 to your computer and use it in GitHub Desktop.

Select an option

Save dwiash/646788 to your computer and use it in GitHub Desktop.
# to run this script, type this line in your console:
#
# $ ruby alien_language.rb < input_file.txt > output_file.txt
#
#
# this script tested with ruby 1.8.7 patchlevel 72
input_array = readlines
var = input_array[0].split(" ")
L = var[0].to_i
D = var[1].to_i
N = var[2].to_i
dictionary = []
(1..D).each do
|i|
dictionary.push(input_array[i])
end
test_case = []
(D+1..D+N).each do
|i|
test_case.push(input_array[i])
end
num_case = 1
test_case.each do
|line|
counter = 0
line = line.gsub("(", "[")
line = line.gsub(")", "]").strip
dictionary.each do
|item|
item = item.strip
eval('counter = counter+1 if "'+ item +'" =~ /^'+ line +'$/')
end
puts "Case ##{num_case}: #{counter}"
num_case = num_case + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment