Created
September 7, 2015 01:52
-
-
Save logicrime/add33d2d590e1a9cfd4b to your computer and use it in GitHub Desktop.
accwords
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
#!/usr/bin/ruby | |
# free 4 u 2 use | |
# hayden jones | |
# this can take any number of files as arguments | |
# eg: ./accwords junk.txt junk2.txt junk3.txt | |
# and accumulates each letter | |
# a = 1, b = 2 ... z = 26 | |
# it prints out the final result | |
letter_array = ('a'..'z').to_a | |
accum = 0 | |
files = [] | |
ARGV.each { |arg| files.push(File.open(arg).readlines.join) } | |
letters = files.join | |
letters.each_char do |char| | |
if letter_array.index(char.downcase) | |
then accum += letter_array.index(char.downcase) | |
end | |
end | |
puts accum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment