Created
April 26, 2012 22:15
-
-
Save jescalan/2503610 to your computer and use it in GitHub Desktop.
Sensical sentence scrambler
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
# --------------------------- | |
# Sensical Sentence Scrambler | |
# --------------------------- | |
# This short program takes any word longer than three characters and randomly shuffles all the characters | |
# except for the first and the last. Strangely enough, sentences are still quite readable like this. | |
# **Usage** | |
# Save the file on your computer as 'scramble.rb'. | |
# From the command line, run `ruby scramble.rb "Here's my sentence!"`, and it should output | |
# the scrambled version below. | |
# **Support** | |
# If you are having trouble with this, have questions about how it works, or anything else, feel free | |
# to email me at jeff.escalante@carrotcreative.com | |
sentence = ARGV.first.split(" ") | |
result = [] | |
sentence.each do |word| | |
if word.length > 3 | |
result << "#{word[0]}#{word[1..word.length-2].split("").shuffle.join()}#{word[word.length-1]}" | |
else | |
result << word | |
end | |
end | |
puts result.join(" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment