Skip to content

Instantly share code, notes, and snippets.

@jescalan
Created April 26, 2012 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jescalan/2503610 to your computer and use it in GitHub Desktop.
Save jescalan/2503610 to your computer and use it in GitHub Desktop.
Sensical sentence scrambler
# ---------------------------
# 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