Created
January 27, 2013 13:18
-
-
Save RickCarlino/4648321 to your computer and use it in GitHub Desktop.
Josh needed help debugging a Ruby script.
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
text = ' ' | |
line_count = 0 | |
File.open("text.txt").each do |line| | |
line_count += 1 | |
text << line | |
end | |
puts "#{line_count} lines" | |
total_characters = text.length | |
puts "#{total_characters} characters" | |
total_characters_nospaces = text.gsub(/\s+/, ' ').length | |
puts "#{total_characters_nospaces} characters excluding spaces" | |
word_count = text.split.length | |
puts "#{word_count} words" | |
sentence_count = text.split(/\.|\?|!/).length | |
puts "#{sentence_count} sentences" | |
paragraph_count = text.split(/\n\n/).length | |
#Lulz, you had a minor spelling error on the following line. You wrote paragraph-count not paragraph_count | |
#Ruby thought you were doing subtraction on a variable that didn't exist. | |
puts "#{paragraph_count} paragraphs" | |
puts "#{sentence_count/paragraph_count} sentences per paragraph (avearge)" | |
puts "#{word_count/sentence_count} words per sentence (average)" |
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
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a urna tortor. Nunc sagittis elementum massa vel laoreet. Pellentesque condimentum tellus et dolor adipiscing ut ultricies odio consequat. Cras molestie elementum ullamcorper. Praesent volutpat diam sed mauris dictum fermentum. Morbi non dapibus lacus. Pellentesque tempus lorem nec risus dignissim eget euismod ligula rutrum. In hac habitasse platea dictumst. Suspendisse potenti. Duis eget posuere justo. Suspendisse potenti. | |
Nam vitae libero quis libero cursus luctus. Curabitur mauris leo, vestibulum et luctus quis, sagittis ut nisl. Praesent volutpat nisi nec erat laoreet varius. Integer id enim vel arcu commodo blandit. Suspendisse magna mauris, pharetra vel auctor non, commodo ut libero. Vivamus id dolor nec purus porta iaculis et ac mi. Phasellus iaculis interdum massa a scelerisque. Proin eu mi vel sapien porta tristique. Pellentesque rutrum mollis tellus ac sodales. Suspendisse diam mauris, sodales eget sollicitudin vitae, pharetra quis elit. Donec iaculis risus vitae velit pellentesque vestibulum. Aliquam pharetra laoreet sapien, eget iaculis tellus gravida vitae. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam vel orci et nisi auctor dapibus. Sed vitae sem lacus. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment