Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created April 29, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/11402663 to your computer and use it in GitHub Desktop.
Save whatalnk/11402663 to your computer and use it in GitHub Desktop.
CodeIQ 結城浩さん出題「スペーストーキー問題」(不完全)
def enc_string(s)
repeated = Hash[("a".."z").to_a.zip (1..26)]
n = s.length
decoded = []
i = 0
while i < n
chars = s[i..i+1]
decoded << chars[0] * repeated[chars[1]]
i += 2
end
decoded.join()
end
out_file = File.open("out.txt", "w")
File.open("words.txt", "r") do |file|
file.each do |line|
line.chomp!
if line.length%2 == 0
out_file.print enc_string(line), ":#{line}\n"
else
out_file.print "X:#{line}\n"
end
end
end
out_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment