Re: TPR1 post-mortem

2002-03-08 Thread Marcelo E. Magallon

Hats off to Ton and Lars!

 Ton Hospel [EMAIL PROTECTED] writes:

  -l $_=pop;s;.;print,s,,$*1.11%10if/\G../,eg;eg

 Wow.  My last fumblings where something along the lines of:

 -l $_=pop;0while+print,s+.+$*111%100if/../+eg,chop

 which I couldn't get to work.

 Perhaps as post-mortem regarding that discussion about the tiebreaker,
 I was wondering how you guys got rid of the while.  I guessed there
 wasn't a while involved because I thought there's got to be a pop, a
 print, certainly an s with e and g.  If figured the best solution
 didn't had a while in it since in mine that uses 7 strokes with 6 \w's.
 The above solution also uses 7 strokes for the same purpose
 (side-effects aside, which is the killer), but the tie-breaker is
 lower.

 The 1.11%10 bit made me giggle for some reason.

 Regarding my one step solution, the secret can be computed as:

Op(i=1..digits, C(i, digits)*digit[i])

 where Op(a,b) := (0, 1..9, 1..9, ...)[a+b] and C(i, j) := j!/i!/(j-i)!
 (or something like that, I can't think straight right now).  This lead
 to a horribly long solution that doesn't even pass the test program :-)

 Thanks guys, my first tournament ever was lots of fun!

-- 
Marcelo



Re: TPR1 post-mortem

2002-03-08 Thread Stephen Turner

On Fri, 8 Mar 2002 [EMAIL PROTECTED] wrote:
 
 Here are some statistics from the current series of games:
 
 fwp Santa (head, tail, ...):35 players on scoreboard
 irc Christmas (human sort): 11 players on scoreboard
 fwp Get Even:   51 players on scoreboard
 TPR Base 36:82 players on scoreboard
 TPR Secret Number: 128 players on scoreboard
 

This reminds me of something. I'd love to know more about the history of
Perl golf. Who invented it, and so on. Does anyone know about this? (And if
so, would it make a good article for TPR? :-)

-- 
Stephen Turner, Cambridge, UKhttp://homepage.ntlworld.com/adelie/stephen/
This is Henman's 8th Wimbledon, and he's only lost 7 matches. BBC, 2/Jul/01




Re: TPR1 post-mortem

2002-03-08 Thread Piers Cawley

Stephen Turner [EMAIL PROTECTED] writes:

 On Fri, 8 Mar 2002 [EMAIL PROTECTED] wrote:
 
 Here are some statistics from the current series of games:
 
 fwp Santa (head, tail, ...):35 players on scoreboard
 irc Christmas (human sort): 11 players on scoreboard
 fwp Get Even:   51 players on scoreboard
 TPR Base 36:82 players on scoreboard
 TPR Secret Number: 128 players on scoreboard
 

 This reminds me of something. I'd love to know more about the history of
 Perl golf. Who invented it, and so on. Does anyone know about this? (And if
 so, would it make a good article for TPR? :-)

Not sure who invented it, but this
http://groups.google.com/groups?selm=7km3p5%24gm6%244%40info2.uah.eduoutput=gplain
appears to be where the term was coined by Greg Bacon.

-- 
Piers

   It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite.
 -- Jane Austen?




Re: TPR1 post-mortem

2002-03-08 Thread F . Xavier Noria

On Fri, 08 Mar 2002 11:41:31 +0100
cizaire_liste [EMAIL PROTECTED] wrote:

: Can someone explains me why 
: 
: my $c = '($a=www)=~s{}{z}g;print $a\n;die';
: eval $c;
: $^O=~s{.}{$c}ee;
: 
: output two lines that are different ?
: ($^O is only used to have a not empty string)

I have not studied it carefully, but at first sight I see a possible
gotcha, when the pattern is {} s uses the last successful pattern that
matched (this is surely imprecise or false, I have not the Camel book
here), just to throw an idea.

-- fxn



Re: rethinking printf

2002-03-08 Thread Matthew Wickline


[EMAIL PROTECTED] wrote:
  why not qf for format strings then


For some reason, I thought Schwern would be the one to suggest a queef
operator ;)

-matt


PS: that may be a US-specific bit of slang
http://google.com/search?q=a+queef+is;



Re: TPR1 post-mortem

2002-03-08 Thread Philippe 'BooK' Bruhat

En réponse à Stephen Turner [EMAIL PROTECTED]:

 On Fri, 8 Mar 2002 [EMAIL PROTECTED] wrote:
  
  Here are some statistics from the current series of games:
  
  fwp Santa (head, tail, ...):35 players on scoreboard
  irc Christmas (human sort): 11 players on scoreboard
  fwp Get Even:   51 players on scoreboard
  TPR Base 36:82 players on scoreboard
  TPR Secret Number: 128 players on scoreboard
  
 
 This reminds me of something. I'd love to know more about the history of
 Perl golf. Who invented it, and so on. Does anyone know about this? (And if
 so, would it make a good article for TPR? :-)

Well, it looks like it's time for somebody to ask for the domain golf.perl.org
and set up a perl golf history, tools, and documentation web site. Volunteers?

-- 
 Philippe BRUHAT - BooK

 When you run from your problem, you make it that much harder for good
 fortune to catch you, as well. (Moral from Groo The Wanderer #14 (Epic))



Re: TPR1 post-mortem

2002-03-08 Thread Jason Purdy

Someone's gonna explain these, right?  Man, I love learning this kinda stuff. 
 Last hole, I learned about pop vs. shift (saving two strokes) and after 
seeing this e-mail and playing around with Perl, I see that -l will take 
care of the newline stuff for me (so I don't have to add $_\n to my print 
statements [6 strokes there]).

Is that #*1.11%10 a number theory to get to the same number?  How did someone 
recognize that pattern? (my advanced calculus/comb math being a lil' rusty)  
What is \G ... $?  Gotta dig out my Camel book again. ;)

Can't wait 'til next month!  Great job Dave  Jerome for managing this!

Cheers,

Jason

If memory serves me right, on Thursday 07 March 2002 20:36, Ton Hospel wrote:
 In article a6913g$k06$[EMAIL PROTECTED],

   [EMAIL PROTECTED] (Ton Hospel) writes:
  Mm, I'm not sure all last results were processed, but the post-mortem
  is on the site, so here we go.
 
  MTV was very close I see. With a simple transformation he's at 47:
 
  -l $_=pop;s;.;print,s,,$*1.11%10if/\G../,eg;eg

 And here's a 46:
 -l $_=pop;s;.;print,s,,$*1.11%10if/../g,eg;eg



Re: TPR1 post-mortem

2002-03-08 Thread Honza Pazdziora

On Fri, Mar 08, 2002 at 03:16:10PM +0100, Marcelo E. Magallon wrote:
 
  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it out
  by reading the docs.

Because after matching the b and the non-boundaries around it, the
non-boundary between b and c already matched. So the next match for 
non-boundary will match between c and d, and since there is no \B
after d, you'll get abbcd.

You can try to rewrite the regexp as

s/_(.)_/$+$+/g;

and match

a_b_c_d

Here, it should be obvious that after matching _b_, your next chance
with _ is between c and d, not between b and c.

Yours,

-- 

 Honza Pazdziora | [EMAIL PROTECTED] | http://www.fi.muni.cz/~adelton/
  ... all of these signs saying sorry but we're closed ...




Re: TPR1 post-mortem

2002-03-08 Thread Keith C. Ivey

Marcelo E. Magallon [EMAIL PROTECTED] wrote:

  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it
  out by reading the docs.

I wondered that too.  I figured it was because \B wouldn't match 
twice at the same place, but then I saw that s/\B./$$/g didn't work 
as expected either.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR1 post-mortem

2002-03-08 Thread Ronald J Kimball

On Fri, Mar 08, 2002 at 10:33:26AM +, Piers Cawley wrote:
 Stephen Turner [EMAIL PROTECTED] writes:
 
  On Fri, 8 Mar 2002 [EMAIL PROTECTED] wrote:
  
  Here are some statistics from the current series of games:
  
  fwp Santa (head, tail, ...):35 players on scoreboard
  irc Christmas (human sort): 11 players on scoreboard
  fwp Get Even:   51 players on scoreboard
  TPR Base 36:82 players on scoreboard
  TPR Secret Number: 128 players on scoreboard
  
 
  This reminds me of something. I'd love to know more about the history of
  Perl golf. Who invented it, and so on. Does anyone know about this? (And if
  so, would it make a good article for TPR? :-)
 
 Not sure who invented it, but this
 http://groups.google.com/groups?selm=7km3p5%24gm6%244%40info2.uah.eduoutput=gplain
 appears to be where the term was coined by Greg Bacon.
 

Actually, I think it was this one from Greg Bacon, a month earlier:

http://groups.google.com/groups?hl=enselm=7imnti%24mjh%241%40info2.uah.edu

Ronald



Re: TPR1 post-mortem

2002-03-08 Thread Honza Pazdziora

On Fri, Mar 08, 2002 at 09:30:40AM -0500, Keith C. Ivey wrote:
 
 I wondered that too.  I figured it was because \B wouldn't match 
 twice at the same place, but then I saw that s/\B./$$/g didn't work 
 as expected either.

Well, for 'abcd', it returns abbccdd with 5.004_04 (my production
version still) and abbcdd with 5.6.1. Scary.

-- 

 Honza Pazdziora | [EMAIL PROTECTED] | http://www.fi.muni.cz/~adelton/
  ... all of these signs saying sorry but we're closed ...




Re: TPR1 post-mortem

2002-03-08 Thread F . Xavier Noria

On Fri, 8 Mar 2002 15:16:10 +0100
Marcelo E. Magallon [EMAIL PROTECTED] wrote:

:  As you can see it's just a series of 1 .. 9, except for 0.  With that
:  in mind my first I tried something like (0,(1..9)x11)[$n].  Actually,
:  before that I tried something more like (0,(1..9)x2)[$a+$b]

I liked this shorcut here (that was in my last but one submission I
think):

($a..9,1..9)[$b]

$b was $` in my approach, I did not find a shorter way to extract the
first digit from $` than $`'?' there, at least $` was of type string.
and didn't need double quotes.

-- fxn



Re: TPR1 post-mortem

2002-03-08 Thread Ronald J Kimball

On Fri, Mar 08, 2002 at 12:04:15PM +0100, F.Xavier Noria wrote:
 On Fri, 08 Mar 2002 11:41:31 +0100
 cizaire_liste [EMAIL PROTECTED] wrote:
 
 : Can someone explains me why 
 : 
 : my $c = '($a=www)=~s{}{z}g;print $a\n;die';
 : eval $c;
 : $^O=~s{.}{$c}ee;
 : 
 : output two lines that are different ?
 : ($^O is only used to have a not empty string)
 
 I have not studied it carefully, but at first sight I see a possible
 gotcha, when the pattern is {} s uses the last successful pattern that
 matched (this is surely imprecise or false, I have not the Camel book
 here), just to throw an idea.

Nice work, that is the correct explanation.

The first time $c is evaled in the code snippet, there is no previous
successfully matched pattern, so s{}{z}g matches the null string at every
position in $a.  When $c is evaled inside s{.}{$c}ee, the pattern /./ was
just successfully matched, so s{}{z}g matches /./.

This shows the same behavior:

($a=www)=~s{}{z}g;
print $a\n;

$a =~ /./;

($a=www)=~s{}{z}g;
print $a\n;

Ronald



Re: TPR1 post-mortem

2002-03-08 Thread F . Xavier Noria

On Fri,  8 Mar 2002 15:37:42 +0100 (CET)
F.Xavier Noria [EMAIL PROTECTED] wrote:

: $b was $` in my approach, I did not find a shorter way to extract the
: first digit from $` than $`'?' there, at least $` was of type string.
: and didn't need double quotes.

I meant $b was $' there.

-- fxn



Re: TPR1 post-mortem

2002-03-08 Thread Philippe 'BooK' Bruhat

En réponse à Keith C. Ivey [EMAIL PROTECTED]:

 Marcelo E. Magallon [EMAIL PROTECTED] wrote:
 
   A question of my own: why doesn't
  
  s/\B.\B/$$/g
  
   work as I expect, namely abcd - abbccd.  I really can't figure it
   out by reading the docs.
 
 I wondered that too.  I figured it was because \B wouldn't match 
 twice at the same place, but then I saw that s/\B./$$/g didn't work 
 as expected either.

What you want is:

s/(?!^).(?!$)/$$/g

Now, can we shorten it?

s/\B.(?=\B)/$$/g

Anything better?

-- 
 Philippe BRUHAT - BooK

 When you run from your problem, you make it that much harder for good
 fortune to catch you, as well. (Moral from Groo The Wanderer #14 (Epic))



Re: TPR1 post-mortem

2002-03-08 Thread Prakash Kailasa

Hats off to Ton, Lars and many others. And, thanks to Dave and Jerome
for making this happen. This was the most fun I had in a long time.

Thanks to Marcelo for the explanation.

I request others to follow with their own accounts about how they
arrived at their formula(e|s). I am especially intrigued with the
usage of hex() by Ton and Chris (I haven't looked at all the results,
so there might be others too). How the heck did you guys think of such
a thing?

Incredible.

Compared to these, mine was a simplistic $1+01+($1+8)%9, and I was
proud about myself for coming up with it, oh, may be for a brief
second. I have a long way to go.

Can't wait to read your stories. Keep'em coming.
/prakash


On Fri, Mar 08, 2002 at 03:16:10PM +0100, Marcelo E. Magallon wrote:
  Jason Purdy [EMAIL PROTECTED] writes:
 
   Is that #*1.11%10 a number theory to get to the same number?  How did
   someone recognize that pattern? (my advanced calculus/comb math being
   a lil' rusty)
 
  I don't know others, but I started by looking at the input and output,
  like this:
 
  0   0
  1   1
... ...
  9   9
 10   1
 11   2
 12   3
... ...
 18   9
 19   1
 20   2
 
  As you can see it's just a series of 1 .. 9, except for 0.  With that
  in mind my first I tried something like (0,(1..9)x11)[$n].  Actually,
  before that I tried something more like (0,(1..9)x2)[$a+$b] (where $a
  and $b are the digits).  Then I noticed that I could get the same
  result using %9 and some conditionals.  After putting this stuff aside
  and having some sleep I just pictured the thing as a table like this:
 
  0   1   2   3   4 ...
 0   00  11  22  33  44 ...
 1   10  21  32  43  54 ...
 ...
 8   80  91  12  23  34 ...
 9   90  11  22  33  44 ...
 
  which made it kind of evident that 111%100 should do what I wanted.
  *Then* I had a different problem to solve :-)
 
   What is \G ... $?  Gotta dig out my Camel book again.
 
  Check out perlre and perlvar and the g option to m//.
 
  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it out
  by reading the docs.
 
  TIA,
 
  Marcelo

-- 
Prakash Kailasa mailto:[EMAIL PROTECTED]
==
  Arnold's Addendum:
Anything not fitting into these categories causes cancer in rats.
==



Re: TPR1 post-mortem

2002-03-08 Thread Ronald J Kimball

On Fri, Mar 08, 2002 at 03:16:10PM +0100, Marcelo E. Magallon wrote:

  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it out
  by reading the docs.

It works as expected in perl5.005_3 and perl5.7.2.  There are many subtle
bugs in the regex engine in perl5.6.0 and perl5.6.1.

Ronald



Re: TPR1 post-mortem

2002-03-08 Thread Rick Klement

Marcelo E. Magallon wrote:
 
  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it out
  by reading the docs.

I ran smack into this one too.

It works on 5.005_03, but fails on 5.6.1, so I figured it's a bug.
Does anyone have a different version of perl to try it on?

[EMAIL PROTECTED] wrote:
 
 Maybe Perl golf is useful, after all -- as a QA tool to find
 Perl bugs. :)

-- 
Rick Klement



Re: TPR1 post-mortem

2002-03-08 Thread Adam Spiers

Philippe 'BooK' Bruhat ([EMAIL PROTECTED]) wrote:
 What you want is:
 
 s/(?!^).(?!$)/$$/g
 
 Now, can we shorten it?
 
 s/\B.(?=\B)/$$/g

Except that that tickles the bug discussed elsewhere in this thread,
and is hence no use.

$ echo 1234 | perl5.6.1 -lpe 's/\B.(?=\B)/$$/g'
12234

 Anything better?

Yep :-)

  s/(?=.(.).)/$+/g

Produces all but the penultimate pair in reverse order, which is of
course OK, because the function is symmetrical.  I didn't end up using
it though, and noone else did either, it seems.



Re: TPR1 post-mortem

2002-03-08 Thread Eugene van der Pijll

En op 08 maart 2002 sprak Ronald J Kimball:
 On Fri, Mar 08, 2002 at 10:33:26AM +, Piers Cawley wrote:
  Stephen Turner [EMAIL PROTECTED] writes:
  
   On Fri, 8 Mar 2002 [EMAIL PROTECTED] wrote:
   
   Here are some statistics from the current series of games:
   
   fwp Santa (head, tail, ...):35 players on scoreboard
   irc Christmas (human sort): 11 players on scoreboard
   fwp Get Even:   51 players on scoreboard
   TPR Base 36:82 players on scoreboard
   TPR Secret Number: 128 players on scoreboard
   
  
   This reminds me of something. I'd love to know more about the history of
   Perl golf. Who invented it, and so on. Does anyone know about this? (And if
   so, would it make a good article for TPR? :-)
  
  Not sure who invented it, but this
  http://groups.google.com/groups?selm=7km3p5%24gm6%244%40info2.uah.eduoutput=gplain
  appears to be where the term was coined by Greg Bacon.
  
 
 Actually, I think it was this one from Greg Bacon, a month earlier:
 
 http://groups.google.com/groups?hl=enselm=7imnti%24mjh%241%40info2.uah.edu
 
 Ronald

That was probably the first occurrence of the term Perl golf, but the
game itself is much older:

http://groups.google.com/groups?selm=1990Mar20.203516.8429%40iwarp.intel.com

Okay, here's my entry for the shortest self-reproducing Perl program.
Any takers for shorter?  Any one liners?

http://groups.google.com/groups?selm=1992Mar31.222415.19043%40uvaarpa.Virginia.EDU

A friend asked me to write the shortest script I could to collapse
multiple blank lines down to one.

http://groups.google.com/groups?selm=1993Jul23.213258.2943%40clarinet.com

 Subject: 10 little indians in Perl?

That last one was a real golf thread as seen also on FWP, with remarks
like: Much too much time on my hands... and reverse one of the ?
tests and we chop off another one

Of course, some people can do a golf thread all by themselves in one
post:

http://groups.google.com/groups?selm=1991Apr29.072206.5621%40jpl-devvax.jpl.nasa.gov



Eugene



Re: TPR1 post-mortem

2002-03-08 Thread Andy_Bach

5.6.1
abbcd
5.6.0
abbcd
5.005_03
abbccd
5.005_02
abbccd
5.004_04
abbccd
5.000
abbccd
4.0.1.6p19
abbccd
4.0.1.8p36
abbccd

Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED] 
VOICE: (608) 261-5738  FAX 264-5030






Rick Klement [EMAIL PROTECTED]
Sent by: root@nodots-daemon
03/08/02 09:19 AM

 
To: Fun With Perl [EMAIL PROTECTED]
cc: 
Subject:Re: TPR1 post-mortem


Marcelo E. Magallon wrote:
 
  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it out
  by reading the docs.

I ran smack into this one too.

It works on 5.005_03, but fails on 5.6.1, so I figured it's a bug.
Does anyone have a different version of perl to try it on?

[EMAIL PROTECTED] wrote:
 
 Maybe Perl golf is useful, after all -- as a QA tool to find
 Perl bugs. :)

-- 
Rick Klement






Re: TPR1 post-mortem

2002-03-08 Thread Chris Dolan

Prakash Kailasa wrote:
 
 I request others to follow with their own accounts about how they
 arrived at their formula(e|s). I am especially intrigued with the
 usage of hex() by Ton and Chris (I haven't looked at all the results,
 so there might be others too). How the heck did you guys think of such
 a thing?
 

Like others did, I built a chart

perl -le 'for$i(0..9){for$j(0..9){printf%3d,$i+$j}print}'
   0  1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9 10
   2  3  4  5  6  7  8  9 10 11
   3  4  5  6  7  8  9 10 11 12
   4  5  6  7  8  9 10 11 12 13
   5  6  7  8  9 10 11 12 13 14
   6  7  8  9 10 11 12 13 14 15
   7  8  9 10 11 12 13 14 15 16
   8  9 10 11 12 13 14 15 16 17
   9 10 11 12 13 14 15 16 17 18

and noted that I wanted everything above 9 to be smaller.  First I 
played with %9
but I got the unfortunate result that while 10%9 is 1, as desired, 9%9 
is zero, not
9.  I decided I needed a gap between 9 and 10, and it occured to me that 
  interpreted in a base larger than 10, there would be a gap.  I also 
realized that the reason that %9 was attractive was that it was the 
largest single-digit number.  So

perl -le 'for$i(0..9){for$j(0..9){printf%3d,hex($i+$j)%15}print}'
   0  1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9  1
   2  3  4  5  6  7  8  9  1  2
   3  4  5  6  7  8  9  1  2  3
   4  5  6  7  8  9  1  2  3  4
   5  6  7  8  9  1  2  3  4  5
   6  7  8  9  1  2  3  4  5  6
   7  8  9  1  2  3  4  5  6  7
   8  9  1  2  3  4  5  6  7  8
   9  1  2  3  4  5  6  7  8  9

gives the right chart.  The 15 is crucial because in hex, its the largest
single digit number.

My biggest failing in this competition is that I couldn't get the $` 
approach to work so I was stuck with $' and chop.  Ton's ingenious 
^s//pop/e was the thing I was missing.

Chris




base36 (was Re: TPR1 post-mortem)

2002-03-08 Thread Bill -Sx- Jones

On 3/8/02 12:18 PM, Chris Dolan [EMAIL PROTECTED] wrote:
 
 Like others did, I built a chart
 
 perl -le 'for$i(0..9){for$j(0..9){printf%3d,$i+$j}print}'
  0  1  2  3  4  5  6  7  8  9




Speaking of charts -

May I revisit Base 36 for a moment?

I am playing around with trying to 'visualize' Base 36 in something other
than 0..9,A..Z - sort of like using Dominos:

**
**
**
__ = Z = 35 = 6x6-1
**
**
**

Instead of boring the group with my baby Perl code, I was wondering if I
could suggest a current discussion on this or maybe a possible future Perl
Golf session ?


???
-Sx-  :]





Re: TPR1 post-mortem

2002-03-08 Thread Marcelo E. Magallon

 Bart Lateur [EMAIL PROTECTED] writes:

  18   9
  19   1
  20   2
  
  How can one add two digits, and come up with a number larger than 18?

 Sorry, my bad.  I meant that as in if the input string is 20 the
 output string is 2.  At some point I kept thinking about this in terms
 of abcd - abbccd - xyz, where x=f(ab) and so on.

-- 
Marcelo



Re: TPR1 post-mortem

2002-03-08 Thread Stephen Turner

On Fri, 8 Mar 2002, Keith C. Ivey wrote:
 
 I wondered that too.  I figured it was because \B wouldn't match 
 twice at the same place, but then I saw that s/\B./$$/g didn't work 
 as expected either.
 

I fell foul of this too. It's maybe worth pointing out that m/\B./g doesn't
have the expected effect either:

% perl -le'print abcdefgh=~/\B./g'
bdfh

-- 
Stephen Turner, Cambridge, UKhttp://homepage.ntlworld.com/adelie/stephen/
This is Henman's 8th Wimbledon, and he's only lost 7 matches. BBC, 2/Jul/01




Re: TPR1 post-mortem

2002-03-08 Thread Stephen Turner

I've looked quickly at all the entries up to 55 strokes, and identified the
following methods for difficult bits of the problem. Apologies for errors
and omissions!

Methods for pulling off all pairs of characters:

s/./ ___`%10+$___ /g   (Ton-47, Jukka-50, Rick-51, ~Chris-53, Andrew-53,
  Lyon-54, Jasper-55, Xavier-55)
s|.| ___$___ if/../g|   (MTV-49)
/(?=(..)./   (Ton-52, Rick-52, Jukka-53, Antti-55, Adam-55)
/..(?{ ___$___ })/  (Stephen-54, Eugene-55)

Methods for calculating the new digit:

hex($1+$2)%15 (Ton-47, Chris-53)
$x%9||9x$x9  (MTV-49)
$x*1.11%10(~Jukka-50, Rick-51, Ton-52)
chop($x)+$x   (Andrew-53)
$x%9||9*!!-$x (Stephen-54)
(0..9,1..9)[$x]   (Lyon-54)
-$x?$x%9||9:0 (Antti-55)
$x%9||0+$x9 (MTV-54, Adam-54, Ton-55, Eugene-55, Adam-55)

(I really like $x*1.11%10. That would have saved me three strokes!)

Methods for looping:

while (Ton-47, Chris-53a, Andrew-53, Adam-54, Antti-55,
   Eugene-55, Jasper-55, Xavier-55)
do$0  (A different Ton-47)
s///g inside s/// (MTV-49, Jukka-50, Rick-51, Chris-53b, Lyon-54
`$^X $0`  (Stephen-54)

-- 
Stephen Turner, Cambridge, UKhttp://homepage.ntlworld.com/adelie/stephen/
This is Henman's 8th Wimbledon, and he's only lost 7 matches. BBC, 2/Jul/01





Re: TPR1 post-mortem

2002-03-08 Thread Eugene van der Pijll

En op 08 maart 2002 sprak Marcelo E. Magallon:
 
  At some point I kept thinking about this in terms
  of abcd - abbccd - xyz, where x=f(ab) and so on.


Me too. Did anyone else notice this:

~$ perl -le'$_=abcd;$,=,;print unpackA2XA2XA2X,$_'
ab,bc,cd

However, I couldn't make anything out of this that was shorter than,
say, 70 chars.

Eugene



Re: TPR1 post-mortem

2002-03-08 Thread Rick Klement

Adam Spiers wrote:
 
 Stephen Turner ([EMAIL PROTECTED]) wrote:
  I've looked quickly at all the entries up to 55 strokes, and identified the
  following methods for difficult bits of the problem. Apologies for errors
  and omissions!
 
 A nice summary :-)
 
  Methods for looping:
 [...]
  `$^X $0`  (Stephen-54)
 
 I considered this recursive approach too but never got anything
 decent.  The rules were maybe slightly vague on this intricacy, but
 couldn't you have shaved two off with this?
 
   `./$0`
 
 It would have passed the test program, and run fine from the
 command-line via `perl secret.pl', but not via `./secret.pl' :-)
 Don't know whether the judges would have accepted it.

Not allowed, by the rule:

When tested, you can assume your script to have file permissions of 0644.

-- 
Rick Klement



Re: TPR1 post-mortem

2002-03-08 Thread Rick Klement

Stephen Turner wrote:
 
 I've looked quickly at all the entries up to 55 strokes, and identified the
 following methods for difficult bits of the problem. Apologies for errors
 and omissions!
 
 Methods for pulling off all pairs of characters:
 
 s/./ ___`%10+$___ /g   (Ton-47, Jukka-50, Rick-51, ~Chris-53, Andrew-53,
   Lyon-54, Jasper-55, Xavier-55)
 s|.| ___$___ if/../g|   (MTV-49)
 /(?=(..)./   (Ton-52, Rick-52, Jukka-53, Antti-55, Adam-55)
 /..(?{ ___$___ })/  (Stephen-54, Eugene-55)

Super analysis !

One small correction, my 51 used:

s/.?/___$`%100___/g

-- 
Rick Klement



Re: TPR1 post-mortem

2002-03-08 Thread Peter Makholm

Adam Spiers [EMAIL PROTECTED] writes:

 decent.  The rules were maybe slightly vague on this intricacy, but
 couldn't you have shaved two off with this?

   `./$0`

No. The rules clearly states that the scripts gets installed with
(unix) file permissions 0664 so you have to call the interpreter
explicitly.

(Or change the filepermissions from inside the script. I don't know if
the judges would accept that)

-- 
Emacs er det eneste moderne styresystem der ikke er multitrådet.



Re: TPR1 post-mortem

2002-03-08 Thread Ton Hospel

In article [EMAIL PROTECTED],
Jason Purdy [EMAIL PROTECTED] writes:
 Someone's gonna explain these, right?  Man, I love learning this kinda stuff. 
  Last hole, I learned about pop vs. shift (saving two strokes) and after 
 seeing this e-mail and playing around with Perl, I see that -l will take 
 care of the newline stuff for me (so I don't have to add $_\n to my print 
 statements [6 strokes there]).

Definitely have a look at the archives of some old golf. Also look
at http://a108.bauhuette.haw-hamburg.de/golf/challenge.html
 
 Is that #*1.11%10 a number theory to get to the same number?  How did someone 
 recognize that pattern? (my advanced calculus/comb math being a lil' rusty)  

In my case it was because i was thinking about how you do multiplication
by hand and got thinking about this sum:

  ab
 ab
ab

ASsb

where s is the last digit of the sum of a and b, and S is the same, but 
with the carry from s added in. And THAT is exactly what we were supposed
to calculate. The sift add pattern you get from 111. So we need the
third-last digit from $num*111, which you can get by dividing by 100
and modulus 10, so you get:

$num*1.11%10

Also, if a+b is small enough as not to give carry (which happens if the
number is 18 or lower), you can use:

$num*1.1%10

The hex() trick i found when enumerating all functions in perlfunc and
thinking about which one changes behaviour at 10. Then you see that 
numbers  10 get through undamaged, and 10 becomes 16 (should be 1) and
they count further again. so add modulus 15 to compensate.

It's only useful for the case where you have two digits from different places.
you need either + or . to combine them, and that has rather low precedence,
so you tend to need the parenthesis anyways, so in a sense the cost is only
6 strokes.

PS: the entries in the scoreboard are not ordered by tie score. 
It's the entry with do$0 that won (better tie-score)

Also a note about looping: in golf only these loops tend to happen
if you need a conditional loop (unlike a fixed loop where s///eg, map and
modifier for are also useful), whose lengths are sometimes a bit hard to
estimate since they depend on how much you can cuddle the thing before
and after:

 - modifier until/while length 5 upto 7 if you can't cuddle
 - for(1;2;3){4}length 7 but only if you can fill all slots. 
Therefore almost never the best loop (you can
cuddle up some postfix stuff though)
 - do$0   length 6, can be 5 if you can can cause the 
called thing to die. Can be 5 or 4 if you can
somehow write the expression so $0 becomes a
result (e.g. do${some_expression} or do
$0|some_expression)

You can basically ignore things like redo (one entry used ..redo for.. in a
way that works, but i rather think that's a perl bug), goto etc. They all
end up longer.

Notice that in this case the number of iterations was constrained by the
input length, so s///eg, map and for based loops are also possible.

Can anyone find counterexmples for other loopingstyles that can be shorter ?



Re: TPR1 post-mortem

2002-03-08 Thread Ton Hospel

In article [EMAIL PROTECTED],
Eugene van der Pijll [EMAIL PROTECTED] writes:
 En op 08 maart 2002 sprak Marcelo E. Magallon:
 
  At some point I kept thinking about this in terms
  of abcd - abbccd - xyz, where x=f(ab) and so on.

 
 Me too. Did anyone else notice this:
 
 ~$ perl -le'$_=abcd;$,=,;print unpackA2XA2XA2X,$_'
 ab,bc,cd
 
 However, I couldn't make anything out of this that was shorter than,
 say, 70 chars.
 
 Eugene

Also fun is this:

perl -wle '$_=abcde; pos=1; print $ while /.\G./g'
ab
bc
cd
de

But I could build nothing useful with that (s/// does not restart)



Re: TPR1 post-mortem

2002-03-08 Thread Marcelo E. Magallon

 Adam Spiers [EMAIL PROTECTED] writes:

   Op(i=1..digits, C(i, digits)*digit[i])

  One step for very unusual bindings of one ;-)

 Well, I mean it like:

1234 - 1 @ 3*2 @ 3*3 @ 4 - 1

 where a @ b means the funky operation we all know already and a * b is
 usual multiplication.

 About this operation, I found it amusing that it's defined for all |N,
 it's closed, associative and commutative.  If you take 0 to be the
 identity, then there are no inverses for elements other than 0, if you
 take 9, 0 doesn't have an identity -- weird thing.

  I'm just gutted that I had considered *1.1 and then rejected it as
  being too much hassle to remove the two outer digits.  If only I'd
  realised I could have done that in 3 extra characters!

 Well... you at least considered it.  When I saw that *1.11%10 I went
 duh!.  I think the marks produced by keys on my forehead are still
 visible :-)

-- 
Marcelo