Skip to content

Instantly share code, notes, and snippets.

@ezza
Last active August 29, 2015 14:05
Show Gist options
  • Save ezza/d99faffdd09e8aed20c0 to your computer and use it in GitHub Desktop.
Save ezza/d99faffdd09e8aed20c0 to your computer and use it in GitHub Desktop.
Codeday Friday: Wordloop

Given a single word as input try to find a repeated letter inside of it such that you can loop the text around and reuse that letter. For example:

$ ruby word_loop.rb Mississippi
 i

 p
 p

Mis

 ss

 si

You case see the word starts on line 4, reads to the right, then down, then left, then up again reusing the first i and finishing on line 1.

More examples:

$ ruby word_loop.rb Markham

Ma

ar

hk

or:

$ ruby word_loop.rb yummy

yu

mm

If a loop cannot be made, your code can just print an error message:

$ ruby word_loop.rb Dana

No loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment