More Spaghetti

Bill Ott bott at grpl.org
Wed Oct 6 12:52:26 CDT 1999


Both Joel and Bill G. responded correctly, but Joel was first.
The garbled mess (nine 'y' separated lines with 4 strings each) were sorted
by the 3rd, 2nd, and 1st elements, then only the first element from each
line was used to reassemble the message:
never_under_estimate_the_power_of_the_schwartz

It would have been easier if it was displayed like this:

print map {$_->[3]}
sort {$a->[1] <=> $b->[1] ||
      $a->[2] <=> $b->[2] ||
      $a->[3] cmp $b->[3]}
map {[$_,(split /y/)[2,1,0] ]}
@x=<DATA>;

Notice, only 1 semi-colon, making each line's output, the input for the
previous line.  So, when tracing through the code, it seems to execute from
the bottom up.  Something that I thought was really cool.

Now, for the bonus points, can anyone give a name to this map-sort-map
technique?

HINT: it's in the cookbook

--
Bill Ott      bott at grpl.org


Joel Meulenberg wrote:

> I guess I was supposed to explain it too.
> The data is really 9 3-tuples.  The data items in each line of data are
> delimited by "y" characters and no data beyond the 3rd item of a line
> (3-tuple) is significant.
> The tuples are then sorted by the 3rd, 2nd, 1st data items within each
> tuple and all the 1st data items (in the now-sorted tuples) are strung
> together to form the very cool aphorism.
>
> +Joel
>
> --- Joel Meulenberg <joelmeulenberg at yahoo.com> wrote:
> > never_under_estimate_the_power_of_the_schwartz
> >
> > Must be a reference to Spaceballs.  : )
> >
> > +Joel
> > --- Bill Ott <bott at grpl.org> wrote:
> > > If it is to be called spaghetti, then it shall look like spaghetti!
> > > This is about as messy as I could come up with.
> > >
> > > Again, no cheating by running the code, but you'd still have to
> > > explain
> > > it...
> > > --
> > > Bill Ott      bott at grpl.org
> > > --------------------------
> > > ###
> > > ###  What does the following print? ...and how (why)?
> > > ###
> > >
> > > print map {$_->[3]} sort {$a->[1] <=> $b->[1] ||
> > >     $a->[2] <=> $b->[2] ||$a->[3] cmp $b->[3]}
> > > map {[$_,(split /y/)[2,1,0]]}@x=<DATA>;
> > >
> > > __DATA__
> > > he_scy123y888yaaa
> > > er_esy9y123yabc
> > > r_undy343y23yayz
> > > nevey09y23yaba
> > > timaty222y138yaba
> > > hwartzy1y999yduh
> > > _powey223y145ybbc
> > > e_they223y138yabc
> > > r_of_ty555y333yxyz
> > >
> > >
> > >
> > >
> > >
> >
> >
> > =====
> > __________________________________________________
> > AdStream programs expose you to a stream of banner ads while you're
> > connected to the Internet.  In exchange for a smidgen of your
> > attention
> > they pay you cash.  You can easily earn enough to pay your monthly
> > ISP
> > bill.  Compare the various AdStream programs at:
> > http://adstreaminfo.hypermart.net/
> > __________________________________________________
> > Do You Yahoo!?
> > Bid and sell for free at http://auctions.yahoo.com
> >
>
> =====
> __________________________________________________
> AdStream programs expose you to a stream of banner ads while you're
> connected to the Internet.  In exchange for a smidgen of your attention
> they pay you cash.  You can easily earn enough to pay your monthly ISP
> bill.  Compare the various AdStream programs at:
> http://adstreaminfo.hypermart.net/
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com




More information about the grand-rapids-pm-list mailing list