Created
April 29, 2014 14:51
-
-
Save whatalnk/11402663 to your computer and use it in GitHub Desktop.
CodeIQ 結城浩さん出題「スペーストーキー問題」(不完全)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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