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: 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: 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}sandtwo 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: 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.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
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: 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[255f]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: 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
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--cprint 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
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: 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: 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
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
[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
[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 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