Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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]}"
result << word
puts result.join(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.