Word Loop (#149)

The three rules of Ruby Q.:

  1. Please do not post any solutions or spoiler discussion for this quiz
    until
    48 hours have passed from the time on this message.

  2. Support Ruby Q. by submitting ideas as often as you can:

http://www.rubyquiz.com/

  1. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps
everyone
on Ruby T. follow the discussion. Please reply to the original quiz
message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Here’s a fun little challenge from the Educational Computing
Organization of
Ontario.

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

or:

$ 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.

On Dec 7, 1:45 pm, Ruby Q. [email protected] wrote:

    yu
    mm

Maybe it’s because it’s a Friday afternoon, but I don’t understand the
quiz problem. Could someone who understands this try explaining it
(without, of course, discussing any code or even pseudo-code to
approach it).

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

Gavin K. wrote:

On Dec 7, 1:45 pm, Ruby Q. [email protected] wrote:

    yu
    mm

Maybe it’s because it’s a Friday afternoon, but I don’t understand the
quiz problem. Could someone who understands this try explaining it
(without, of course, discussing any code or even pseudo-code to
approach it).

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

I agree, I’m lost as well…

On Dec 7, 2007 3:45 PM, Ruby Q. [email protected] wrote:

that you can loop the text around and reuse that letter. For example:

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

    $ ruby word_loop.rb Dana
    No loop.

I read this quiz on the mailing list in GMail and I didn’t get this
challenge at first. Then I realized that you need to imagine the
examples in a fixed-width font.

Just FYI. :slight_smile:

On Dec 7, 2007 4:32 PM, Drew O. [email protected] wrote:

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

I agree, I’m lost as well…

Posted via http://www.ruby-forum.com/.

OH! Fixed width font shows it:

$ ruby word_loop.rb yummy
yu
mm

means

y → u
/\ /
| |
m<- m

Hope that helps.

On Dec 7, 2007 4:32 PM, Drew O. [email protected] wrote:

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

I agree, I’m lost as well…

Posted via http://www.ruby-forum.com/.

I guarantee that if you paste the examples into an editor with a
fixed-width font you’ll get it immediately. Try vi/emacs/pico/nano
(or Notepad if you’re in Windows, I guess?) The Mississippi one is
the key.

On Dec 7, 2007 4:37 PM, Jason R. [email protected] wrote:

quiz problem. Could someone who understands this try explaining it
OH! Fixed width font shows it:
m<- m

Hope that helps.

(Sorry for double post)

Look at the actual Ruby Q. page for this quiz:

http://www.rubyquiz.com/quiz149.html

For the Mississippi example, start with M and follow the spelling of the
word. You’ll go right, down, left, and up, reusing one of the 'i’s

Jason

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

Imagine your word as a string. You’re trying to make a knot, just a fold
really, in the string, and the bit where the string folds over itself is
a repeated letter.

  • donald

On Dec 7, 2:37 pm, Christian von Kleist [email protected] wrote:

Maybe it’s because it’s a Friday afternoon, but I don’t understand the

I guarantee that if you paste the examples into an editor with a
fixed-width font you’ll get it immediately. Try vi/emacs/pico/nano
(or Notepad if you’re in Windows, I guess?) The Mississippi one is
the key.

I guarantee you’re wrong, only because I was reading it with a fixed-
width font, both in email and on comp.lang.ruby. The pattern just
didn’t jump out at first.

But I got it now, thanks :slight_smile:

Quoth Drew O.:

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

I agree, I’m lost as well…

They mean make a counter-clockwise “loop” of letters.

Spaced out more (in a fixed width font), this looks like:

start -> ‘y’ -> ‘u’

       ^      v

      'm' <- 'm'

= “yummy”.

HTH,

On Dec 7, 2:27 pm, Phrogz [email protected] wrote:

     p

I’ve looked over those examples a few times and I’m totally baffled.
What does “loop the text around and reuse that letter” mean?

Ah, got it.

[y] → [u]
^ |
| v
[m] ← [m]

[M] → [a]
^ |
| v
[a] [r]
^ |
| v
[h] ← [k]

   [i]
    ^
    |
   [p]
    ^
    |
   [p]
    ^
    |

[M] → [i] → [s]
^ |
| v
[s] [s]
^ |
| v
[s] ← [i]

On Dec 7, 2007 3:30 PM, Christian von Kleist [email protected]
wrote:

     p
    hk
    No loop.

I read this quiz on the mailing list in GMail and I didn’t get this
challenge at first. Then I realized that you need to imagine the
examples in a fixed-width font.

Just FYI. :slight_smile:

I wish I read read that before I wasted too much time staring at the
examples. Thanks.

Phrogz wrote:

     si

Maybe it’s because it’s a Friday afternoon, but I don’t understand the
quiz problem. Could someone who understands this try explaining it
(without, of course, discussing any code or even pseudo-code to
approach it).

It took me a few monents too. The letters have to be arranged in a grid
so that by moving one square at a time, the word is spelled out. The
test is to see whether the word can be spelled out by, at some point,
moving over the same grid square twice.

I’m taking from the MISSISSIPI example that moves have to be in the same
direction as the last move, or at a 90 degree angle to it, otherwise
it could be spelled by moving up back onto “S” after the second “I” in
the bottom right.

a

On Dec 7, 3:45 pm, Phrogz [email protected] wrote:

     i
    ar

(without, of course, discussing any code or even pseudo-code to
[m] ← [m]
^
[s] [s]
^ |
| v
[s] ← [i]

Very nice visual explanation.

I stared at this quiz for a while and simply could not understand. It
was only when I was about to post a reply begging for an explanation
that I got it.

It’s clear to me now I should’ve posted a reply with the explanation
instead of just moving on.

On Dec 7, 2007, at 3:50 PM, Alex F. wrote:

I’m taking from the MISSISSIPI example that moves have to be in the
same direction as the last move, or at a 90 degree angle to it

Correct, and turns need to be clockwise.

James Edward G. II

“Alex F.” [email protected] wrote in message
news:[email protected]

    Mis

It took me a few monents too. The letters have to be arranged in a grid so

Hmm…
Looks like mississippi is ambiguous, what about

I
P
P
I
MISS
SI

?

EK

On Dec 7, 2007, at 11:40 PM, Eugene K. wrote:

   $ ruby word_loop.rb Mississippi

the
the same grid square twice.

?

I don’t see how this works with 90 degree turns in a clockwise
direction, as mentioned earlier in this thread.

Of course, I’m never one to discourage experimentation.

James Edward G. II

On Dec 7, 2007, at 3:30 PM, Phrogz wrote:

Maybe it’s because it’s a Friday afternoon, but I don’t understand the
quiz problem. Could someone who understands this try explaining it
(without, of course, discussing any code or even pseudo-code to
approach it).

I apologize for all of the confusion. I had trouble explaining this
one, which is why I pretty much punted and showed a bunch of
examples. :wink:

There are some better visual descriptions in this thread now though,
so hopefully everyone gets it now.

James Edward G. II

“James G.” [email protected] wrote in message
news:[email protected]

MISS

      I
      P
      |
      P
      |
      I
      |

M → I → S → S
| |
S ← I

On Dec 8, 2007, at 11:10 AM, Eugene K. wrote:

P

     |

M -> I -> S -> S
| |
S <- I

Ah, I see it now. Sorry. The letters didn’t line up for me correctly
in the previous message.

You are right, that works too.

James Edward G. II