Forum: Ruby Text Munger (#76)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 14:35
(Received via mailing list)
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.

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

by Matthew Moss

	Now terhe is a fnial rseaon I thnik that Jsues syas, "Lvoe your
	emneies." It is tihs: taht love has wtiihn it a remvpidtee pewor. And
	three is a pwoer three taht eellvtanuy tfranrmsos idvlinaidus. Taht's
	why Juess syas, "Love your emeeins."  Bsceaue if you hate your
	enmeies, you have no way to reedem and to tarfnrsom your eenmeis. But
	if you love yuor emienes, you wlil decsiovr that at the vrey root of
	love is the pwoer of rdoemptein. You just keep loinvg pepole and keep
	lnivog tehm, even tgouhh they're mteitnsiarg you. Hree's the porsen
	who is a nhoeigbr, and tihs psoren is dnoig simhoetng wrong to you and
	all of that. Just keep being fnrdliey to that preosn. Keep liovng
	them. Don't do atnynhig to earsmrbas tehm. Just keep lvonig them, and
	they can't stand it too long. Oh, they raect in mnay ways in the
	bineningg. They react wtih brnetitess beucase they're mad bauesce you
	lvoe them like that. Tehy raect wtih gluit flegines, and setioemms
	they'll hate you a lltite more at that tinoiasrtn piroed, but just
	keep lvniog them. And by the poewr of your love tehy will beark down
	uendr the load. That's lvoe, you see. It is retpmevide, and tihs is
	why Juess says love. Trehe's shimeotng aubot love that blidus up and
	is cavrtiee. Trehe is stmeonihg aubot hate that tares dwon and is
	disettvrcue. So lvoe your eenmeis.

On first glance, the above may appear to be gibberish, but you may find
that you
can actually read this portion of a speech from Dr Martin Luther King
Jr.  The
brain has an amazing capacity to compensate for things that aren't quite
right,
and one study has shown that when the first and last letters of words
are left
alone but those in the middle are scrambled, the text is often still
quite
comprehensible.

Your task for this quiz, then, is to take a text as input and output the
text in
this fashion. Scramble each word's center (leaving the first and last
letters of
each word intact). Whitespace, punctuation, numbers -- anything that
isn't a
word -- should also remain unchanged.
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-04-21 14:59
(Received via mailing list)
Hi --

On Fri, 21 Apr 2006, Ruby Quiz wrote:

> 	who is a nhoeigbr, and tihs psoren is dnoig simhoetng wrong to you and
> 	disettvrcue. So lvoe your eenmeis.
> each word intact). Whitespace, punctuation, numbers -- anything that isn't a
> word -- should also remain unchanged.

Question:

Given a word like "there's" or "that's", does the letter before the
apostrophe count as a "last" letter?  In other words, could "that's"
become "ttha's"?

In the example above, there's no case where that letter gets
scrambled.  It's possible that that's coincidence, but it doesn't look
like it.


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 Florian GroÃ? (Guest)
on 2006-04-21 15:12
(Received via mailing list)
Ruby Quiz wrote:

> Your task for this quiz, then, is to take a text as input and output the text in
> this fashion. Scramble each word's center (leaving the first and last letters of
> each word intact). Whitespace, punctuation, numbers -- anything that isn't a
> word -- should also remain unchanged.

What about writing an unscrambler? Could that also be done for this quiz
or might that be next week's task? :)
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 15:15
(Received via mailing list)
On Apr 21, 2006, at 8:10 AM, Florian Groß wrote:

> What about writing an unscrambler? Could that also be done for this
> quiz or might that be next week's task? :)

It's not part of the challenge this week or next, but you know I'm
always for setting your own goals.  :)

James Edward Gray II
A16652fd5d83c0473bd1e39d9a2117a6?d=identicon&s=25 Dirk Meijer (Guest)
on 2006-04-21 16:17
(Received via mailing list)
this quiz is probably easier than usually, as, for the first time
ever, i felt up to it, and created a solution in not so much time.
i'll be posting it in 48 hrs ;-)
greetings, Dirk.

2006/4/21, James Edward Gray II <james@grayproductions.net>:
Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-21 16:30
(Received via mailing list)
On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} this quiz is probably easier than usually, as, for the first time
} ever, i felt up to it, and created a solution in not so much time.
} i'll be posting it in 48 hrs ;-)

Yes, I sent my solution directly to James. He or I will repost it on
Sunday.

} greetings, Dirk.
--Greg

} 2006/4/21, James Edward Gray II <james@grayproductions.net>:
} > On Apr 21, 2006, at 8:10 AM, Florian Gro? wrote:
} >
} > > Ruby Quiz wrote:
} > >
} > >> Your task for this quiz, then, is to take a text as input and
} > >> output the text in
} > >> this fashion. Scramble each word's center (leaving the first and
} > >> last letters of
} > >> each word intact). Whitespace, punctuation, numbers -- anything
} > >> that isn't a
} > >> word -- should also remain unchanged.
} > >
} > > What about writing an unscrambler? Could that also be done for
this
} > > quiz or might that be next week's task? :)
} >
} > It's not part of the challenge this week or next, but you know I'm
} > always for setting your own goals.  :)
} >
} > James Edward Gray II
} >
}
}
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-04-21 16:48
(Received via mailing list)
> Given a word like "there's" or "that's", does the letter before the
> apostrophe count as a "last" letter?  In other words, could "that's"
> become "ttha's"?
>
> In the example above, there's no case where that letter gets
> scrambled.  It's possible that that's coincidence, but it doesn't look
> like it.

Do it whichever way you like it...

I don't know what the study said about contractions, if anything.
Personally, I think I would consider the parts before and after as
separate words, which would be slightly less scrambled, but my
intuition (which could be wrong) says that counting it as one whole
word might throw off legibility more than expected.
A5ae84b6af0a67cdea1db87706a11a6f?d=identicon&s=25 Yoann Guillot (Guest)
on 2006-04-21 17:16
(Received via mailing list)
On Fri, Apr 21, 2006 at 11:27:08PM +0900, Gregory Seidman wrote:
> On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
> } this quiz is probably easier than usually, as, for the first time
> } ever, i felt up to it, and created a solution in not so much time.
> } i'll be posting it in 48 hrs ;-)
>

Mmh, for my first participation, i get a quizz solved by a one-liner.
And still i discover things :)

Yoann
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-04-21 17:25
(Received via mailing list)
One line?
Hmmm....  Methinks I need to go back and reexamine my own solution.  :)
Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-21 17:31
(Received via mailing list)
On Sat, Apr 22, 2006 at 12:24:06AM +0900, Matthew Moss wrote:
} One line?
} Hmmm....  Methinks I need to go back and reexamine my own solution.
:)

Heh. I decided against making it a single line for readability purposes.
Yeah, it can be done in a single line, but it will be less readable and
less efficient.

--Greg

} On 4/21/06, Yoann Guillot <john-rubytalk@ofjj.net> wrote:
} > On Fri, Apr 21, 2006 at 11:27:08PM +0900, Gregory Seidman wrote:
} > > On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} > > } this quiz is probably easier than usually, as, for the first
time
} > > } ever, i felt up to it, and created a solution in not so much
time.
} > > } i'll be posting it in 48 hrs ;-)
} > >
} >
} > Mmh, for my first participation, i get a quizz solved by a
one-liner.
} > And still i discover things :)
} >
} > Yoann
} >
} >
}
}
A16652fd5d83c0473bd1e39d9a2117a6?d=identicon&s=25 Dirk Meijer (Guest)
on 2006-04-21 17:47
(Received via mailing list)
my attempts to one-line it failed, and since it was now three lines
anyway, i decided to expand the entire thing for readability.
greetings, Dirk.

2006/4/21, Gregory Seidman <gsslist+ruby@anthropohedron.net>:
Ced5fff44ff8929fc974012ea108b284?d=identicon&s=25 Sergey Volkov (Guest)
on 2006-04-21 19:29
(Received via mailing list)
Looks like this Quiz is too easy.
May I suggest smthng to make it more challenging?
1. Vowel can be exchanged with vowel only,
    consonant can be exchanged with consonant only;
2. Parameterize the solution, so that set of exchangeable characters
classes
    can be specified (optionally);
Sorry, if I'm breaking the Quiz rules.

Happy Rubying,
Sergey

----- Original Message -----
From: "Matthew Moss" <matthew.moss.coder@gmail.com>
Sent: Friday, April 21, 2006 11:24 AM


One line?
Hmmm....  Methinks I need to go back and reexamine my own solution.  :)
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 19:29
(Received via mailing list)
On Apr 21, 2006, at 9:27 AM, Gregory Seidman wrote:

> On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
> } this quiz is probably easier than usually, as, for the first time
> } ever, i felt up to it, and created a solution in not so much time.
> } i'll be posting it in 48 hrs ;-)
>
> Yes, I sent my solution directly to James.

Random playing around...

Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Atchtaed is my
résumé.Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Acaehttd is my
résumé.Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Atceahtd is my
résumé.Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
Ahaecttd is my
résumé.
James Edward Gray II
Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-04-21 19:35
(Received via mailing list)
On Sat, Apr 22, 2006 at 02:28:48AM +0900, James Edward Gray II wrote:
} On Apr 21, 2006, at 9:27 AM, Gregory Seidman wrote:
}
} >On Fri, Apr 21, 2006 at 11:16:38PM +0900, Dirk Meijer wrote:
} >} this quiz is probably easier than usually, as, for the first time
} >} ever, i felt up to it, and created a solution in not so much time.
} >} i'll be posting it in 48 hrs ;-)
} >
} >Yes, I sent my solution directly to James.
}
} Random playing around...
}
} Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
} Atchtaed is my r?sum?.
} Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
} Acaehttd is my r?sum?.
} Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
} Atceahtd is my r?sum?.
} Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
} Ahaecttd is my r?sum?.

Yeah, it treats accented characters as punctuation. The two regexes
could
be changed to handled accented characters, but I leave that as an
exercise
for the reader <g>.

} James Edward Gray II
--Greg
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-04-21 19:35
(Received via mailing list)
Hi --

On Fri, 21 Apr 2006, Matthew Moss wrote:

> I don't know what the study said about contractions, if anything.
> Personally, I think I would consider the parts before and after as
> separate words, which would be slightly less scrambled, but my
> intuition (which could be wrong) says that counting it as one whole
> word might throw off legibility more than expected.

I guess if the part after the ' isn't going to be mixed in with the
part before (which I definitely don't think it should be), then the
part before does really count as a word, so its first and last letters
would be preserved.

   there's   =>  terhe's  but not   theer's


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 19:35
(Received via mailing list)
On Apr 21, 2006, at 12:26 PM, Sergey Volkov wrote:

> Looks like this Quiz is too easy.

I'll tell you what I told David Black off-list:

One of the easiest ones we have ever done, yes, and I think that's a
good thing.

Programmers of all skill levels follow the quiz and it's a common
complaint that all the problems are "advanced" material.  I'm trying
to get better about that.

> May I suggest smthng to make it more challenging?
> 1. Vowel can be exchanged with vowel only,
>    consonant can be exchanged with consonant only;
> 2. Parameterize the solution, so that set of exchangeable
> characters classes
>    can be specified (optionally);

The Ruby Quizzes are ideas.  If you need to add this to challenge
yourself, go for it.  We won't come and take your keyboard away, I
promise.  ;)

James Edward Gray II
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 19:38
(Received via mailing list)
On Apr 21, 2006, at 12:33 PM, Gregory Seidman wrote:

> }
>
> Yeah, it treats accented characters as punctuation. The two regexes
> could
> be changed to handled accented characters, but I leave that as an
> exercise
> for the reader <g>.

Really?  With everyone bragging about how easy this quiz is?  :D

James Edward Gray II
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-04-21 19:41
(Received via mailing list)
On 4/21/06, Sergey Volkov <gm.vlkv@gmail.com> wrote:
> Looks like this Quiz is too easy.
> May I suggest smthng to make it more challenging?
> 1. Vowel can be exchanged with vowel only,
>     consonant can be exchanged with consonant only;
> 2. Parameterize the solution, so that set of exchangeable characters classes
>     can be specified (optionally);
> Sorry, if I'm breaking the Quiz rules.

James (being the host) can put forth his own comments on the goals of
the quiz. But I think there's plenty of room for both simple and
mildly complex problems; the simpler ones especially give newbies some
fun.

Feel free to add more to your own code if you like. Since I'll be
writing the summary, I'll be looking at all the solutions and will
comment on extras as I find them interesting, appropriate, etc.
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2006-04-21 19:44
(Received via mailing list)
On 4/21/06, James Edward Gray II <james@grayproductions.net> wrote:
>
> Random playing around...
>
> Neo:~/Desktop$ ruby gregory_seidmans_solution.rb test_document.txt
> Atchtaed is my résumé.

My solution also did not munge résumé. Seems that \w does not include
accented characters, so résumé becomes the words r and sum, which are
too small to be munged. Is there something one can require to make \w
include non-Latin characters?

Ryan
Be3f276f615e29a7c605efd1d3bc3cae?d=identicon&s=25 Mike (Guest)
on 2006-04-21 19:57
(Received via mailing list)
> Random playing around...
>
> Neo:~/Desktop$ ruby gregory_seidmans_solution.rb
> test_document.txt Atchtaed is my résumé.
> Neo:~/Desktop$ ruby gregory_seidmans_solution.rb
> test_document.txt Acaehttd is my résumé.
> Neo:~/Desktop$ ruby gregory_seidmans_solution.rb
> test_document.txt Atceahtd is my résumé.
> Neo:~/Desktop$ ruby gregory_seidmans_solution.rb
> test_document.txt Ahaecttd is my résumé.
>

Keep in mind that longer words with a purely randomly munged inside will
not
be "readable".

"Ahaecttd" takes effort to figure out that it was "Attached" before the
munging.

The physical process of munging is very easy (as we've seen from people
reporting one line results), but modeling something that'll also produce
"readable" results for all lengths of words is a bit more challenging.
:)

-M
A16652fd5d83c0473bd1e39d9a2117a6?d=identicon&s=25 Dirk Meijer (Guest)
on 2006-04-21 20:46
(Received via mailing list)
you know, it's great that this quiz is easy! when i had read the other
ones, i'd feel hopeless and most of the times, i wouldn't even try,
but with this quiz, i knew i could come up with a solution, which made
me study the MatchData class, which'll come in handy for sure some
day!
greetings, Dirk.

2006/4/21, Mike <ruby@crazyted.com>:
49ab3ce5a4922b4747d1d6f330784629?d=identicon&s=25 Jake McArthur (Guest)
on 2006-04-21 20:52
(Received via mailing list)
My first participation in Ruby Quiz, and it has to be easy. That
said, I must really be missing something because some of you guys are
mentioning one-liners, and mine is 26 lines. Maybe it's because I
made mine highly abstracted, but I still don't really see how to do
this in one line.

- Jake McArthur
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2006-04-21 21:11
(Received via mailing list)
Strictly speaking, any Ruby code can be made into one line with
liberal use of the semi-colon (;). It would just be an extremely long
line!

My full, nicely abstracted solution for this quiz is 36 lines
(including empty lines), but I also wrote a somewhat obfuscated
one-line version which is 104 characters. But it is missing some of
the features of the full one. But overall it solves the quiz. It is
probably possible to make an even shorter version.

Ryan
49ab3ce5a4922b4747d1d6f330784629?d=identicon&s=25 Jake McArthur (Guest)
on 2006-04-21 21:32
(Received via mailing list)
When I say "one-liner," I'm excluding cases of using semicolons. In
code, I consider semicolons to be line breaks.
;-)

- Jake McArthur
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-21 21:48
(Received via mailing list)
On Sat, 22 Apr 2006, Ryan Leavengood wrote:

> Ryan
my fully oo version is 12 lines and only 40 words.

i went golfing and got one line : 96 chars

let the games begin ;-)

-a
5c841628b56df3a68984986e9f095d01?d=identicon&s=25 Andrew Johnson (andrew)
on 2006-04-21 22:14
unknown wrote:

> my fully oo version is 12 lines and only 40 words.
>
> i went golfing and got one line : 96 chars
>
> let the games begin ;-)

As a script, my one-liner is down to 70 chars including
the newline. It can be shortened a bit as a command-liner.
:-)

andrew
81d609425e306219d54d793a0ad98bce?d=identicon&s=25 Matthew Moss (Guest)
on 2006-04-21 22:18
(Received via mailing list)
On 4/21/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> > probably possible to make an even shorter version.
> >
> > Ryan
>
>
> my fully oo version is 12 lines and only 40 words.
>
> i went golfing and got one line : 96 chars
>
> let the games begin ;-)


Oh great...  Now I have to read these solutions when writing up a
summary.

(Suddenly, I have recollections of my time as a teaching assistant,
having to read mountains of pages of Pascal code written by freshman
newbie programmers....  <shudder>.)
171a9b5755cdb090e0c2b3c20a521fbc?d=identicon&s=25 Phil Hagelberg (Guest)
on 2006-04-21 22:30
(Received via mailing list)
ara.t.howard@noaa.gov writes:

> i went golfing and got one line : 96 chars

86 chars after removing all the extraneous spaces. Of course, now it
looks like the Camping source.

Not bad for my first Ruby Quiz.

I have to say I am in favor of making quizzes of varying
difficulty. Like some others here, I've been a bit intimidated by all
the heavy meta stuff in the past, but with varying difficulty I can
work my way up to the tough stuff.

-Phil Hagelberg
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2006-04-21 22:37
(Received via mailing list)
From: "Andrew Johnson" <ajohnson@cpan.org>
>
> As a script, my one-liner is down to 70 chars including
> the newline. It can be shortened a bit as a command-liner.
> :-)

Wow, nice.  Does that include the restriction in the quiz rules that
numbers have to be left alone?  Or does your solution rearrange
both numbers and letters?


Regards,

Bill
4b174722d1b1a4bbd9672e1ab50c30a9?d=identicon&s=25 Ryan Leavengood (Guest)
on 2006-04-21 22:43
(Received via mailing list)
On 4/21/06, Phil Hagelberg <phil@hagelb.org> wrote:
>
> I have to say I am in favor of making quizzes of varying
> difficulty. Like some others here, I've been a bit intimidated by all
> the heavy meta stuff in the past, but with varying difficulty I can
> work my way up to the tough stuff.

I agree with you, and I'm very experienced with Ruby. In most cases
the toughness is just in the problem itself, not even the Ruby aspects
of it. I don't usually have time to solve those, but problems like
this which can be done in an hour or so are fun and worthwhile. Plus
all the various solutions usually provide some nice insights (even
from newbies!)

If a problem is so tough that it is even hard to read a solution, let
alone code one, I think the value of the quiz is diminished some. So
I'd suggest we try to keep most quizzes on the easy side and throw in
a few complicated ones now and then.

Actually in hindsight this seems to be the pattern, so keep it up! ;)

Ryan
F1a324b7cf0e3ec13a3490240b5a8321?d=identicon&s=25 PerlyGates (Guest)
on 2006-04-21 22:52
> i went golfing and got one line : 96 chars

For reference:

<pre>perl -pe
's/(?<=\w)\w+(?=\w)/join"",sort{int(rand(3)-2)}split"",$&/eg'</pre>

(65 characters)
49ab3ce5a4922b4747d1d6f330784629?d=identicon&s=25 Jake McArthur (Guest)
on 2006-04-21 22:55
(Received via mailing list)
Well, I can make one in ~60 chars that rearranges both. Still working
on getting <70 for not rearranging numbers....

- Jake McArthur
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-21 23:11
(Received via mailing list)
On Apr 21, 2006, at 3:34 PM, Bill Kelly wrote:

> From: "Andrew Johnson" <ajohnson@cpan.org>
>>
>> As a script, my one-liner is down to 70 chars including
>> the newline. It can be shortened a bit as a command-liner.
>> :-)
>
> Wow, nice.  Does that include the restriction in the quiz rules that
> numbers have to be left alone?  Or does your solution rearrange
> both numbers and letters?

I'm still waiting for someone to show off their solution properly
handling the trivial (multi-byte) example I showed earlier...  :)

James Edward Gray II
49ab3ce5a4922b4747d1d6f330784629?d=identicon&s=25 Jake McArthur (Guest)
on 2006-04-21 23:23
(Received via mailing list)
Working on my short version. 62 chars long and works for your
example, but still trying to get <70 with it working correctly with
digits.

  -Jake McArthur
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-04-22 01:05
(Received via mailing list)
Hi --

On Sat, 22 Apr 2006, PerlyGates wrote:

>> i went golfing and got one line : 96 chars
>
> For reference:
>
> <pre>perl -pe
> 's/(?<=\w)\w+(?=\w)/join"",sort{int(rand(3)-2)}split"",$&/eg'</pre>
>
> (65 characters)

But \w includes underscore.  I think punctuation is supposed to remain
unscrambled, isn't it?  And numbers likewise.


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!
Ddbfebb47432f6599da361df6a135c7c?d=identicon&s=25 Adam Shelly (Guest)
on 2006-04-22 03:56
(Received via mailing list)
On 4/21/06, Ruby Quiz <james@grayproductions.net> wrote:

> Your task for this quiz, then, is to take a text as input and output the text in
> this fashion. Scramble each word's center (leaving the first and last letters of
> each word intact). Whitespace, punctuation, numbers -- anything that isn't a
> word -- should also remain unchanged.
>

I know everyone here is Nice(tm), so I'm sure this is not the
intent...  but between this quiz and the Markov chain one, it seems we
are building a set of utilities perfect for generating those  'Re:
PHARmudMACY'
spam emails selling 'vigara' and such that have been sneaking through
my spam filter at work recently...



-Adam
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-04-22 04:02
(Received via mailing list)
Hi --

On Sat, 22 Apr 2006, Adam Shelly wrote:

> are building a set of utilities perfect for generating those  'Re:
> PHARmudMACY'
> spam emails selling 'vigara' and such that have been sneaking through
> my spam filter at work recently...

Maybe we can use the techniques to filter those messages out :-)


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!
Be3f276f615e29a7c605efd1d3bc3cae?d=identicon&s=25 Mike (Guest)
on 2006-04-22 04:02
(Received via mailing list)
I've been able to condense mine to about 15 lines - I'm always impressed
that you guys can shrink stuff down so far... I just wish I could
understand
them after they're posted to the group! :)

-M
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-22 06:07
(Received via mailing list)
On Apr 21, 2006, at 8:55 PM, Adam Shelly wrote:

>
> I know everyone here is Nice(tm), so I'm sure this is not the
> intent...  but between this quiz and the Markov chain one, it seems we
> are building a set of utilities perfect for generating those  'Re:
> PHARmudMACY'
> spam emails selling 'vigara' and such that have been sneaking through
> my spam filter at work recently...

I vote we assume the best instead of the worst.

James Edward Gray II
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-04-22 12:31
(Received via mailing list)
On Sat, 2006-04-22 at 06:09 +0900, James Edward Gray II wrote:
> > both numbers and letters?
>
> I'm still waiting for someone to show off their solution properly
> handling the trivial (multi-byte) example I showed earlier...  :)

$ ./munger.rb test.txt
Attehcaed is my résmué.
$ ./munger.rb test.txt
Atthaceed is my réumsé.
$ ./munger.rb test.txt
Attacheed is my rémsué.
$ ./munger.rb test.txt
Attcaehed is my rémusé.
$ ./munger.rb test.txt
Attecahed is my rémsué.

It's four lines though.
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-04-22 13:09
(Received via mailing list)
On Sat, 2006-04-22 at 19:28 +0900, Ross Bamford wrote:
> > > numbers have to be left alone?  Or does your solution rearrange
> > > both numbers and letters?
> >
> > I'm still waiting for someone to show off their solution properly
> > handling the trivial (multi-byte) example I showed earlier...  :)
>
> $ ./munger.rb test.txt
> Attehcaed is my résmué.

(Sorry for the noise) - the test text used there doesn't go too well
with my solution, which limits how much of a word is rearranged. This is
a better example:

[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La viiosn euroénepne strégiatque
[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La vioisn eurpeénone strgaéitque
[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La vioisn eurenopéne strtagiéque
[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La vision eurpeéonne stréigatque
[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La vision euréonpene strgtéiaque
[rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
La visoin eureéonpne striagtéque

(from La vision européenne stratégique)
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-22 16:33
(Received via mailing list)
On Apr 22, 2006, at 5:28 AM, Ross Bamford wrote:

> $ ./munger.rb test.txt
> Attehcaed is my résmué.
> $ ./munger.rb test.txt
> Atthaceed is my réumsé.
> $ ./munger.rb test.txt
> Attacheed is my rémsué.
> $ ./munger.rb test.txt
> Attcaehed is my rémusé.
> $ ./munger.rb test.txt
> Attecahed is my rémsué.

Why are the e's not moving?

James Edward Gray II
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-04-22 17:53
(Received via mailing list)
On Sat, 2006-04-22 at 23:31 +0900, James Edward Gray II wrote:
> > $ ./munger.rb test.txt
> > Attecahed is my rémsué.
>
> Why are the e's not moving?

My solution scrambles only part of the inside of the word, depending on
the word length, and favours keeping more from the start of the word. So
with this example it's taking the six letter 'rémsué' and deciding to
scramble 3 letters, 'msu' (remains after we take two from the start, one
from the end). So with that input, the e's wouldn't be touched.

I just didn't think about that before I posted - the second output I
posted showed some longer accented words with the e's moving around
properly :).
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-22 17:59
(Received via mailing list)
Ross Bamford wrote:

> [rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
> La vision euréonpene strgtéiaque
> [rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
> La visoin eureéonpne striagtéque
>
> (from La vision européenne stratégique)
>

The pattern, "eu??????ne str?????que" is constant in your results.

--

Ray
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-04-22 18:08
(Received via mailing list)
On Sun, 2006-04-23 at 00:56 +0900, Ray Baxter wrote:
> > [rosco@jukebox text-munger-76]$ ./munger.rb test2.txt
>
Well, that's a question of more random, or more readable. A good point
was raised about longer words becoming unrecognisable when just randomly
scrambled...

OTOH If we're doing random scrambling, leaving only first and last
letter I think I can get back down to two lines...

What's everyone else doing?
E2148159cc245f2335bb9f333c5ce449?d=identicon&s=25 Alex Barrett (Guest)
on 2006-04-22 18:24
(Received via mailing list)
"text".gsub(/\B(\w{2,})\B/) { |s| s.length.times { |i| r =
rand(s.length);
s[i], s[r] = s[r], s[i] }; s }

It is one line, but it does have a couple of semi-colons.
F1a324b7cf0e3ec13a3490240b5a8321?d=identicon&s=25 PerlyGates (Guest)
on 2006-04-22 18:25
unknown wrote:
> But \w includes underscore.  I think punctuation is supposed to remain
> unscrambled, isn't it?  And numbers likewise.

Point taken.

perl -pe
's/(?<=[a-z])[a-z]+(?=[a-z])/join"",sort{rand>0.5}split"",$&/egi'

(69 chars)
E2148159cc245f2335bb9f333c5ce449?d=identicon&s=25 Alex Barrett (Guest)
on 2006-04-22 18:40
(Received via mailing list)
Use negated word boundaries (\B) instead of the lookarounds to lose a
few
characters.
F1a324b7cf0e3ec13a3490240b5a8321?d=identicon&s=25 PerlyGates (Guest)
on 2006-04-22 19:35
Alex Barrett wrote:
> Use negated word boundaries (\B) instead of the lookarounds to lose a
> few
> characters.

Thanks.  And character twiddling rather than sort:

    perl -pe 's/\B([a-z])([a-z])\B/rand>.5?$1.$2:$2.$1/egi'
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2006-04-22 19:42
(Received via mailing list)
On 22-Apr-06, at 1:35 PM, PerlyGates wrote:

> Alex Barrett wrote:
>> Use negated word boundaries (\B) instead of the lookarounds to lose a
>> few
>> characters.

Doesn't \B bring back the problems with _ ?

Mike

>
> Thanks.  And character twiddling rather than sort:
>
>     perl -pe 's/\B([a-z])([a-z])\B/rand>.5?$1.$2:$2.$1/egi'
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

--

Mike Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
86216345f72b5c078098b6597b232ee4?d=identicon&s=25 Himadri Choudhury (Guest)
on 2006-04-23 11:48
(Received via mailing list)
Here's my solution.

Usage : scramble.rb <text_file>

I made 3 attempts.

1)
print ARGF.read.gsub!(/\B[a-z]+\B/) {|x| x.split('').sort_by{rand}.join}

Here I use gsub to find all the words. Use split to convert strings into
arrays. And then use the sort_by{rand} to scramble the arrays. And
finally
use join to convert the array back to a string.
I'm assuming that words don't have upper case letters in the middle, so
that
I can get away with [a-z].

2)
print ARGF.read.gsub!(/\B[a-z]+\B/) {|x| x.unpack
('c*').sort_by{rand}.pack('c*')}

I found this method of converting strings to and from arrays to be
faster.
I'm not sure what the standard idiom for doing this is. But, I'm sure
I'll
learn after seeing other people's solutions ;)

3 If sort_by{rand} does what I think it does, it probably has a bias
when
the rand function returns the same value. So, this is my third
implementation:

print ARGF.read.gsub!(/\B[a-z]+\B/) {|x|
    x.length.times {|i|
        j = rand(i+1)
        x[j], x[i] = x[i] , x[j]
    }
    x
}

Basically, this is an implementation of scrambling that uses swaps. I
remember this method for scrambling from way back, but I can't seem to
find
a good reference for it at the moment.
I also figured that this method would be faster since it is linear,
while
the sorts are n log(n) (n = length of the word)

To by surprise, I found this method to actually be slower for any normal
text. One possible explanation is that when words are relatively short
you
don't gain much from the n vs. nlogn difference, and you lose because
while
this method always has n swaps, sorting may have less.

In order to see any performance benefit from the 3rd method I had to
make up
some horrifically long words which aren't terribly likely in  the
English
language (maybe I should have tried German :)).

Himadri
Cd49db0b676767ea4358b1047c4cddd2?d=identicon&s=25 Robin Stocker (Guest)
on 2006-04-23 12:44
(Received via mailing list)
Himadri Choudhury wrote:
> In order to see any performance benefit from the 3rd method I had to make up
> some horrifically long words which aren't terribly likely in  the English
> language (maybe I should have tried German :)).

Try Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz :)
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-04-23 14:53
(Received via mailing list)
Seems like forty-eight hours are up now, so here are my solutions for
this quiz, it was good to get a quick one :) I wrote a simple random
munging solution, and a slightly longer one that munges only part of the
words. I went for a different way on the latter one, just to play with
regexps a bit, but I expect its performance isn't great...

Both support unicode properly, as long as the -Ku stays on the ruby
command line ;) I could have used the u modifier instead but wanted to
save on the repetition.


# ========= random munging
#!/usr/local/bin/ruby -Ku
$stdout << ARGF.read.gsub(/\B((?![\d_])\w{2,})\B/) do |w|
  $&.split(//).sort_by { rand }
end

# (easily compresses to:)

#!/usr/local/bin/ruby -npKu
gsub(/\B((?![\d_])\w){2,}\B/){$&.split(//).sort_by{rand}}



# ========= slightly-less-random munging
#!/usr/local/bin/ruby -Ku
RX =
Hash.new{|h,k|h[k]=/(.{#{(k/4.0).round}})#{'(.)'*(k/2.0).round}(.*)/}
$stdout << ARGF.read.gsub(/((?![\d_])\w){4,}/) do |w|
  (caps = RX[w.split(//u).length].match(w).captures).first +
      caps[1..-2].sort_by { rand }.to_s + caps.last
end
0aca516785b12ea4ffd4fec43d69f586?d=identicon&s=25 Albert Vernon Smith (Guest)
on 2006-04-23 14:59
(Received via mailing list)
Is the performance better if you skip swaps when i == j ?

Also, for a swap method to give random results doesn't one need to
swap from a random position in the array which has not been passed
through yet?  (see http://en.wikipedia.org/wiki/Shuffle noting Fisher-
Yates shuffling.)

-a
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-23 16:53
(Received via mailing list)
On Apr 23, 2006, at 4:45 AM, Himadri Choudhury wrote:

> Here's my solution.

Just a gentle reminder here folks, please remember that Ruby Quiz has
a 48 hour no-spoiler period before solutions should be posted.  I'm
not a big stickler on this, but I know some people do like the time.
It's super easy to figure in your head, just look at the quiz date
and time and bump it forward two days.  That's when it's OK to submit.

For the record, I do consider posting solutions in other languages
(like Perl) a spoiler.

Thank you.

James Edward Gray II
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-23 17:34
(Received via mailing list)
> Your task for this quiz, then, is to take a text as input and output the
> text in this fashion. Scramble each word's center (leaving the first and
> last letters of each word intact). Whitespace, punctuation, numbers --
> anything that isn't a word -- should also remain unchanged.

_________________________________________
solution one
_________________________________________


     harp:~ > cat a.rb
     class String
       def scramble on = ''
         re = %r/( (?:\b \w \w{2,} \w \b) | \s+ | . )/iox
         scan(re){|words| on << words.first.scrambled}
         on
       end
       def scrambled
         self[1..-2] = self[1..-2].split(%r//).sort_by{rand}.to_s if
size >= 4
         self
       end
     end
     ARGF.read.scramble STDOUT


     harp:~ > ruby a.rb < a.rb
     cslas Srntig
       def srbcamle on = ''
         re = %r/( (?:\b \w \w{2,} \w \b) | \s+ | . )/iox
         sacn(re){|wrods| on << wodrs.fisrt.salbercmd}
         on
       end
       def sclmaebrd
         slef[1..-2] = slef[1..-2].split(%r//).s_botry{rnad}.t_os if
size >= 4
         slef
       end
     end
     ARGF.read.srcalbme SUDOTT


_________________________________________
solution two (golfing)
_________________________________________

     harp:~ > ruby -npae
'gsub!(/\b(\w)(\w{2,})(\w)\b/){_=$3;[$1,$2.split(//).sort_by{rand},_]}'
a.rb
     calss Snrtig
       def sbcarlme on = ''
         re = %r/( (?:\b \w \w{2,} \w \b) | \s+ | . )/iox
         sacn(re){|wdros| on << wdros.first.slramcebd}
         on
       end
       def smlcbaerd
         self[1..-2] = slef[1..-2].siplt(%r//).srbt_oy{rand}.t_os if
size >= 4
         self
       end
     end
     ARGF.read.smclarbe SUTODT


     harp:~ > wc -c
     gsub!(/\b(\w)(\w{2,})(\w)\b/){_=$3;[$1,$2.split(//).sort_by{rand},_]}
          70



thanks for the fun quiz!


-a
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-23 18:45
(Received via mailing list)
On Apr 23, 2006, at 4:45 AM, Himadri Choudhury wrote:

> to find
> a good reference for it at the moment.

http://www.nist.gov/dads/HTML/fisherYatesShuffle.html

James Edward Gray II
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2006-04-23 18:51
(Received via mailing list)
On 4/23/06, James Edward Gray II <james@grayproductions.net> wrote:

> For the record, I do consider posting solutions in other languages
> (like Perl) a spoiler.

How about COBOL or FORTRAN?  Or is that a spoiler for a different
reason? ;)
5c841628b56df3a68984986e9f095d01?d=identicon&s=25 Andrew Johnson (andrew)
on 2006-04-23 19:11
Well, the simple regex based one-liner seems to have gotten
plenty of airplay, so I decided to expand mine in an attempt
to improve the readability of the munged text. For example:

A naive munging:

  Noumeurs idavilundis have dneoatrstmed the ieneascrd
  dfifclutiy oinrcrucg wehn leihngter wdors are slipmy
  reiondmazd. Raionizdnmg wiihtn hntyahoeipn buadoreins
  offers smoe irnmoeemvpt.

A slightly more readable munging:

  Nuemruos inididvuals hvae dnometrtsaed the insecraed
  dfiifulcty ocucrinrg when lghetnier wrods are smiply
  rnamodized. Randomzinig wihtin hyphenatoin bonduiares
  offres some imvoepremnt.

Original text:

  Numerous individuals have demonstrated the increased
  difficulty occurring when lengthier words are simply
  randomized. Randomizing within hyphenation boundaries
  offers some improvement.

The hyphen-boundary randomizer:

  require 'text/hyphen'
  hyp  = Text::Hyphen.new :left => 1, :right => 1
  text = ARGF.read
  text.gsub!(/[^\W\d_]+/) do |m|
    hyp.visualize(m).split(/(^\w|\w$)|-/).map{|t|
      t.split(//).sort_by{rand}.join
    }.join
  end
  puts text
  __END__


cheers,
andrew
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-04-23 19:53
(Received via mailing list)
On Apr 21, 2006, at 2:34 PM, Ruby Quiz wrote:

> The three rules of Ruby Quiz:
> [...]
> Suggestion:  A [QUIZ] in the subject of emails about the problem
> helps everyone
> on Ruby Talk follow the discussion.

Can you also suggest that people reply to the original thread instead
of making new ones when they send their solutions? Right now there is:

- Original ruby quiz thread
- [QUIZ][SOLUTION] ...
- [QUIZ] ... A solution
- [QUIZ] ... A simplistic solution
- [SOLUTION] ...

-- Daniel
0aca516785b12ea4ffd4fec43d69f586?d=identicon&s=25 Albert Vernon Smith (Guest)
on 2006-04-23 20:03
(Received via mailing list)
From rubyquiz.com:

> Where should I send my solutions?
> Ideally, solutions should be sent to the Ruby Talk mailing list for
> all to see and learn from. All solutions sent to Ruby Talk are
> archived with the quiz. If you do not subscribe to Ruby Talk, you
> may send your messages to me and I will forward them to the list
> for you. Solutions are easy to find if your message subject
> includes a [SOLUTION], so that's probably the best tactic to make
> sure your work is recognized.

-a
86216345f72b5c078098b6597b232ee4?d=identicon&s=25 Himadri Choudhury (Guest)
on 2006-04-23 21:43
(Received via mailing list)
> On 4/23/06, Albert Vernon Smith <smithav@cshl.edu> wrote:
> Also, for a swap method to give random results doesn't one need to
> swap from a random position in the array which has not been passed
> through yet?  (see http://en.wikipedia.org/wiki
>
> /Shuffle noting Fisher-
> Yates shuffling.)
>

Yes. You are right. My memory didn't serve me well in this case.
Instead of j = rand(i+1), it should have been: j = i + rand(x.length-i)

Thanks for the reference.

Himadri
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-23 21:46
(Received via mailing list)
On Apr 23, 2006, at 12:52 PM, Daniel Harple wrote:

> now there is:
>
> - Original ruby quiz thread
> - [QUIZ][SOLUTION] ...
> - [QUIZ] ... A solution
> - [QUIZ] ... A simplistic solution
> - [SOLUTION] ...

Done.

James Edward Gray II
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-23 21:49
(Received via mailing list)
On Apr 23, 2006, at 1:02 PM, Albert Vernon Smith wrote:

> From rubyquiz.com:
>
>> Where should I send my solutions?
>> Ideally, solutions should be sent to the Ruby Talk mailing list
>> for all to see and learn from. All solutions sent to Ruby Talk are
>> archived with the quiz. If you do not subscribe to Ruby Talk, you
>> may send your messages to me and I will forward them to the list
>> for you. Solutions are easy to find if your message subject
>> includes a [SOLUTION], so that's probably the best tactic to make
>> sure your work is recognized.

Thank you.  I have updated the FAQ.

James Edward Gray II
Bf334d32da42f532ed3e2396da6311b8?d=identicon&s=25 Tom Moertel (Guest)
on 2006-04-24 03:57
(Received via mailing list)
Ruby Quiz wrote:
> Your task for this quiz, then, is to take a text as input and output the text in
> this fashion. Scramble each word's center (leaving the first and last letters of
> each word intact). Whitespace, punctuation, numbers -- anything that isn't a
> word -- should also remain unchanged.

My solution:

=== snip ===

# Ruby Quiz 76
# http://www.rubyquiz.com/quiz76.html
#
# Solution of Tom Moertel
# http://blog.moertel.com/
# 2006-04-21
#
# Usage:  munge.rb [inputs...]

class String
    def munge!
     (length - 2).downto(2) do |i|
       j = rand(i) + 1
       self[i], self[j] = self[j], self[i]
     end
     self
   end
end

while line = gets
   puts line.gsub(/\w+/) { |s| s.munge! }
end

=== end ===

A few notes:

I took the term "scramble" in the task definition to mean randomly
permute because some occurrences of words in the example text were
apparently unchanged by the scrambling transformation (e.g., "keep" and
  "being" in the tenth line) and some words that had multiple
occurrences were scrambled differently for each occurrence (e.g.,
"remvpidtee" in the second line vs. "retpmevide" in the fourth from the
last line).

str.munge! (fairly) permutes the inner characters of +str+ and has no
effect on strings of three or fewer characters.

I used +gets+ in the main I/O loop in order to get sensible command-line
input handling for free.

Cheers,
Tom
A5ae84b6af0a67cdea1db87706a11a6f?d=identicon&s=25 Yoann Guillot (Guest)
on 2006-04-24 13:38
(Received via mailing list)
Hello,

Here is my solution to the quiz.
It's not a one-liner anymore - i've left the first version in the
comments, for historical purposes.


# 1st try:
# does not scramble abcd123, which may or not be a good thing
# no support for accented characters
# _ is considered a letter
#puts ARGF.read.gsub(/\b(?=\D+\b)(\w)(\w+)(?=\w\b)/) { $1 +
$2.split('').sort_by{rand}.join }

class String
	# returns the string with characters randomly placed
	def randomize
		split('').sort_by{rand}.join
	end

	# character class to identify a word's letter
	# arbitrarily ripped from iso-8859-1
	WordChars = '[a-zA-Z\xc0-\xd6\xd8-\xf6\xf8-\xfd\xff]'

	# randomizes each word (defined by +chars+), leaving alone the
	# first and last letters
	# uses a default argument to fit in 80 cols :)
	def scramble_words(chars = WordChars)
		gsub(/(#{chars})(#{chars}+)(?=#{chars})/) { $1 + $2.randomize }
	end
end

puts ARGF.read.scramble_words if __FILE__ == $0
E2148159cc245f2335bb9f333c5ce449?d=identicon&s=25 Alex Barrett (trib4lmaniac)
on 2006-04-24 13:55
@James Gray: Can you please only add my second listing on rubyquiz.com.
They are both effectively the same; only one has less characters.
Thanks.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-24 15:02
(Received via mailing list)
On Apr 24, 2006, at 6:55 AM, Alex Barrett wrote:

> @James Gray: Can you please only add my second listing on
> rubyquiz.com.
> They are both effectively the same; only one has less characters.
> Thanks.

Is it not the second link on this page?

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

If not, please send me a link to the message.

James Edward Gray II
E2148159cc245f2335bb9f333c5ce449?d=identicon&s=25 Alex Barrett (trib4lmaniac)
on 2006-04-24 16:42
James Gray wrote:
> Is it not the second link on this page?

Sorry, I shouldn't have said "add." I meant could you _remove_ the first
listing and keep the seconds.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-24 16:47
(Received via mailing list)
On Apr 24, 2006, at 9:42 AM, Alex Barrett wrote:

> James Gray wrote:
>> Is it not the second link on this page?
>
> Sorry, I shouldn't have said "add." I meant could you _remove_ the
> first
> listing and keep the seconds.

Nothing wrong with showing progress, is there?

I always handle the quiz solutions that way.  See the past problems
for examples.

James Edward Gray II
E2148159cc245f2335bb9f333c5ce449?d=identicon&s=25 Alex Barrett (trib4lmaniac)
on 2006-04-24 17:53
James Gray wrote:
> Nothing wrong with showing progress, is there?
>
> I always handle the quiz solutions that way.  See the past problems
> for examples.
>
> James Edward Gray II

Aye, usually I'd agree with you. But in this case the two examples are
almost exactly the same. Just changing it to work with input instead of
a string.
The first one I posted was in reply to a post about one-liners. Not
intended as a seperate submission.

And what's with the "3D's" in the mailing list archives?
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-24 18:36
(Received via mailing list)
On Apr 24, 2006, at 10:53 AM, Alex Barrett wrote:

> Aye, usually I'd agree with you. But in this case the two examples are
> almost exactly the same. Just changing it to work with input
> instead of
> a string.
> The first one I posted was in reply to a post about one-liners. Not
> intended as a seperate submission.

I have removed the first link.

James Edward Gray II
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-04-24 20:01
This is my first try:
puts $<.read.split(/\W/).map{|x|x==""||nil
?"":"#{x[0..0]}#{x[1...a=x.size-1].split(//).sort{rand}}#{x[a..a+1]}
"}*""

but this doesn't work on single letter words & I wanted to use inject.
My final version:

puts
$<.inject([]){|a,w|a<<w.gsub(/\B(\w+)\B/){$1.split('').sort_by{rand}}}


j`ey
http://www.eachmapinject.com
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2006-04-24 22:29
(Received via mailing list)
On 4/23/06, Gregory Brown <gregory.t.brown@gmail.com> wrote:
>
> On 4/23/06, James Edward Gray II <james@grayproductions.net> wrote:
>
> > For the record, I do consider posting solutions in other languages
> > (like Perl) a spoiler.
>
> How about COBOL or FORTRAN?  Or is that a spoiler for a different reason?
> ;)
>
>
James was talking about languages, wasn't he :))

--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein
This topic is locked and can not be replied to.