[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Word Loop (#149

James Gray

12/7/2007 8:45:00 PM

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

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.

46 Answers

Phrogz

12/7/2007 9:27:00 PM

0

On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> wrote:
> 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?

Christian von Kleist

12/7/2007 9:30:00 PM

0

On Dec 7, 2007 3:45 PM, Ruby Quiz <james@grayproductions.net> wrote:
> 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.rub...
>
> 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. :)

Drew Olson

12/7/2007 9:32:00 PM

0

Gavin Kistner wrote:
> On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> 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...
--
Posted via http://www.ruby-....

Christian von Kleist

12/7/2007 9:37:00 PM

0

On Dec 7, 2007 4:32 PM, Drew Olson <olsonas@gmail.com> wrote:
> Gavin Kistner wrote:
> > On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> 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...
> --
> Posted via http://www.ruby-....
>
>

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.

Jason Roelofs

12/7/2007 9:38:00 PM

0

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

On Dec 7, 2007 4:32 PM, Drew Olson <olsonas@gmail.com> wrote:

> Gavin Kistner wrote:
> > On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> 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...
> --
> Posted via http://www.ruby-....
>
> OH! Fixed width font shows it:

$ ruby word_loop.rb yummy
yu
mm

means

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

Hope that helps.

Phrogz

12/7/2007 9:41:00 PM

0

On Dec 7, 2:27 pm, Phrogz <phr...@mac.com> wrote:
> On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> wrote:
>
>
>
> > 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?

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]

Jason Roelofs

12/7/2007 9:41:00 PM

0

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

On Dec 7, 2007 4:37 PM, Jason Roelofs <jameskilton@gmail.com> wrote:

>
> On Dec 7, 2007 4:32 PM, Drew Olson <olsonas@gmail.com> wrote:
>
> > Gavin Kistner wrote:
> > > On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> 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...
> > --
> > Posted via http://www.ruby-....
> >
> > OH! Fixed width font shows it:
>
> $ 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/qu...

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

Phrogz

12/7/2007 9:42:00 PM

0

On Dec 7, 2:37 pm, Christian von Kleist <cvonkle...@gmail.com> wrote:
> On Dec 7, 2007 4:32 PM, Drew Olson <olso...@gmail.com> wrote:
>
>
>
> > Gavin Kistner wrote:
> > > On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> 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...
> > --
> > Posted viahttp://www.ruby-....
>
> 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 :)

Ball, Donald A Jr (Library)

12/7/2007 9:42:00 PM

0

> 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

Alex Fenton

12/7/2007 9:43:00 PM

0

Phrogz wrote:
> On Dec 7, 1:45 pm, Ruby Quiz <ja...@grayproductions.net> wrote:
>> 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

<snip>

> 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