[QUIZ] Text Munger (#76)

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

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

···

From: "Andrew Johnson" <ajohnson@cpan.org>

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! :wink:

Ryan

···

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.

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! Ruby for Rails
Paper version coming in early May!

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.

···

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

One line?
Hmmm.... Methinks I need to go back and reexamine my own solution. :slight_smile:

···

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 :wink:
>

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

Yoann

} 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 :wink:
} >
} >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

···

On Sat, Apr 22, 2006 at 02:28:48AM +0900, James Edward Gray II wrote:

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

···

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

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

-M

Well, I can make one in ~60 chars that rearranges both. Still working on getting <70 for not rearranging numbers....

- Jake McArthur

···

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

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

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

James Edward Gray II

···

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

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?

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)

···

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

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

···

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.

} One line?
} Hmmm.... Methinks I need to go back and reexamine my own solution. :slight_smile:

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 Sat, Apr 22, 2006 at 12:24:06AM +0900, Matthew Moss wrote:

} 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 :wink:
} > >
} >
} > Mmh, for my first participation, i get a quizz solved by a one-liner.
} > And still i discover things :slight_smile:
} >
} > Yoann
} >
} >
}
}

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

One line?
Hmmm.... Methinks I need to go back and reexamine my own solution. :slight_smile:

···

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

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 :wink:
>

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

Yoann

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

James Edward Gray II

···

On Apr 21, 2006, at 12:33 PM, Gregory Seidman wrote:

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 :wink:
} >
} >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>.

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

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

-M

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

···

On Apr 21, 2006, at 4:09 PM, James Edward Gray II wrote:

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

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

James Edward Gray II

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

···

On Sat, 2006-04-22 at 06:09 +0900, James Edward Gray II wrote:

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

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk

Use negated word boundaries (\B) instead of the lookarounds to lose a few
characters.

···

On 22/04/06, PerlyGates <nothanks@example.com> wrote:

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)

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

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?

···

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