Skip to content

Instantly share code, notes, and snippets.

@logicrime
Created September 7, 2015 01:52
Show Gist options
  • Save logicrime/add33d2d590e1a9cfd4b to your computer and use it in GitHub Desktop.
Save logicrime/add33d2d590e1a9cfd4b to your computer and use it in GitHub Desktop.
accwords
#!/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