Re: regex of the month (decade?)
Yanick Champoux schreef: > *dieresis* or *diæresis > >Well I, for one, never knew that such a thing existed. Neato! Too > bad the name of the mark, though, which is definitively unfortunate. According to the infallible Wikipedia, this diacritic is also called a trema. Only if used as a seperation mark, not as an umlaut. HTH Eugene
Re: Punctuation Free Quine -- Almost
Dave Mitchell schreef: > I believe the following is a genuine, punctuation-free Quine: > > s zzs vvxv > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s SxSlcfirstSe > and s YZZxZYvvxvYi and print > z > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s ZVZchr 122Zie > and s SxSlcfirstSe > and s YZZxZYvvxvYi and print Nice. You can go one step further; this one only contains letters and whitespace: s zzs vvxv and s ZVZchr length x x length xxZie and s ZVZchr length x x length xxZie and s ZVZchr length x x length xxZie and s SxSlcfirstSe and s YZZxZYvvxvYi and print z and s ZVZchr length x x length xxZie and s ZVZchr length x x length xxZie and s ZVZchr length x x length xxZie and s SxSlcfirstSe and s YZZxZYvvxvYi and print Eugene
Re: "Secret" operators
Andrew Savige schreef: > The table below is based on wild guesswork. If there are any oldbies > listening, please chime in with corrections. Not an oldbie, but... > @{[]} aka ???The Schwartz early 1990s The Larry, May 1 1994 http://groups-beta.google.com/group/comp.lang.perl/msg/1d82c7c3f3e94266 > y///c aka Abigail's Length Horror The Abigaillate 1990s Although I agree about the name, the inventor seems to have been The Hall, Jun 22 1996 http://groups-beta.google.com/group/comp.lang.perl.misc/msg/7680c5d579b5fc23 > stuff value into $\ for printing The van der Pijll 2001 I'm almost sure that I've seen a very early post by Larry, Randal, or Tom Christiansen (most probably Larry), where this trick is used. I did come up with it independently, though. gr,Eu
Re: unhead
Jose Alves de Castro schreef: > Imagine you want to print a file, but without the first N lines... > > For any N, maybe this: > > print if ($N+1)..0; > > Any thoughts? Any other ideas? What would be the best way to do this? I don't know about "best", but I rather like: 3...!print; to print everything but the first 3 lines. Eugene
Re: Fun - Each character at most once
[EMAIL PROTECTED] schreef: > Can anyone improve the above so that it checks the whole of <>, not just one > line? Bonus points for an explicit multi-character message rather than undef > on failure. #!perl -0234 <>=~m{(.)[^$/]*\1}sand&two contains no characters twice (except for the final \n), checks the whole of <>, and prints a not-very-appropriate message on failure. Eugene
Re: Converting a textfile-like string to an array and back
Andrew Savige schreef: > Aristotle golfed: > > $_=$x;@lines=(/^.*/mg)x+length; > > Against my better judgment, I will have a go at golfing this: > > $_=$x;@l=(/^.*/mg)x/./s This clobbers $_. Not nice for the rest of the program. Correct is: {local$_=$x;@l=(/^.*/mg)x/./s} or @l=(/^.*/mg)x/./sfor$x Unfortunately, you had "use strict" in your first post, and neither of these are use-strict safe. (-ugene -- Call a program "elegant" if no smaller program produces the same output. -- (, _| (haitin
Re: m/(\d+)(a){\1}/ ??
Aaron J Mackey schreef: > > $_ = "2aaa"; > @d = m/(\d+)(a){\1}/; > # @d = (2, a, a); > > That construct doesn't seem to work; Is there a way to get it to work? Even if it would work, the output would be different. Compare: @d = m/(\d+)(a){2}/; print "@d"; # output: 2 a The parentheses around a return only one match, regardless of the number within the {}. You can come close by using the (??{ code }) construct: @d = m/(\d+)((??{"a{$1}"}))/; print "@d"; # output: 2 aa Apparently, ()'s inside the (??{}) do not capture what they match, or else @d = m/(\d+)(??{'(a)'x$1})/; would be exactly what you want. Eugene
Re: Golf contests and naive solutions?
En op 17 maart 2002 sprak Jerome Quelin: > We were wondering if the referees were to provide a naive solution for > perlgolf contests? As y'all know, I have promised to organize the Dutch Masters around Easter. Because of your monthly TPR matches, I don't think anyone will object if the DM will be held in mid-April (say, April 18-22). Anyway, I'm trying to find some fun problems at the moment, and one of the holes will probably be just this: it will be a more difficult problem, but a simple (and long) solution will be given. I've just written that solution, and I'm simplifying it now. > So, what do you think? Should the referees provide a naive solution? We're > waiting for your feedbacks... I don't think it is necessary for all holes. If you're talking about the TPR matches, if the next one is as 'simple' (as in: easy to explain, and with short solutions) as the previous two, there is probably no need. But I'm not really a beginner, so my opinion does not really count. Eugene
Re: rethinking printf
Why not replace the escape character '%' with '#'? No new quoting operators or functions to learn. And introduce a warning if there are no #'s in the format string. Eugene
Re: Perl Golf as a sport
En op 10 maart 2002 sprak Rick Klement: > That split$& was a brilliant move, not ugly at all. I look at that one as > asking the right question: "do you want to count items, or the gaps > between items?" Sometimes it's not finding a good answer that's important, > it's finding a good question! Yes. It would be even more brilliant if that was the way I had found it. Instead, I just tried replacing the substitution with split. And when that didn't work, I asked myself why... But let's keep this between us. There's no need to disillusion the fans out there. Eugene
Re: Perl Golf as a sport
En op 10 maart 2002 sprak [EMAIL PROTECTED]: > Rick is a brilliant golfer and I feel sure he would have found the > same "ugly" improvement from s/$&/$&/g to split$& had he not been > suffering from the giggles. That was NOT an ugly improvement, IMNSHO. When I thought up the idea of counting the fenceposts, I had about the same reaction as Rick when he found the s/$&/$&/ solution. > 3) Be pragmatic. Don't get too carried away with fanciful solutions. > > This is a common failing among chess players; they spend an hour > or more analysing a fanciful line, only to reject it and find > themselves in time trouble later in the game. > > Perhaps, Eugene and Stephen Turner fell into this trap in the > secret number game, where they both pursued deliciously complex > variations involving the (${}) construct in preference to simpler > more pragmatic solutions involving s///eg. Actually, I did look for other solutions; I just could not find them. I did not try the s///eg within s///eg way, as I was sure that couldn't work. Earlier, I had tried things like m#___(?{___/./___})___#, which produced an error message about non-reentrant regex-routines. I know... I should have tried anyway. > Most of the top Perl golfers have such good technique that if you > throw them an idea, they can quickly refine it into a solution. > But how do you find the ideas? Read manpages. Perlrun, perlvar, perlfunc and perlre especially. Turn off the computer and go do something else that does not require much thinking. I get most ideas in the shower, in bed just before I go to sleep, or while riding a bike to/from work. (If anyone on fwp lives around Utrecht & drives a car: please be careful during golf games. Thank you.) > I welcome any practical advice on > this, especially from Ton, who seems most prolific in this area. > For example, how do you dream up things like s//pop/e? I think I have first seen this technique, setting $_ using s///e, in a post by Abigail some years ago. So that's another hint: read Abigail's complete works. Eugene
Re: TPR1 post-mortem
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 unpack"A2XA2XA2X",$_' ab,bc,cd However, I couldn't make anything out of this that was shorter than, say, 70 chars. Eugene
Re: TPR1 post-mortem
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.edu&output=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=en&selm=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
Can anyone explain this entry to me? -l $%=!print,/..(?{$%.=$&%9||0+$&&&9})^/while$_=$%||pop Why does it give the correct result for an argument 0? The while-test $_=$%||pop evaluates to 0, but the loop is executed once anyway. And here's another 55 that I came up with: -l $x+=print,/..(?{$ARGV[$x].=$&%9||0+$&&&9})^/for@ARGV which is nice, but why doesn't this work: -l $x+=print,/..(?{$_[$x].=$&%9||0+$&&&9})^/for@_=pop By the way, congratulations to Ton, and thanks to Dave and Jerome for the wonderful tournament. Eugene
Re: BoB
Stephen Turner schreef op 04 maart 2002: > Well, I see BoB's got 52. I'm still stuck on 60. Still, even if I am > 8 behind BoB, at least I'm only 4 behind Eugene. :-) 5, unless you have taken one off as well. But I do not see how it can be any shorter than that. Eugene
Re: TPR0 Final Results
[EMAIL PROTECTED] schreef op 21 februari 2002: > Ton Hospel schreef op 21 februari 2002: > >> $\=(30+ord lc)%39+36*$\.$/for pop=~/./g;print > >> > >> Hey, that's 45! Stephen, are you happy now? > >> Ton, you are the best golf post-mortem analyst in the world. :) > >> > > You did all the hard work, I just moved some chars around. > > Eugene van der Pijll schreef op 3 februari 2002: > > Beaten? I not understand! The Andrew-Ton collective: 90 Eugene: 89. > > Besides, your solution fails for long files. > > I hope this 45 restores some credibility to the Andrew-Ton collective > whose motto is: "If you can't win the game, win the post-mortem". :) OK, OK, I have to admit that that is impressive. Here are two of my attempts. Enjoy! #!/usr/bin/perl -l [pop=~/.(?{$a=$a*36-55+$&=~y#0-9##*7+ord$&})/g];print$a (58) #!/usr/bin/perl -l $"=",";print~~grep$.gt$_,glob"{@{[0..9,A..Z]}}"x length($.=pop) (66) Eugene
Re: RC4 < 182 bytes
[EMAIL PROTECTED] schreef op 18 februari 2002: > Eugene van der Pijll schreef op 17 februari 2002: > > 151: > > > > sub f{@s[$x,$y]=@s[($y+=$s[$x])%=@s,$x]; > > $s[$x++]+$s[$y]}@k=pop=~/../g;$y+=hex$k[ > > $x%@k],f for@s=0..255;$x=1;$y=0;$x%=@s,p > > rint$_^chr$s[f()%@s]for<>=~/./g > > I haven't got a clue about RC4, Neither have I, and I have no way to test them on long data samples, so test it before you use it... > but inspecting Eugene's > masterpiece, can you save a stroke by replacing: > > rint$_^chr$s[f()%@s]for<>=~/./g > with: > rint$_^chr$s[255&f]for<>=~/./g Ah, then I can save another two strokes: sub f{@s[$x,$y]=@s[($y+=$s[$x])%=@s,$x]; $s[$x++]+$s[$y]-@s}@k=pop=~/../g;$y+=hex $k[$x%@k],f for@s=0..255;$x=1;$y=0;print $_^chr$s[f$x%=@s]for<>=~/./g If you insert a $/=\1; somewhere in the middle, and remove the =~/./g at the end, it accepts multiline input. Eugene
Re: RC4 < 182 bytes
Rocco Caputo schreef op 16 februari 2002: > I can't seem to get it below 160 characters. This is split > arbitrarily at 40 characters; it will not work until joined. > > sub f{@s[$x,$y]=@s[($y+=$s[$x])%=@s,$x]; > $s[$x]+$s[$y]}@k=pop=~/../g;$y+=hex$k[$x > %@k],f,$x++for@s=0..255;$x=$y=0;$x++,$x% > =@s,print chr($s[f()%@s]^ord)for<>=~/./g 151: sub f{@s[$x,$y]=@s[($y+=$s[$x])%=@s,$x]; $s[$x++]+$s[$y]}@k=pop=~/../g;$y+=hex$k[ $x%@k],f for@s=0..255;$x=1;$y=0;$x%=@s,p rint$_^chr$s[f()%@s]for<>=~/./g Eugene
Re: RC4 < 182 bytes
Samy Kamkar schreef op 16 februari 2002: > It's RC4, so far in 182 bytes, accepts a hex key (e.g., a0b1c2) in > $ARGV[0] and reads input from <>: > sub > f{@s[$x,$y]=@s[$y,$x]}@k=map{hex}pop=~/../g;$y=($y+$k[$_%@k]+$s[$x=$_])%256,f > for@t=@s=0..255;$x=$y=0;$x++,$y+=$s[$x%=256]%256,f,print > chr($s[($s[$x]+$s[$y])%256]^ord)for<>=~/./g > > So, any of you have any ideas of shortening it? sub f{@s[$x,$y]=@s[$y%=@s,$x]}@k=map{hex}pop=~/../g;$y+=$k[$_%@k]+$s[$x=$_],f for@t=@s=0..255;$x=$y=0;$x++,$y+=$s[$x%=@s],f,print chr($s[($s[$x]+$s[$y])%@s]^ord)for<>=~/./g (173) It's not exactly the same; I assume that the expression $y+=$s[$x%=256]%256 in your version should be ($y+=$s[$x%=256)%=256 ? Eugene
Re: Golf and the Perl Review
Jerome Quelin schreef op 06 februari 2002: > On Mercredi 6 Février 2002 10:53, Philippe 'BooK' Bruhat wrote : > > I think it's high-time fwp developped the module Game::Golf, or > > Game::PerlGolf, to help handling these contests. > > > > It should have a scoring method (maybe with several scoring rules > > (embedded newlines, etc) And even better, I think it should use > > Test::Harness to handle testing. > > This idea was lying around, since I just developped such a script. I mailed > it to Andrew and Eugene, since they are our arbiters (last and to-come). So, > sorry to both of you guys for duplicate mails. And I'm playing with your script right now. Looks good. We probably need two programs: one for the arbiter, and one for the golfers. The routines that they have in common can be put into a module, but I'm not sure if that is the right thing to do. Installing a module can be a problem, especially for beginners. > Sample code should end with __END__ token, which will (of course) not be > taken as part of the entry. It's easier to end entries with empty lines. If an entry contains an empty line of itself, then one should end it with __END__. Perhaps the participants' program would write out the entries in the correct format, to be sent to the arbiter. > This is not exactly a module, nor does it use Test::Harness, but maybe we can > reuse some part of it. Or let's get rid of it and restart from scratch. > Anyway, if somebody would like to put this idea a little further, then I'm in! I think your script is a good start, and I think I will use it or something like it at the next match. About the next match: I have a few ideas already for the course. I'm thinking of holding it around the middle of March. There will be an announcement about a week before. Eugene to
Re: Flog. Re: substitution question
Bill -OSX- Jones schreef op 04 februari 2002: > > I believe Perl 'Go Fish' would be better - Go Fish? Google-de-google... Ah, Kwartetten! > * You find sets of solutions which match RegEx from a given problem. Or: find the RegEx, given a number of strings that match it. A kind of Perl Zendo (see http://www.wunderland.com/WTS/Kory/Games/Zendo/ for an explanation of Zendo). I think that would make a nice game. Eugene
Re: Beginner's definition ?
[EMAIL PROTECTED] schreef op 03 februari 2002: > How about this? > > printf"%010d\n",$.,<>eugene: 21 strokes > -p }{$_=$.+1e9.$/^"\ca" ton:21 strokes > -p }{$_=$.+1e9.$/^v1 bob:20 strokes > > Proving that Eugene can indeed be beaten, albeit only > after two months of analysis. ;-) Beaten? I not understand! The Andrew-Ton collective: 90, Eugene: 89. Besides, your solution fails for long files. Eugene
My Unorthodox/Artistic entry
[EMAIL PROTECTED] schreef op 28 januari 2002: > > Supremely Unorthodox/Artistic Prizes > > > I will give advance notice, at least: > Eugene (77 char solution) > Keith (74 char solution) > BooK(your gs solution, you know the one) > should definitely participate! After seeing Keiths solution, I have given up hope of winning this, but if anyone is interested: My nicest solution was this one: #!/usr/bin/perl -p $_ x=1&~eval$..join'__|y _y',_,a,e,i,o,u,Y,' __c' The string that gets evaluated for the first line of the file is: "1___|y _ya__|y _ye__|y _yi__|y _yo__|y _yu__|y _yY__|y _y\n__c" The first term in this string is the line number, followed by three underscores. As underscores are allowed in numeric constants, this evaluates to just the line number. The 7th term, "y _yY__" counts the number of y's and Y's in the line. As the line was guaranteed to be in lower case, this is equivalent to counting the number of y's. The other terms count both y's and one other vowel. When the number of y's is even, and the count of y's and a's is even, the number of a's is also even. I could also have counted all vowels individually, but then I should have written them as a,e,i,o,u,'y' , as an unquoted y is interpreted as the transliteration operator. The important thing here is the choice of the y/// delimiters. Other possible solutions of the same length are: #!/usr/bin/perl -p $_ x=1&~eval$..join'*//|y/y',_,a,e,i,o,u,Y,' //c' and #!/usr/bin/perl -p $_ x=1&~eval$..join"## |y#y",_,a,e,i,o,u,Y,' ##c' Of course, all these solutions can easily be shortened by one character: #!/usr/bin/perl -p $_ x=1&~eval join'__|y _y',$.,a,e,i,o,u,Y,' __c' However, I only noticed that when I started writing this post. I abandoned this approach when I saw that Rick Klement was at 69, a full 8 strokes under my score. Eugene
Re: some questions on golf
Rick Klement schreef op 29 januari 2002: > Joerg Ziefle wrote: > > > > * How sick do you have to be to come up with those <50 stroke solutions for >even.pl? :) > > I can't speak for Eugene, but I've had a low-grade fever > going on two weeks now. > > I hadn't thought about it that way, but maybe it *did* help :) I'm sure it didn't. I sent in my best solution on friday (I think), and have been in bed with a severe headache only since yesterday afternoon. Eugene
Re: even.pl solutions
Stephen Turner schreef op 29 januari 2002: > Five programs didn't use $. , of which the shortest is this one from Ton > Hospel in equal third place: > > -ln ($a=aeiouy)=~s!!--&~y-!g;eval"\$|$a--c&&print" 50 ton > > It's another meta-program. The line counting is done by $|-- , although even > that isn't obvious until you've worked out what $a is above. There is more going on than that. Why does Ton use the variable $| ? Any other variable doesn't work... Eugene
Re: FORE! Get Even Golf Game Tees Off
[EMAIL PROTECTED] schreef op 28 januari 2002: > ''=~('('.'?'.'{'.( > '['^'+').('['^')').('`'| > ')').('`'|'.').('['^'/').'"' >.('`'^'#').('`'|'!').('`'|"\.").( [snip] Aaargh! Was that really necessary? Eugene
Re: Possible improvements for the next golf apocalypse
If no-one objects, I will organize the next Golf tournament somewhere around Easter next year. I won't call it the Easter Apocalypse, however, as that will not be appreciated by some people... > While it is still fresh in everyone's minds, I thought I should > make some notes on possible improvements for the next apocalypse. The word 'apocalypse' is already in use for a type of Perl Golf tournament, so it is perhaps not the right name. I'm open to suggestions. > 1. Timing > > We probably all spent more time on this than we can afford. > I think 5 days was too long; 2-3 days feels about right. I think 5 days is just the right length. After all, quality code costs time, and all of the runners-up achieved their 91 score in the last two days. Beginning on a Thursday seems to be a good idea. > It seems fairest to announce the game start time two weeks (say) > before the event, to give people time to prepare. Yes. > 2. Tie-breaking rule > > I chose to break ties by rewarding the first to post. > I suppose other ways are possible (e.g. reward the more > efficient one) but they all seem a little artificial. I like the idea of awarding prizes to the 'best' or 'most original' solutions. Perhaps the 'first to post' rule is best for the overall standings, while the 'best per hole' prize will go to the most original entry. > 3. Number of Holes > > Though 9/18 is traditional in golf, five seemed sufficient to > provide an interesting spread of scores. Any more than five > may be unnecessarily cruel. > > 4. Hole Difficulty > > When I posted the game, I thought the holes were too easy. > In retrospect, I think they were about right because they were > simple enough to allow novice golfers to have a go, while still > providing a challenge for the elite golfer. The difficulty of the holes is not easy to judge. Probably I will go for three or four easy, short holes, par 30 or lower, and one or two longer ones, with par around 80, say. > 5. Individual Hole Scores - to post or not to post? > > The individual hole scores were kept secret until Eugene, in a > sportsmanlike gesture, revealed his leading scores about 16 > hours from the end. I think this worked quite well. > > However, I suggest that in future games the Arbiter should reveal > the leading scores for each hole about 4-8 hours from the end. > This should make the final hours quite exciting. It should be somewhere between 12 and 24 hours to give everyone in all time-zones the chance to read them. > 6. Perl Version > > Interestingly, I never stated the Perl version, and had no > trouble in this area! I suppose it should work on the > latest stable version of Perl. All solutions should work in perl 5.6.1, will probably be the rule next time. > 7. Scoring Rule > > There seem to be two reasonable scoring rules: > 1) The "cross-platform" one-liner that I chose. > 2) The multi-line rule (with newline counting as 1, > but not on the leading #!perl line) as implemented > in Keith C Ivey's submitted GolfScore() function. I think next time multi-line programs will be allowed, with newlines counting as one stroke. > ... Had I allowed multiple lines, I am > certain Eugene would have found the multi-line solutions > found by others on hole 4. I'm not so sure about that. I didn't consider using multiple lines at all. > 8. Fairness > > I think the key to a fair game is a really tight test program > on day one (tsanta.pl had too many holes). It is ideal if you > can just say "if it passes the test program, it is ok"; > that also eliminates ambiguity about the game's semantics > and spares you from having to describe the semantics. I don't think that can be done. Some rules should have been a bit clearer, but you can't foresee every loophole that will be used. I found the test program very useful, so as a referee I will make it public at the start of the competition. However, programs that pass the test program but have fatal effects (output to STDERR, fail for n>100 etc.) will be disqualified. Eugene
Re: Santa Hole 4 (mid.pl) Post Mortem
Rick Klement schreef op 07 december 2001: > The one I did that I liked was > > sub{shift,pop while@_>2;print@_}->(<>) How about: sub a{@_>2?shift^pop^&a:print@_}a<> Note that ^ is almost the only possible operator between shift, pop and &a here. Most other operators give either a warning or a fatal error. Eugene
Re: Santa Hole 4 (mid.pl) Post Mortem
Philip Newton schreef op 07 december 2001: > On Fri, 7 Dec 2001 10:58:03 +1100 , [EMAIL PROTECTED] (Andrew Savige) > wrote: > > > *** Hole 4 (mid.pl) *** > > --- Piers Cawley - 25 > > #!/usr/bin/perl -p0 > > $_=$1while/.(^.+)^/ms > > --- Rick Delaney - 25 > > #!/usr/bin/perl -p0 > > $_=$1while/.^(.+)^/sm > > --- Karsten Sperling - 25 > > #!/usr/bin/perl -p0 > > $_=$1while/.(^.+^)/sm > > --- Eugene van der Pijll - 25 > > #!/usr/bin/perl -p0 > > $_=$1while/.^(.+)^/ms > > --- Keith C Ivey - 25 > > #! /usr/bin/perl -p0 > > $_=$1while/.(^.+)^/ms > > Interesting how different people liked that ^'s in different places :) Yes. And no one went for the variants with \n: #!/usr/bin/perl -p0 $_=$1while/\n(.+)^/ms Also, a majority of perl golfers prefer ms over sm. Another important fact: the array @F is only used by the best golfers. The lesser gods use @a and @_ almost exclusively. One of my more interesting tries on this hole was int.5+($.-=2)/2||print for<> Eugene
Re: Santa Hole 1 (head.pl) Post Mortem
[EMAIL PROTECTED] schreef op 06 december 2001: > On Thu, 06 December 2001, [EMAIL PROTECTED] wrote: > > --- Aaron D Marasco -- 12 > > #!/usr/bin/perl -p > > 11..exit; > > [ Duh... semicolon... just to say publicly what I said on > submission... he encouraged newbies... :) ] I forget to remove the semicolons sometimes too... You also missed a space in rev.pl, and didn't use the famous }{ trick in wc.pl. With a bit more experience, you would have equalled the best score at all of those holes, which is not bad at all for a newbie. These are things which will probably be in the first chapter of the Perl Golf handbook that Japhy proposed. I would be glad to help with that, by the way. > > --- Yanick --- 13 > > #!/usr/bin/perl -p > > $_ x=$.<11 > > Can this one be explained please? (And can we keep explanations in the > per-hole threads?) $_ = $_ x ($.<11); $_ is repeated ($.<11) times. So for the first ten lines, $.<11 evaluates to 1, and $_ stays the same. For the other lines, $.<11 is false, which evaluates to 0 in a numeric context, and $_ is repeated zero times, so $_=''. Eugene
Re: The Santa Claus Golf Apocalypse
Jeff 'japhy' Pinyan schreef op 06 december 2001: > On Dec 6, Piers Cawley said: > > >[EMAIL PROTECTED] writes: > > > >> *** Eugene van der Pijll: 89 (11 19 13 25 21) *** > >> --- rev.pl - > >> #!/usr/bin/perl -p > >> $\=$_.$\}{ > > > >That's just *beautiful*. I just couldn't see past 'print reverse<>'. > > I tried that route for hours (and a whiskey sour). I couldn't get it to > mesh. DAMN that's brilliant. I almost fell off my bike when I thought of that one. Of course, your solution is more readable. Eugene
Re: The Santa Claus Golf Apocalypse
[EMAIL PROTECTED] schreef op 07 december 2001: > According to my reckoning, there is 2 hours to go > before the cut-off time. Do you have daylight savings time in Australia? According to your last post there is still 3 hours to go. Eugene
Re: The Santa Claus Golf Apocalypse
[EMAIL PROTECTED] schreef op 06 december 2001: > > "if there is any interest" ... hmm, Piers, do you give a damn? > Eugene, I think there is intense interest in your scores! I did get that impression. > I would like to leave it up to Eugene to decide when/if he posts > his scores. I will be sleeping a few hours before the deadline, > so I tell you now that Eugene holds the lowest or equal lowest > score for each and every hole. Now that I know the best scores, it would be unfair not to share them with the competition. So with less than 16 hours to go, these are the scores to beat: head.pl 11 tail.pl 19 rev.pl 13 mid.pl 25 wc.pl 21 -- 89 Good luck, everyone Eugene
Re: The Santa Claus Golf Apocalypse
[EMAIL PROTECTED] schreef op 06 december 2001: > Eugene van der Pijll wrote: > > Just post the entries of the top-5 to fwp, and let everyone comment, > > including the competitors. > > You're right; it's the Perl way. I am sure the competitors can > agree among themselves. In the unlikely event of a dispute, > I can call in the independent experts for a decision. > > Out of respect for the Perl journeyman, however, I am inclined > to post all solutions. That's OK, you're the one doing all the work. Perhaps it would be best to begin a new thread for each of the problems. This is already the largest thread on fwp since I don't know when. I could post my scores for each hole a few hours before the deadline, if there is any interest. Or you can post the best scores per hole, if those are different. Just to encourage the competition... Eugene
Re: The Santa Claus Golf Apocalypse
Bernie Cosell schreef op 05 december 2001: > On 5 Dec 2001, at 14:09, Eugene van der Pijll wrote: > > > Bernie Cosell schreef op 05 december 2001: > > > Meta-question: since Perl is content to try to *call* '&main::;' is there > > > some trickery to *DEFINE* such a subroutine? For example, trying: > > >main:: { die; } > > > gets you what I would have expected in the '..&' case: a syntax error for a > > > missing subroutine name. > > > > perl -e'*;=sub {1}; print &;' > > good heavens.. the actual subroutine name is semi-colon?? So the name isn't > missing and isn't null, but is ';'. I'm not sure that that doesn't make it > MORE confusing to me --- Are there other punctuation marks that work in that > context?? > > Three questions: > 1) is semicolon the ONLY puncuation mark that has this odd > special-dispensation? I'd expect not. > 2) WHY does perl allow this --- it still seems like a slam-dunk syntax error > situation to me The global variables @a, $a, %a and &a are all stored in the same data structure (the typeglob, see perldata). Therefore, if the subscript separator variable $; can be used, there should be an entry in the symbol table for ;, and @;, %; and &; are valid names. > 3) who *discovered* this anomaly? [how does someone even think to TRY > something bizarre like this.] In my case, I discovered it quite accidentally. I replaced exit with &f, resulting in an 'undefined subroutine f called' error. Then Piers said it could be one character shorter... Eugene
Re: The Santa Claus Golf Apocalypse
Bernie Cosell schreef op 05 december 2001: > Meta-question: since Perl is content to try to *call* '&main::;' is there > some trickery to *DEFINE* such a subroutine? For example, trying: >main:: { die; } > gets you what I would have expected in the '..&' case: a syntax error for a > missing subroutine name. perl -e'*;=sub {1}; print &;' Eugene
Re: The Santa Claus Golf Apocalypse
[EMAIL PROTECTED] schreef op 05 december 2001: > Given that tsanta.pl has many loopholes, a panel of experts will > than examine the leading solutions for correctness (disqualifying > an entry that fails for files longer than 100 lines, for example). > To avoid an obvious conflict of interest, I suggest that only > non-competitors be invited to the panel. Just post the entries of the top-5 to fwp, and let everyone comment, including the competitors. > Please let me know when you think we should end the game. As soon as possible. Eugene
Re: The Santa Claus Golf Apocalypse
Piers Cawley schreef op 04 december 2001: > Eugene van der Pijll <[EMAIL PROTECTED]> writes: > > > There is a very nice 26-character mid.pl solution which is not based on > > anything in that thread. > > Hmm... I think I have the same mid.pl as you. So, I need to get three > chars off either tail.pl or wc.pl then I should say that I only found this solution today, and it was no improvement on my previous solution, which was based on the earlier thread. So that conclusion is not necessarily correct... Eugene
Re: The Santa Claus Golf Apocalypse
Piers Cawley schreef op 04 december 2001: > > Hmm. Oh yeah, I just got rid of the -p trickery I was using in wc.pl. > Shame about the 'all on one line' rule or I'd be down to 90 now... How > Eugene got down to 89 is a completely mystery though. -p trickery? In wc.pl?? I haven't found any reasonable -p solution there. -n yes. -p? Impossible. I think I would be at 87 if newlines were allowed, 84 with the & solution. > > (Of course, I'd also like to see the "best score per hole", but I > > guess that got "voted down".) > > Seems so. I'd like to know what the best scores per hole are. On the one hand, perhaps I could sleep easier then. On the other hand, you'll have much more incentive to look for solutions... Perhaps it's better without the best scores per hole. Eugene
Re: The Santa Claus Golf Apocalypse
[Sorry Philippe, I sent this as a private reply first, so you've seen this already...] Philippe 'BooK' Bruhat schreef op 04 december 2001: > On Tue, 4 Dec 2001, Rick Klement wrote: > > I'm now at 92 with no assistance :) > > I am at 94 with the assistance of the previous fwp thread for mid.pl... There is a very nice 26-character mid.pl solution which is not based on anything in that thread. > And I also cheated in head.pl (tsanta.pl accepts it, but it doesn't work > as expected...) to shave off one keystroke. If you have the same solution as Piers and me, that cheat will not be accepted by Santa. > > Mine are all simple straightforward perl, with only one using a > > command line switch, and then just with the obvious usage, none > > of this hinted trickery. I guess I'm just not trying hard enough. :) > > I guess mine are too. But Piers head.pl entry (I refer to the use.perl.org > journal entry I shouldn't have read) is very good. And it's > straightforward Perl, as documented in Amelia. I didn't think about it, > even though I translated the whole chapter 3 in French. :-S One of my solutions depends on rather illogical behaviour, which is not defined in any documentation that I know of. one or more of the others use rather obscure constructs, comparable to the one used in Piers' head.pl. > I am very curious to see what else than the obvious can be done for > rev.pl. And I wonder if shorter than the obvious is possible (I guess so). The obvious one was, I guess, found by one of the first submitters. According to the first standings, Japhy was the first hole leader, even though several people with a lower total score came along later. Let's assume that he had that obvious solution. If there is a new leader on hole 3 in the next standings, there must be a shorter one... Eugene
Re: The Santa Claus Golf Apocalypse
Piers Cawley schreef op 03 december 2001: > Eugene van der Pijll <[EMAIL PROTECTED]> writes: > > > > Of course, using what I assume to be the same hack, my score goes > > down > > by two strokes as well... > > Only two? You can get it down by three. You're right, after some experimenting, I found the 1-character exit. How very... interesting... if that is the right word. Eugene
Re: The Santa Claus Golf Apocalypse
[EMAIL PROTECTED] schreef op 04 december 2001: > Piers has found some brilliant hacks, no question. > I don't want to give too much away by going in to more detail. > I think this one will have to be decided by a panel > of experts at the end of the game. I honestly don't > feel qualified to allow or disqualify right now. We'll see... > For now, assume that Piers is on 92, but that > may drop depending on what the jury decides. Of course, using what I assume to be the same hack, my score goes down by two strokes as well... Eugene
Re: The Santa Claus Golf Apocalypse
Santa wrote: > As an early Christmas present, you are invited to play > Santa Claus' newly constructed 5-hole golf course. Great idea! How long will the game be? Until Christmas? And how do you want to receive the five programs? Zipped, as attachments, in the mail body? > [...] I am open to > ideas re the winner's prize. The winner gets to organize the Easter golf competition? Eugene
Re: middle line (was Re: Daily Perl FAQ...)
Eugene van der Pijll schreef op 30 november 2001: > perl -p0 -e'$_=$1while/\n(.*)\n./s' Oops, this has problems with blank lines at the end of the file. Doesn't matter, Andrew's last try is the same length. Eugene
Re: middle line (was Re: Daily Perl FAQ...)
[EMAIL PROTECTED] schreef op 30 november 2001: > Yannick's last solution: > > perl -p0 -e'$_=$1while/\n(.*)\n/s' (Yv3.2) > > prints two centre lines when presented with a > test file containing an odd number of lines. This can be repaired at the cost of one stroke: perl -p0 -e'$_=$1while/\n(.*)\n./s' This prints the two centre lines for files of even length, which is more reasonable. > I think this leaves the current golf leader as > Eugene on 37 strokes (35 under par) with: > > perl -p0 -e'$_=(/(.*\n)/g)[y|\n||/2]' > > Eugene, I like this solution (and I think we should > have an 'open' category in any case), but there > may be a protest if someone suggests this solution > violates the 'no array' requirement. It's a list! Not an array! But you're right, both solutions are O(n) in memory. The shortest O(1) solution I've found is a variant of Ian Phillipps' solution: perl -e'open$_,$ARGV[0]for F,G;while,;die$_=' Eugene
Re: middle line (was Re: Daily Perl FAQ...)
Jeff 'japhy' Pinyan schreef op 29 november 2001: > >> > perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//' > >> perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//' (Yanick) > >> perl -p0 -e'$n=y|\n||>>1;s/(.*\n){$n}//;s/\n.*//s'(Andrew) > >> perl -p0 -e'$n=1+y|\n||/2;/(.*\n){$n}/;$_=$+' (Yv2.0) > > perl -p0 -e'$n=1+y|\n||/2;($_)=/(.*\n){$n}/' (japhy) These last two don't work for me if there is an odd number of lines (when $n is fractional). This one does: perl -p0 -e'$_=(/(.*\n)/g)[y|\n||/2]' Eugene