[QUIZ] Text Munger (#76)

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

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

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

James Edward Gray II

···

On Apr 21, 2006, at 12:26 PM, Sergey Volkov wrote:

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.

···

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.

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

(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)

···

On Sat, 2006-04-22 at 19:28 +0900, Ross Bamford wrote:

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:

$ ./munger.rb test.txt
Attehcaed is my résmué.

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

Why are the e's not moving?

James Edward Gray II

···

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

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'

···

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

I have removed the first link.

James Edward Gray II

···

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.

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

···

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

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?

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

Ross Bamford wrote:

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)

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

···

--

Ray

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

···

On 22-Apr-06, at 1:35 PM, PerlyGates wrote:

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.

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

···

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

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?

···

On Sun, 2006-04-23 at 00:56 +0900, Ray Baxter wrote:

Ross Bamford wrote:

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

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

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

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

···

On 22/04/06, Ross Bamford <rossrt@roscopeco.co.uk> wrote:

On Sun, 2006-04-23 at 00:56 +0900, Ray Baxter wrote:
> Ross Bamford wrote:
>
> > 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)
> >
>
> The pattern, "eu???ne str???que" is constant in your results.
>

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?

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