[QUIZ] Word Loop (#149)

R

Ruby Quiz

The three rules of Ruby Quiz:

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 Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk 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.
 
P

Phrogz

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

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?
 
D

Drew Olson

Gavin said:
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...
 
J

Jason Roelofs

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I agree, I'm lost as well...

$ ruby word_loop.rb yummy
yu
mm

means

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

Hope that helps.
 
P

Phrogz

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?

Ah, got it.

[y] ->
^ |
| v
[m] <- [m]


[M] -> [a]
^ |
| v
[a] [r]
^ |
| v
[h] <- [k]





^
|
[p]
^
|
[p]
^
|
[M] -> ->
^ |
| v

^ |
| v
<-
 
J

Jason Roelofs

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

$ ruby word_loop.rb yummy
yu
mm

means

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

Hope that helps.

(Sorry for double post)

Look at the actual Ruby Quiz 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
 
P

Phrogz

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 :)
 
B

Ball, Donald A Jr (Library)

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
 
A

Alex Fenton

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
 
S

Sam Larbi

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

The three rules of Ruby Quiz:

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 Quiz by submitting ideas as often as you can:

http://www.rubyquiz.com/

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk 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.

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. :)

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

Yossef Mendelssohn

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?

Ah, got it.

[y] ->
^ |
| v
[m] <- [m]

[M] -> [a]
^ |
| v
[a] [r]
^ |
| v
[h] <- [k]


^
|
[p]
^
|
[p]
^
|
[M] -> ->
^ |
| v

^ |
| v
<-


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

James Gray

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. ;)

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

James Edward Gray II
 
J

James Gray

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 Gray II
 
E

Eugene Kalenkovich

Alex Fenton said:
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

Hmm..
Looks like mississippi is ambiguous, what about

I
P
P
I
MISS
SI

?


EK
 
J

James Gray

Hmm..
Looks like mississippi is ambiguous, what about

I
P
P
I
MISS
SI

?

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 Gray II
 
E

Eugene Kalenkovich

James Gray said:
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 Gray II

I
P
|
P
|
I
|
M -> I -> S -> S
| |
S <- I
 
J

James Gray

I
P
|
P
|
I
|
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 Gray II
 
T

tho_mica_l

Looks like mississippi is ambiguous, what about
I don't see how this works with 90 degree turns in a clockwise
direction, as mentioned earlier in this thread.

I get 5 possible solutions for Mississippi. Some solutions could be
considered redundant though.

Is the task rather to find possible loops (5 solutions) or letters at
possible intersections (3 solutions)?

thomas.
 
J

James Gray

I get 5 possible solutions for Mississippi. Some solutions could be
considered redundant though.

Is the task rather to find possible loops (5 solutions) or letters at
possible intersections (3 solutions)?

The task is to draw one of the possible loops.

James Edward Gray II
 
E

Eric I.

I presume allowing multiple overlaps is valid (if not encouraged?).
For example, "absolvable" can make use of three overlaps:

......
..abs.
..vlo.
...e..
......

And "chincherinchee", which is a South African perennial, can be
arranged with seven overlaps. I'll leave it as a mini-challenge you
can try....

Eric

====

On-site, hands-on Ruby training is available from http://LearnRuby.com
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top