perl.golf http://www.nntp.perl.org/group/perl.golf/ ... Copyright 1998-2008 perl.org Mon, 06 Oct 2008 13:59:22 +0000 ask@perl.org scrabble word scorer by Jasper Hi, y&#39;all,<br/><br/>Can anyone beat 55 on this? I don&#39;t know if we ever did it as a<br/>challenge. Should I search for it in the book?<br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/06/msg2506.html Tue, 17 Jun 2008 03:44:15 +0000 Re: 答复: A challenge to explain the strange results (under linux) by Daniel Tiefnig Zhu Shanshan wrote:<br/>&gt; As you said, when I substituted &quot;s/\r\n$//&quot; with &quot;chomp&quot;, it did<br/>&gt; work. After looking up the explanation of &quot;chomp&quot; in perldoc, I found<br/>&gt; &quot;chomp&quot;, which I always used to remove the newline previous, removes<br/>&gt; any trailing string that corresponds to the current value of &quot;$/&quot;.<br/><br/>Hej,<br/><br/>JFTR, you may also want to have a look at &quot;perldoc perlport&quot;. The first<br/>issue discussed is &quot;Newlines&quot;.<br/><br/>lg,<br/>daniel<br/> http://www.nntp.perl.org/group/perl.golf/2008/06/msg2505.html Thu, 12 Jun 2008 09:56:56 +0000 答复: A challenge to explain the strange results (under linux) by Zhu Shanshan Thanks.<br/>As you said, when I substituted &quot;s/\r\n$//&quot; with &quot;chomp&quot;, it did work. After<br/>looking up the explanation of &quot;chomp&quot; in perldoc, I found &quot;chomp&quot;, which I<br/>always used to remove the newline previous, removes any trailing string that<br/>corresponds to the current value of &quot;$/&quot;. And this time, it removed &quot;\n&quot; for<br/>me. I&#39;m really puzzled by this phenomena, because I always work with<br/>&quot;chomp&quot;. I guessed the problem came from the new SFTP software used<br/>recently. Then I compared it with WinSCP using the same script. Bingo!<br/>WinSCP has deleted &quot;\r&quot; for me and that&#39;s why I could luckily work,<br/>previous.<br/><br/>Anyway, thank you again!<br/><br/><br/>-----&#x90AE;&#x4EF6;&#x539F;&#x4EF6;-----<br/>&#x53D1;&#x4EF6;&#x4EBA;: Ronald J Kimball [mailto:rjk-perl-golf@tamias.net] <br/>&#x53D1;&#x9001;&#x65F6;&#x95F4;: 2008&#x5E74;6&#x6708;12&#x65E5; 12:28<br/>&#x6536;&#x4EF6;&#x4EBA;: Zhu Shanshan<br/>&#x6284;&#x9001;: Perl Golf<br/>&#x4E3B;&#x9898;: Re: A challenge to explain the strange results (under linux)<br/><br/>I would bet that your color.txt file has Windows line endings on all<br/>platforms. If you do this:<br/><br/> perl test.pl color.txt | less<br/><br/>you may find that you&#39;re getting output after all.<br/><br/><br/>Make sure color.txt has Unix line endings on the Linux machines. Here&#39;s<br/>one way to fix it:<br/><br/> perl -pi -e &#39;tr/\r//d&#39; color.txt<br/><br/>Ronald<br/><br/><br/> http://www.nntp.perl.org/group/perl.golf/2008/06/msg2504.html Wed, 11 Jun 2008 22:30:31 +0000 Re: A challenge to explain the strange results (under linux) by Ronald J Kimball I would bet that your color.txt file has Windows line endings on all<br/>platforms. If you do this:<br/><br/> perl test.pl color.txt | less<br/><br/>you may find that you&#39;re getting output after all.<br/><br/><br/>Make sure color.txt has Unix line endings on the Linux machines. Here&#39;s<br/>one way to fix it:<br/><br/> perl -pi -e &#39;tr/\r//d&#39; color.txt<br/><br/>Ronald<br/> http://www.nntp.perl.org/group/perl.golf/2008/06/msg2503.html Wed, 11 Jun 2008 21:28:28 +0000 A challenge to explain the strange results (under linux) by Zhu Shanshan I used perl &quot;v5.8.5 built for i386-linux-thread-multi&quot;.<br/><br/> <br/><br/>My data:<br/><br/>##################### File:color.txt<br/><br/>chartreuse<br/><br/>deeppink<br/><br/>goldenrod<br/><br/>lightblue<br/><br/>dodgerblue<br/><br/>darkgoldenrod<br/><br/> <br/><br/>My scripts:<br/><br/>##################### File: test.pl<br/><br/>use strict;<br/><br/>use warnings;<br/><br/>open IN,&quot;color.txt&quot; or die;<br/><br/>while (&lt;IN&gt;){<br/><br/> chomp;<br/><br/> print &quot;$_&quot;;<br/><br/>}<br/><br/>close IN;<br/><br/> <br/><br/>Results under linux platform(Nothing):<br/><br/>&quot;Linux compome 2.6.12-1.1381_FC3smp #1 SMP Fri Oct 21 04:03:26 EDT 2005 i686<br/>i686 i386 GNU/Linux&quot; RedHat<br/><br/>&quot;Linux biome 2.6.9-55.ELsmp #1 SMP Fri Apr 20 16:36:54 EDT 2007 x86_64<br/>x86_64 x86_64 GNU/Linux&quot; RedHat<br/><br/>&quot;Linux hanlab 2.6.16.46-0.12-smp #1 SMP Thu May 17 14:00:09 UTC 2007 i686<br/>i686 i386 GNU/Linux&quot; OpenSUSE<br/><br/>##################### command: perl test.pl<br/><br/> <br/><br/> <br/><br/>Results under Microsoft Windows XP (in my expectation):<br/><br/>##################### command: d:\soft\bin\perl.exe test.pl<br/><br/>Chartreusedeeppinkgoldenrodlightbluedodgerbluedarkgoldenrod<br/><br/> <br/><br/> <br/><br/>It&#39;s not really a Perl challenge. But can anyone give me some help or<br/>suggestions?<br/><br/>Thanks in advance<br/><br/> <br/><br/>Shanshan Zhu<br/><br/><br/> http://www.nntp.perl.org/group/perl.golf/2008/06/msg2502.html Wed, 11 Jun 2008 21:00:16 +0000 Re: google's challenges by Jasper 2008/5/30 Randal L. Schwartz &lt;merlyn@stonehenge.com&gt;:<br/>&gt;&gt;&gt;&gt;&gt;&gt; &quot;Jasper&quot; == Jasper &lt;jaspermccrea@gmail.com&gt; writes:<br/>&gt;<br/>&gt; Jasper&gt; Well, that was a big assumption, then.<br/>&gt;<br/>&gt; Keep in mind, &quot;obvious&quot; to you is very unlikely &quot;obvious&quot; to everyone else,<br/>&gt; since we all run in different circles.<br/><br/>I only found out about it because the guy next to me was doing them.<br/>They do seem to be somewhat under the radar.<br/><br/>The third one opened yesterday. It wasn&#39;t really worthwhile writing a<br/>program to solve it.<br/><br/>The robots one is still the only one I&#39;d consider golfable. If one<br/>allows the answers to be in non-integer format, the answer can be<br/>pretty small - I have it around 48 with command line arguments. About<br/>70 with the integer format required by google, and that&#39;s using<br/>Math::BigInt.<br/><br/>Have a nice weekend..<br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2501.html Fri, 30 May 2008 02:07:12 +0000 Re: google's challenges by merlyn &gt;&gt;&gt;&gt;&gt; &quot;Jasper&quot; == Jasper &lt;jaspermccrea@gmail.com&gt; writes:<br/><br/>Jasper&gt; Well, that was a big assumption, then.<br/><br/>Keep in mind, &quot;obvious&quot; to you is very unlikely &quot;obvious&quot; to everyone else,<br/>since we all run in different circles.<br/><br/>-- <br/>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095<br/>&lt;merlyn@stonehenge.com&gt; &lt;URL:http://www.stonehenge.com/merlyn/&gt;<br/>Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.<br/>See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion<br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2500.html Thu, 29 May 2008 18:02:43 +0000 Re: google's challenges by Bram On Tue, 27 May 2008 13:27:54 +0200, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/><br/>&gt; Has anyone been golfing the google challenges?<br/><br/>What challenges?<br/><br/>&gt;<br/>&gt; I&#39;ve got the robot one to around 74 characters (not including the &#39;use<br/>&gt; Math::BigInt&#39; :))<br/>&gt;<br/>&gt; The other one didn&#39;t seem all that interesting in comparison..<br/>&gt;<br/>&gt; ~~~tumbleweed~~~<br/><br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2499.html Tue, 27 May 2008 06:54:07 +0000 Re: google's challenges by Jasper 2008/5/27 Bram &lt;p5p@perl.wizbit.be&gt;:<br/>&gt; On Tue, 27 May 2008 13:27:54 +0200, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt;<br/>&gt;&gt; Has anyone been golfing the google challenges?<br/>&gt;<br/>&gt; What challenges?<br/><br/>Well, that was a big assumption, then.<br/><br/>http://treasurehunt.appspot.com/<br/><br/>Two so far, more on the way, first to complete them all correctly wins<br/>a prize. An Aston Martin, I think.<br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2498.html Tue, 27 May 2008 06:15:41 +0000 google's challenges by Jasper Has anyone been golfing the google challenges?<br/><br/>I&#39;ve got the robot one to around 74 characters (not including the &#39;use<br/>Math::BigInt&#39; :))<br/><br/>The other one didn&#39;t seem all that interesting in comparison..<br/><br/>~~~tumbleweed~~~<br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2497.html Tue, 27 May 2008 04:28:02 +0000 Re: Just chipping in... by Jasper stupid reply-to<br/><br/>2008/5/19 Jasper &lt;jaspermccrea@gmail.com&gt;:<br/>&gt; 2007/11/20 Tuomo Salo &lt;bass@iki.fi&gt;:<br/>&gt;&gt; This one has no performance issues and is even a little bit shorter. Yay!<br/>&gt;&gt;<br/>&gt;&gt; #!perl -l<br/>&gt;&gt; $r=qr/\((??{$r})*\)/;map/^$r+$/&amp;&amp;print,glob&quot;{(,)}&quot;x2x pop<br/>&gt;<br/>&gt; OK, so it took me a number(!) of months, but this is shorter, and<br/>&gt; prints in order..<br/>&gt;<br/>&gt; #!perl -l<br/>&gt; eval&#39;$c-=fork?wait&amp;&amp;$c?s//(/:.1:- s//)/;&#39;x2x pop||print<br/>&gt;<br/>&gt; Didn&#39;t I read a proverb somewhere about a tortoise and a hare, and the<br/>&gt; tortoise losing his job, and the hare shifting the blame onto the<br/>&gt; ex-tortoise?<br/>&gt; --<br/>&gt; Jasper<br/>&gt;<br/><br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/05/msg2496.html Mon, 19 May 2008 08:59:47 +0000 Re: Upcoming event by Peter Johncke <br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/><br/>&quot;Keep On Swinging&quot;<br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/><br/>Great Chain [http://rs6.net/tn.jsp?e=001bTia2OQdbhzJoyecAuMdehbAb848anStrR0Y5F_vzWufXVBQgwH2acZqZ4ApMTo5AJi7tF9_N1ibE_I4Nx-03nqr9_sCGFB7G166IHlrES6GWwuRLxKgipl2QR64teEl]<br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/><br/>&quot;The Trick Shot Master presents an unforgettable Golf Spectacle unlike anything <br/>you have ever seen&quot;<br/><br/>Peter Johncke &quot;The Trick Shot Master&quot; brings you a Golf Show unlike anything you<br/> have ever seen.<br/><br/>. Peter travels all over the world with his amazing show.<br/><br/>For information and booking an appearance for your next event contact us by calling<br/>or email:<br/><br/>The Trick Shot Master<br/><br/>Tel. +1-561-627-2437<br/><br/>E-mail: info@trickshotmaster.com [mailto:info@trickshotmaster.com]<br/><br/>www.trickshotmaster.com [http://rs6.net/tn.jsp?e=001bTia2OQdbhzJoyecAuMdehbAb848anStrR0Y5F_vzWufXVBQgwH2acZqZ4ApMTo5AJi7tF9_N1ibE_I4Nx-03nqr9_sCGFB7G166IHlrES6GWwuRLxKgipl2QR64teEl]<br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/><br/>The Trick Shot Master<br/>1464 Cupcoy Ave<br/>Jupiter, Florida 33458<br/>+1 (561) 627-2437<br/><br/>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br/>Forward email<br/>http://ui.constantcontact.com/sa/fwtf.jsp?m=1010984599072&amp;ea=golf@perl.org&amp;a=1102057415786<br/><br/><br/>This email was sent to golf@perl.org,<br/>by peter@trickshotmaster.com<br/><br/>Update Profile/Email Address<br/>http://visitor.constantcontact.com/d.jsp?v=001hFoVgtC2xN_mgYHQeroXohXla1D0SDLhJVk7fIUtPzidW6VpiZujCdohtSmpJoc-iXF6s2S9ilw%3D&amp;p=oo<br/><br/>Instant removal with SafeUnsubscribe(TM)<br/>http://visitor.constantcontact.com/d.jsp?v=001hFoVgtC2xN_mgYHQeroXohXla1D0SDLhJVk7fIUtPzidW6VpiZujCdohtSmpJoc-iXF6s2S9ilw%3D&amp;p=un<br/><br/>Privacy Policy:<br/>http://ui.constantcontact.com/roving/CCPrivacyPolicy.jsp<br/><br/><br/>Email Marketing by<br/>Constant Contact(R)<br/>www.constantcontact.com<br/><br/><br/>The Trick Shot Master | 1464 Cupcoy Ave | Jupiter | FL | 33458<br/> http://www.nntp.perl.org/group/perl.golf/2008/04/msg2495.html Mon, 14 Apr 2008 02:35:38 +0000 Re: Just chipping in... by Jasper if anyone is still listening (ha) - someone reminded me of this last<br/>week, so I spent another 10 minutes looking at it.<br/><br/>#!perl -l<br/>eval&#39;$c-=fork?$c?s//(/:exit:- s//)/;&#39;x2x pop or print<br/><br/>is the shortest I can get with this forking method, which still prints<br/>the results in a random order, but it&#39;s shorter than bass&#39;s.<br/><br/>Jasper<br/><br/>On 23/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt; On 23/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt;<br/>&gt; &gt; Just thought of this.<br/>&gt; &gt;<br/>&gt; &gt; Probably has performance issues and is a little bit longer. Boo!<br/>&gt; &gt;<br/>&gt; &gt; #!perl -l<br/>&gt; &gt; $l=2*pop;fork?$l&gt;$c++?$_.=&#39;(&#39;:exit:$c--?$_.=&#39;)&#39;:exit while$l--;print<br/>&gt; &gt;<br/>&gt; &gt; Doesn&#39;t order correctly (it would if I added a wait), doesn&#39;t print<br/>&gt; &gt; right, but everyone loves potentially killing their machine with a<br/>&gt; &gt; fork. Can&#39;t get rid of the two exits, so there seems to be flab for<br/>&gt; &gt; sure<br/>&gt;<br/>&gt;<br/>&gt; Flabby indeed<br/>&gt;<br/>&gt; #!perl -l<br/>&gt; $_.=fork?$c--?&#39;)&#39;:exit:++$c&amp;&amp;&#39;(&#39;for($_)x(2*pop);$c||print<br/>&gt;<br/>&gt; That&#39;s the same length as bass, but still with the same problems. A<br/>&gt; waitpid does solve the ordering problem, but the only way to stop the<br/>&gt; overall parent exiting before all the permutations have printed is to<br/>&gt; do something awful. Those solutions add lotsa characters... :(<br/>&gt;<br/>&gt; --<br/>&gt;<br/>&gt; Jasper<br/>&gt;<br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2008/03/msg2494.html Mon, 31 Mar 2008 07:27:32 +0000 Re: Just chipping in... by Jasper On 23/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/><br/>&gt; Just thought of this.<br/>&gt;<br/>&gt; Probably has performance issues and is a little bit longer. Boo!<br/>&gt;<br/>&gt; #!perl -l<br/>&gt; $l=2*pop;fork?$l&gt;$c++?$_.=&#39;(&#39;:exit:$c--?$_.=&#39;)&#39;:exit while$l--;print<br/>&gt;<br/>&gt; Doesn&#39;t order correctly (it would if I added a wait), doesn&#39;t print<br/>&gt; right, but everyone loves potentially killing their machine with a<br/>&gt; fork. Can&#39;t get rid of the two exits, so there seems to be flab for<br/>&gt; sure<br/><br/>Flabby indeed<br/><br/>#!perl -l<br/>$_.=fork?$c--?&#39;)&#39;:exit:++$c&amp;&amp;&#39;(&#39;for($_)x(2*pop);$c||print<br/><br/>That&#39;s the same length as bass, but still with the same problems. A<br/>waitpid does solve the ordering problem, but the only way to stop the<br/>overall parent exiting before all the permutations have printed is to<br/>do something awful. Those solutions add lotsa characters... :(<br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2493.html Fri, 23 Nov 2007 08:17:13 +0000 Re: Just chipping in... by Daniel Tiefnig Tuomo Salo wrote:<br/>&gt; This one has no performance issues and is even a little bit shorter. <br/>&gt; Yay!<br/><br/>AND it does print lines in wrong order! :o)<br/>Doesn&#39;t it? It does for me.<br/><br/>lg,<br/>daniel<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2492.html Fri, 23 Nov 2007 07:08:54 +0000 Re: Just chipping in... by Jasper On 20/11/2007, Tuomo Salo &lt;bass@iki.fi&gt; wrote:<br/>&gt; This one has no performance issues and is even a little bit shorter. Yay!<br/>&gt;<br/>&gt; #!perl -l<br/>&gt; $r=qr/\((??{$r})*\)/;map/^$r+$/&amp;&amp;print,glob&quot;{(,)}&quot;x2x pop<br/><br/><br/>Just thought of this.<br/><br/>Probably has performance issues and is a little bit longer. Boo!<br/><br/>#!perl -l<br/>$l=2*pop;fork?$l&gt;$c++?$_.=&#39;(&#39;:exit:$c--?$_.=&#39;)&#39;:exit while$l--;print<br/><br/>Doesn&#39;t order correctly (it would if I added a wait), doesn&#39;t print<br/>right, but everyone loves potentially killing their machine with a<br/>fork. Can&#39;t get rid of the two exits, so there seems to be flab for<br/>sure<br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2491.html Fri, 23 Nov 2007 04:02:56 +0000 Re: Just chipping in... by Tuomo Salo This one has no performance issues and is even a little bit shorter. Yay!<br/><br/>#!perl -l<br/>$r=qr/\((??{$r})*\)/;map/^$r+$/&amp;&amp;print,glob&quot;{(,)}&quot;x2x pop<br/><br/> -bass<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2490.html Tue, 20 Nov 2007 13:51:08 +0000 Re: Just chipping in... by Tuomo Salo -----BEGIN PGP SIGNED MESSAGE-----<br/><br/>- From the keyboard of Tuomo Salo (2007-11-19 17:52):<br/>&gt; From the keyboard of Phil Carmody (2007-11-15 15:05):<br/>&gt;&gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; <br/>&gt; While I could not squeeze this down to a one 80 char line,<br/><br/>Scratch that!<br/><br/>Trading (any) performance and utility (whatsoever) for brevity, here&#39;s<br/>finally a one liner version:<br/><br/>#!perl -l<br/>$r=qr/4(??{$r})*2/;s/^$r*$/y*42*()**print/efor($=x=pop)/2..$=<br/><br/>Not only accomplishing the given task, this little script will also use<br/>up all your CPU and more! Use argument 4 for extra sluggishness!<br/><br/>Argument &gt;= 4 will even overflow the counter variable to protect your<br/>precious processor cycles!<br/><br/> -bass<br/>-----BEGIN PGP SIGNATURE-----<br/>Version: GnuPG v1.2.1 (GNU/Linux)<br/>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org<br/><br/>iQB1AwUBR0MRZ/bPZUB64qcJAQH6oAL/dTSy5U6q0+XCdRizhPC9QV381Lpwja+X<br/>0fZn3IUP9q7ez85RF0j4CP4DSUVbZGNVGnqqNICbNQZo+I2IswG1ZULLtHqiRMkm<br/>E5Mq4U7wULsYqVcUPmGvsnz+B8AWA6OG<br/>=lT/i<br/>-----END PGP SIGNATURE-----<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2489.html Tue, 20 Nov 2007 09:04:53 +0000 Re: Just chipping in... by Juho Snellman Tuomo Salo &lt;tuomo.salo@plenware.fi&gt; writes:<br/><br/>&gt; From the keyboard of Phil Carmody (2007-11-15 15:05):<br/>&gt; &gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; <br/>&gt; While I could not squeeze this down to a one 80 char line, there is only<br/>&gt; one line that does not begin with a # :-)<br/>&gt; <br/>&gt; #!perl -l<br/>&gt; $\=~s#(.*)\n#&quot;$1(\n&quot;x($1=~y/(//&lt;$a).&quot;$1)\n&quot;x($1=~y/)//*2&lt;$_-1)<br/>&gt; #gefor 1..2*($a=pop);print<br/><br/>The following is technically speaking not a one-liner, but is 80 characters<br/>total split to multiple lines:<br/><br/>#!perl<br/>$_||=11x<br/>pop;/1(1*)<br/>?(1?)/?map$_&amp;&amp;do$0,$1!=$&#39;&amp;&amp;&quot;$`($1<br/>1$2$&#39;&quot;,&quot;$`)$1<br/>$&#39;&quot;x$2:print<br/><br/>-- <br/>Juho Snellman<br/><br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2488.html Tue, 20 Nov 2007 01:21:09 +0000 Re: Just chipping in... by Phil Carmody --- Tuomo Salo &lt;tuomo.salo@plenware.fi&gt; wrote:<br/>&gt; -----BEGIN PGP SIGNED MESSAGE-----<br/>&gt; - From the keyboard of Phil Carmody (2007-11-15 15:05):<br/>&gt; &gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; <br/>&gt; While I could not squeeze this down to a one 80 char line, there is only<br/>&gt; one line that does not begin with a # :-)<br/>&gt; <br/>&gt; #!perl -l<br/>&gt; $\=~s#(.*)\n#&quot;$1(\n&quot;x($1=~y/(//&lt;$a).&quot;$1)\n&quot;x($1=~y/)//*2&lt;$_-1)#gefor<br/>1..2*($a=pop);print<br/>&gt; <br/>&gt; I tried to do the generation by hand, implemented that method as a<br/>&gt; regex, and polished (or should I say disfigured) the result with a<br/>&gt; couple of standard golfing tricks. Notice the lack of escaped parens,<br/>&gt; btw :-)<br/>&gt; <br/>&gt; There are probably a couple of mrmagoos there, at least you could lose<br/>&gt; a couple of chars (along with any perceived one-linerness) by replacing<br/>&gt; the &quot;\n&quot;:s with literal newlines.<br/><br/>Masterful! Hyv&auml; Tuomo! I can only begin to work out how it works!<br/><br/>Phil<br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> ____________________________________________________________________________________<br/>Never miss a thing. Make Yahoo your home page. <br/>http://www.yahoo.com/r/hs<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2487.html Mon, 19 Nov 2007 18:45:00 +0000 Re: Just chipping in... by Tuomo Salo -----BEGIN PGP SIGNED MESSAGE-----<br/><br/>- From the keyboard of Phil Carmody (2007-11-15 15:05):<br/>&gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/><br/>While I could not squeeze this down to a one 80 char line, there is only<br/>one line that does not begin with a # :-)<br/><br/>#!perl -l<br/>$\=~s#(.*)\n#&quot;$1(\n&quot;x($1=~y/(//&lt;$a).&quot;$1)\n&quot;x($1=~y/)//*2&lt;$_-1)<br/>#gefor 1..2*($a=pop);print<br/><br/><br/>I tried to do the generation by hand, implemented that method as a<br/>regex, and polished (or should I say disfigured) the result with a<br/>couple of standard golfing tricks. Notice the lack of escaped parens,<br/>btw :-)<br/><br/>There are probably a couple of mrmagoos there, at least you could lose<br/>a couple of chars (along with any perceived one-linerness) by replacing<br/>the &quot;\n&quot;:s with literal newlines.<br/><br/>Cheers,<br/><br/> -bass<br/><br/>-----BEGIN PGP SIGNATURE-----<br/>Version: GnuPG v1.2.1 (GNU/Linux)<br/>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org<br/><br/>iQB1AwUBR0GxVPbPZUB64qcJAQFFFAL/ejNBEfzY9+PwNSS+EtakB+UC7RpfzBu5<br/>FmVwYQ8JXoEiCPjuSfqEA+D6I5qhioNhQsuMOoG3YEbaWbhjRuEpTcNmdIhbDBi1<br/>g8sRXE1rOlCO+wgR4ZVUjXoROrhj4AoN<br/>=4jPH<br/>-----END PGP SIGNATURE-----<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2486.html Mon, 19 Nov 2007 10:40:40 +0000 Re: Just chipping in... by Jasper I give up! I should learn to check before posting... This doesn&#39;t work<br/>either. It looks like it does without counting the results, though :S<br/><br/>On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt; On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt;<br/>&gt; &gt;<br/>&gt; &gt; \$h{$_=&#39;()&#39;x$ARGV[0]};<br/>&gt; &gt; \$h{$_,reverse}while s/\)(.*?)\(/$1()/;<br/>&gt; &gt; print for sort keys %h;<br/>&gt;<br/>&gt; Phil points out that reverse isn&#39;t actually a mirror (and scalar<br/>&gt; reverse makes this horribly incorrect), so it turns out I have to do<br/>&gt; this in two passes.<br/>&gt;<br/>&gt; \$h{$_=&#39;()&#39;x $ARGV[0]};<br/>&gt; \$h{$_}while s/\)(.*?)\(/$1()/;<br/>&gt; $_=&#39;()&#39;x pop;<br/>&gt; \$h{$_}while s/(.*)\)(.*?)\(/$1()$2/;<br/>&gt; print for sort keys %h;<br/>&gt;<br/>&gt; Hopefully someone can fix that :D<br/>&gt;<br/>&gt; --<br/>&gt; Jasper<br/>&gt;<br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2485.html Thu, 15 Nov 2007 08:47:20 +0000 Re: Just chipping in... by Jasper On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/><br/>&gt;<br/>&gt; \$h{$_=&#39;()&#39;x$ARGV[0]};<br/>&gt; \$h{$_,reverse}while s/\)(.*?)\(/$1()/;<br/>&gt; print for sort keys %h;<br/><br/>Phil points out that reverse isn&#39;t actually a mirror (and scalar<br/>reverse makes this horribly incorrect), so it turns out I have to do<br/>this in two passes.<br/><br/>\$h{$_=&#39;()&#39;x $ARGV[0]};<br/>\$h{$_}while s/\)(.*?)\(/$1()/;<br/>$_=&#39;()&#39;x pop;<br/>\$h{$_}while s/(.*)\)(.*?)\(/$1()$2/;<br/>print for sort keys %h;<br/><br/>Hopefully someone can fix that :D<br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2484.html Thu, 15 Nov 2007 08:45:49 +0000 Re: Just chipping in... by Jasvir Nagra To golf it a little to make it into an actual one-liner (even if a<br/>rather long one!)<br/><br/>#!/usr/bin/perl -l<br/>$n=pop;$&quot;=$/;print&quot;@{[w($n)]}&quot;;sub<br/>w{my($n)=pop;!$n?@_=&quot;&quot;:$n==1?@_=&quot;()&quot;:a;if($n&gt;1){for$k(0..--$n){for$p(w($k)){push@_,&quot;($p)$_&quot;for<br/>w($n-$k)}}}@_}<br/><br/>-- jas<br/><br/>On Nov 15, 2007 2:05 PM, Phil Carmody &lt;thefatphil@yahoo.co.uk&gt; wrote:<br/>&gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; I even think a DP non-recursive approach should be quite quick.<br/>&gt; Keeping the output in the logical order might cost a few strokes.<br/>&gt;<br/>&gt;<br/>&gt; #!/usr/bin/perl<br/>&gt;<br/>&gt; $count = $ARGV[0];<br/>&gt;<br/>&gt; print join &quot;\n&quot;, pren($count), &quot;&quot;;<br/>&gt;<br/>&gt; sub pren<br/>&gt; {<br/>&gt; my @list = ();<br/>&gt;<br/>&gt; (my $n) = @_;<br/>&gt; if ($n == 0) {push(@list, &quot;&quot;)}<br/>&gt; elsif($n == 1) {push(@list, &quot;()&quot;)}<br/>&gt; elsif($n &gt; 1)<br/>&gt; {<br/>&gt; foreach $k (0 .. $n-1)<br/>&gt; {<br/>&gt; foreach $p1 (pren($k))<br/>&gt; {<br/>&gt; foreach $p2 (pren($n - 1 - $k))<br/>&gt; {<br/>&gt; push @list, sprintf &quot;(%s)%s&quot;, $p1, $p2;<br/>&gt; }<br/>&gt; }<br/>&gt; }<br/>&gt; }<br/>&gt; return @list;<br/>&gt; }<br/>&gt; ________________________<br/>&gt;<br/>&gt;<br/>&gt; $ ./parens.pl 5 | cat -n<br/>&gt; 1 ()()()()()<br/>&gt; 2 ()()()(())<br/>&gt; 3 ()()(())()<br/>&gt; 4 ()()(()())<br/>&gt; 5 ()()((()))<br/>&gt; 6 ()(())()()<br/>&gt; 7 ()(())(())<br/>&gt; 8 ()(()())()<br/>&gt; 9 ()((()))()<br/>&gt; 10 ()(()()())<br/>&gt; 11 ()(()(()))<br/>&gt; 12 ()((())())<br/>&gt; 13 ()((()()))<br/>&gt; 14 ()(((())))<br/>&gt; 15 (())()()()<br/>&gt; 16 (())()(())<br/>&gt; 17 (())(())()<br/>&gt; 18 (())(()())<br/>&gt; 19 (())((()))<br/>&gt; 20 (()())()()<br/>&gt; 21 (()())(())<br/>&gt; 22 ((()))()()<br/>&gt; 23 ((()))(())<br/>&gt; 24 (()()())()<br/>&gt; 25 (()(()))()<br/>&gt; 26 ((())())()<br/>&gt; 27 ((()()))()<br/>&gt; 28 (((())))()<br/>&gt; 29 (()()()())<br/>&gt; 30 (()()(()))<br/>&gt; 31 (()(())())<br/>&gt; 32 (()(()()))<br/>&gt; 33 (()((())))<br/>&gt; 34 ((())()())<br/>&gt; 35 ((())(()))<br/>&gt; 36 ((()())())<br/>&gt; 37 (((()))())<br/>&gt; 38 ((()()()))<br/>&gt; 39 ((()(())))<br/>&gt; 40 (((())()))<br/>&gt; 41 (((()())))<br/>&gt; 42 ((((()))))<br/>&gt;<br/>&gt;<br/>&gt; () ASCII ribbon campaign () Hopeless ribbon campaign<br/>&gt; /\ against HTML mail /\ against gratuitous bloodshed<br/>&gt;<br/>&gt; [stolen with permission from Daniel B. Cristofani]<br/>&gt;<br/>&gt;<br/>&gt; ____________________________________________________________________________________<br/>&gt; Never miss a thing. Make Yahoo your home page.<br/>&gt; http://www.yahoo.com/r/hs<br/>&gt;<br/><br/><br/><br/>-- <br/>Jasvir Nagra<br/>http://www.cs.auckland.ac.nz/~jas<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2483.html Thu, 15 Nov 2007 08:01:43 +0000 Re: Just chipping in... by Jasper On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt; On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt; &gt; On 15/11/2007, Phil Carmody &lt;thefatphil@yahoo.co.uk&gt; wrote:<br/>&gt; &gt; &gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; &gt; &gt; I even think a DP non-recursive approach should be quite quick.<br/>&gt; &gt; &gt; Keeping the output in the logical order might cost a few strokes.<br/>&gt; &gt;<br/>&gt;<br/>&gt; and (mostly) with a regex :):wq<br/>&gt;<br/>&gt; \$h{$_=&#39;()&#39;x$ARGV[0]};<br/>&gt; while(/\)\(/){<br/>&gt; s/\)(.*?)\(/$1()/;<br/>&gt; \$h{$_,reverse};<br/>&gt; }<br/>&gt; print for sort keys %h;<br/><br/>Should read:<br/><br/>\$h{$_=&#39;()&#39;x$ARGV[0]};<br/>\$h{$_,reverse}while s/\)(.*?)\(/$1()/;<br/>print for sort keys %h;<br/><br/>of course!<br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2482.html Thu, 15 Nov 2007 07:09:57 +0000 Re: Just chipping in... by Jasper On 15/11/2007, Jasper &lt;jaspermccrea@gmail.com&gt; wrote:<br/>&gt; On 15/11/2007, Phil Carmody &lt;thefatphil@yahoo.co.uk&gt; wrote:<br/>&gt; &gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; &gt; I even think a DP non-recursive approach should be quite quick.<br/>&gt; &gt; Keeping the output in the logical order might cost a few strokes.<br/>&gt;<br/><br/>and (mostly) with a regex :):wq<br/><br/>\$h{$_=&#39;()&#39;x$ARGV[0]};<br/>while(/\)\(/){<br/> s/\)(.*?)\(/$1()/;<br/> \$h{$_,reverse};<br/>}<br/>print for sort keys %h;<br/><br/><br/><br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2481.html Thu, 15 Nov 2007 07:05:51 +0000 Re: Just chipping in... by Jasper On 15/11/2007, Phil Carmody &lt;thefatphil@yahoo.co.uk&gt; wrote:<br/>&gt; I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>&gt; I even think a DP non-recursive approach should be quite quick.<br/>&gt; Keeping the output in the logical order might cost a few strokes.<br/><br/><br/>First pass:<br/><br/>sub f {<br/> my($i,$c,@p)=@_;<br/> $i?<br/> map{f($i-1,$c+/\(/-/\)/,@p,$_)}!$c?&#39;(&#39;:$c-$i?qw{) (}:&#39;)&#39;:<br/> print join&#39;&#39;,@p<br/>}<br/>f($ARGV[0]*2);<br/><br/>I suppose that will give an undef for 0...<br/><br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2480.html Thu, 15 Nov 2007 06:50:32 +0000 Just chipping in... by Phil Carmody I saw this on sci.math, and thought &quot;one liner&quot; ;-)<br/>I even think a DP non-recursive approach should be quite quick.<br/>Keeping the output in the logical order might cost a few strokes.<br/><br/><br/>#!/usr/bin/perl<br/><br/>$count = $ARGV[0];<br/><br/>print join &quot;\n&quot;, pren($count), &quot;&quot;;<br/><br/>sub pren<br/>{<br/> my @list = ();<br/><br/> (my $n) = @_;<br/> if ($n == 0) {push(@list, &quot;&quot;)}<br/> elsif($n == 1) {push(@list, &quot;()&quot;)}<br/> elsif($n &gt; 1)<br/> {<br/> foreach $k (0 .. $n-1)<br/> {<br/> foreach $p1 (pren($k))<br/> {<br/> foreach $p2 (pren($n - 1 - $k))<br/> {<br/> push @list, sprintf &quot;(%s)%s&quot;, $p1, $p2;<br/> }<br/> }<br/> }<br/> }<br/> return @list;<br/>}<br/>________________________<br/><br/><br/>$ ./parens.pl 5 | cat -n<br/> 1 ()()()()()<br/> 2 ()()()(())<br/> 3 ()()(())()<br/> 4 ()()(()())<br/> 5 ()()((()))<br/> 6 ()(())()()<br/> 7 ()(())(())<br/> 8 ()(()())()<br/> 9 ()((()))()<br/> 10 ()(()()())<br/> 11 ()(()(()))<br/> 12 ()((())())<br/> 13 ()((()()))<br/> 14 ()(((())))<br/> 15 (())()()()<br/> 16 (())()(())<br/> 17 (())(())()<br/> 18 (())(()())<br/> 19 (())((()))<br/> 20 (()())()()<br/> 21 (()())(())<br/> 22 ((()))()()<br/> 23 ((()))(())<br/> 24 (()()())()<br/> 25 (()(()))()<br/> 26 ((())())()<br/> 27 ((()()))()<br/> 28 (((())))()<br/> 29 (()()()())<br/> 30 (()()(()))<br/> 31 (()(())())<br/> 32 (()(()()))<br/> 33 (()((())))<br/> 34 ((())()())<br/> 35 ((())(()))<br/> 36 ((()())())<br/> 37 (((()))())<br/> 38 ((()()()))<br/> 39 ((()(())))<br/> 40 (((())()))<br/> 41 (((()())))<br/> 42 ((((()))))<br/><br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> ____________________________________________________________________________________<br/>Never miss a thing. Make Yahoo your home page. <br/>http://www.yahoo.com/r/hs<br/> http://www.nntp.perl.org/group/perl.golf/2007/11/msg2479.html Thu, 15 Nov 2007 05:06:04 +0000 (polish) golfs archive by Jasper Hey,<br/><br/>I&#39;m looking for a list of the polish golfs, with rules and test<br/>programs, but kernelpanic.pl, where I expected to find them, seems<br/>reluctant to give them up.<br/><br/>I&#39;m just organizizing a little intra-company golf for fun, is all, but<br/>I don&#39;t want the overhead of creating a whole compo..<br/><br/>Anyone keep any of this around? Anyone know specifically of a good one<br/>that was fun?<br/><br/>I suppose I could grab one of Terje&#39;s golfs that I didn&#39;t do instead...<br/><br/>Thanks<br/>-- <br/>Jasper<br/> http://www.nntp.perl.org/group/perl.golf/2007/07/msg2478.html Tue, 17 Jul 2007 06:14:15 +0000 Re: regexp quickie by Phil Carmody --- Shlomi Fish &lt;shlomif@iglu.org.il&gt; wrote:<br/>&gt; On Thursday 28 June 2007, Phil Carmody wrote:<br/>&gt; &gt; You guys amaze me! (And gals, too, in case Abigail reads this list. <br/>&gt; <br/>&gt; Sorry to disappoint you but Abigail is a guy (at least in the context of <br/>&gt; Perl):<br/>...<br/>&gt; http://www.flickr.com/photos/cogurov/42641335/in/photostream/<br/><br/>Oh, that&#39;s going to get confusing... I&#39;ll have no idea what personal pronoun to<br/>use when referring to h&auml;n in the future on littlegolem, usenet, and here. <br/>Cop-out#1 - use of Finnish (genderless) pronouns.<br/><br/>Phil<br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> <br/>____________________________________________________________________________________<br/>Don&#39;t pick lemons.<br/>See all the new 2007 cars at Yahoo! Autos.<br/>http://autos.yahoo.com/new_cars.html <br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2477.html Thu, 28 Jun 2007 03:53:04 +0000 Re: regexp quickie by Shlomi Fish On Thursday 28 June 2007, Phil Carmody wrote:<br/>&gt; --- Roy.Johnson@shell.com wrote:<br/>&gt; &gt; Mine (borrowing RJK&#39;s testing code): $1 will be the last letter<br/>&gt; &gt; (non-underscore) before or at the target location; $2 will be the first<br/>&gt; &gt; letter at or after the target location, or the last letter if no such<br/>&gt; &gt; letter exists.<br/>&gt; &gt;<br/>&gt; &gt; for (qw/ A_Z_K_ A_____ _____K /) {<br/>&gt; &gt; print &quot;$_\n&quot;;<br/>&gt; &gt; for my $n (1 .. 6) {<br/>&gt; &gt; my $r = $n - 1;<br/>&gt; &gt; print &quot;$n: &quot;;<br/>&gt; &gt; print /^(?=.{0,$r}([^_]))?.{0,$r}.*?([^_])/<br/>&gt; &gt; ? &quot;[$1] ($2)&quot; : &quot;no match&quot;;<br/>&gt; &gt; print &quot;\n&quot;;<br/>&gt; &gt; }<br/>&gt; &gt; }<br/>&gt;<br/>&gt; You guys amaze me! (And gals, too, in case Abigail reads this list. In<br/>&gt; which case she might reduce that it is for RoRoRo&#39;s EinStein bot!)<br/>&gt;<br/><br/>Sorry to disappoint you but Abigail is a guy (at least in the context of <br/>Perl):<br/><br/>{{{{{{{{{<br/>Sep 18 22:11:57 &lt;rindolf&gt; fxn: Abigail is a guy, right?<br/>Sep 18 22:12:23 &lt;Yaakov&gt; Abigail is a very Dutch, very male person.<br/>Sep 18 22:12:35 &lt;fxn&gt; rindolf: yes<br/>Sep 18 22:13:49 &lt;rindolf&gt; fxn: is Abigail his psedonym?<br/>Sep 18 22:14:25 &lt;fxn&gt; rindolf: I don&#39;t know, his name in the conference was <br/>Abigail<br/>Sep 18 22:14:51 &lt;fxn&gt; rindolf: that&#39;s a picture by cog: <br/>http://www.flickr.com/photos/cogurov/42641335/in/photostream/<br/>Sep 18 22:14:52 &lt;shorten&gt; fxn&#39;s url is at http://xrl.us/hnmc<br/>}}}}}}}}}<br/><br/>It is indeed a feminine name, though, at least in its Hebrew origin:<br/><br/>http://en.wikipedia.org/wiki/Abigail<br/><br/>Regards,<br/><br/> Shlomi Fish<br/><br/>&gt; Phil<br/>&gt;<br/>&gt; () ASCII ribbon campaign () Hopeless ribbon campaign<br/>&gt; /\ against HTML mail /\ against gratuitous bloodshed<br/>&gt;<br/>&gt; [stolen with permission from Daniel B. Cristofani]<br/>&gt;<br/>&gt;<br/>&gt;<br/>&gt; ___________________________________________________________________________<br/>&gt;_________ Building a website is a piece of cake. Yahoo! Small Business gives<br/>&gt; you all the tools to get online. http://smallbusiness.yahoo.com/webhosting<br/><br/><br/><br/>-- <br/><br/>---------------------------------------------------------------------<br/>Shlomi Fish shlomif@iglu.org.il<br/>Homepage: http://www.shlomifish.org/<br/><br/>If it&#39;s not in my E-mail it doesn&#39;t happen. And if my E-mail is saying<br/>one thing, and everything else says something else - E-mail will conquer.<br/> -- An Israeli Linuxer<br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2476.html Thu, 28 Jun 2007 02:30:12 +0000 RE: regexp quickie by Phil Carmody --- Roy.Johnson@shell.com wrote:<br/>&gt; Mine (borrowing RJK&#39;s testing code): $1 will be the last letter<br/>&gt; (non-underscore) before or at the target location; $2 will be the first<br/>&gt; letter at or after the target location, or the last letter if no such letter<br/>&gt; exists.<br/>&gt; <br/>&gt; for (qw/ A_Z_K_ A_____ _____K /) {<br/>&gt; print &quot;$_\n&quot;;<br/>&gt; for my $n (1 .. 6) {<br/>&gt; my $r = $n - 1;<br/>&gt; print &quot;$n: &quot;;<br/>&gt; print /^(?=.{0,$r}([^_]))?.{0,$r}.*?([^_])/<br/>&gt; ? &quot;[$1] ($2)&quot; : &quot;no match&quot;;<br/>&gt; print &quot;\n&quot;;<br/>&gt; }<br/>&gt; }<br/><br/>You guys amaze me! (And gals, too, in case Abigail reads this list. In which<br/>case she might reduce that it is for RoRoRo&#39;s EinStein bot!)<br/><br/>Phil<br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> <br/>____________________________________________________________________________________<br/>Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.<br/>http://smallbusiness.yahoo.com/webhosting <br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2475.html Wed, 27 Jun 2007 15:18:25 +0000 RE: regexp quickie by Roy.Johnson &gt; If you want $2 to only ever be the first letter at or after the target<br/>&gt; location, you can just tweak the second half of the regex:<br/>&gt; <br/>&gt; /^(?=.{0,$r}([^_]))?(?:.{$r}.*?([^_]))?/<br/><br/>Save a stroke:<br/> /^(?=.{0,$r}([^_]))?(?:.{$r,}?([^_]))?/<br/><br/>Roy<br/><br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2474.html Wed, 27 Jun 2007 12:49:55 +0000 Re: regexp quickie by Ronald J Kimball On Wed, Jun 27, 2007 at 02:26:35PM -0500, Roy.Johnson@shell.com wrote:<br/>&gt; Mine (borrowing RJK&#39;s testing code): $1 will be the last letter<br/>&gt; (non-underscore) before or at the target location; $2 will be the first<br/>&gt; letter at or after the target location, or the last letter if no such<br/>&gt; letter exists.<br/>&gt; <br/>&gt; for (qw/ A_Z_K_ A_____ _____K /) {<br/>&gt; print &quot;$_\n&quot;;<br/>&gt; for my $n (1 .. 6) {<br/>&gt; my $r = $n - 1;<br/>&gt; print &quot;$n: &quot;;<br/>&gt; print /^(?=.{0,$r}([^_]))?.{0,$r}.*?([^_])/<br/>&gt; ? &quot;[$1] ($2)&quot; : &quot;no match&quot;;<br/>&gt; print &quot;\n&quot;;<br/>&gt; }<br/>&gt; }<br/><br/>I wish I&#39;d thought of doing it that way!<br/><br/>If you want $2 to only ever be the first letter at or after the target<br/>location, you can just tweak the second half of the regex:<br/><br/>/^(?=.{0,$r}([^_]))?(?:.{$r}.*?([^_]))?/<br/><br/>Ronald<br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2473.html Wed, 27 Jun 2007 12:38:34 +0000 RE: regexp quickie by Roy.Johnson Mine (borrowing RJK&#39;s testing code): $1 will be the last letter (non-underscore) before or at the target location; $2 will be the first letter at or after the target location, or the last letter if no such letter exists.<br/><br/>for (qw/ A_Z_K_ A_____ _____K /) {<br/> print &quot;$_\n&quot;;<br/> for my $n (1 .. 6) {<br/> my $r = $n - 1;<br/> print &quot;$n: &quot;;<br/> print /^(?=.{0,$r}([^_]))?.{0,$r}.*?([^_])/<br/> ? &quot;[$1] ($2)&quot; : &quot;no match&quot;;<br/> print &quot;\n&quot;;<br/> }<br/>}<br/><br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2472.html Wed, 27 Jun 2007 12:26:49 +0000 Re: regexp quickie by Phil Carmody --- Ronald J Kimball &lt;rjk-perl-golf@tamias.net&gt; wrote:<br/>&gt; On Wed, Jun 27, 2007 at 05:45:54AM -0700, Phil Carmody wrote:<br/>&gt; &gt; Say I had a string satisfying /^[A-Z_]{6}$/, but not equal to &#39;______&#39;<br/>&gt; &gt; and I wish to extract from that the 1 or 2 letters which are closest to<br/>&gt; &gt; the n-th character in the string. Is there a simple regexp to perform<br/>&gt; &gt; that task?<br/>&gt; <br/>&gt; Well, I wouldn&#39;t exactly call this regex simple... But I have come up with<br/>&gt; one that does it:<br/>... <br/>&gt; /^(?(?=.{0,$r}[A-Z]).{0,$r}|.*)([A-Z])(?(?&lt;!^..{$r}).*?([A-Z]|$))/<br/><br/>&gt; /^.{$r}([A-Z])/ || /^.{0,$r}([A-Z]).*?([A-Z]|$)/ || /^.*([A-Z])/<br/> <br/>&gt; /^.{$r}([A-Z])|^.{0,$r}([A-Z]).*?([A-Z]|$)|^.*([A-Z])/<br/><br/>Woh! I&#39;m glad that&#39;s complicated, as I don&#39;t feel so bad just doing it the<br/>naive way. (I chose the loop, rather than the joining of the result from two<br/>substrs, one using a /^ match and the other using a $/.)<br/><br/>I have another idea how to solve the problem of isolating the (1 or) 2 closest<br/>real letters:<br/><br/>In the A_Z_K_ case, for n=2 (r=1), an equally useful output could be<br/> A_Z___<br/>That is, to replace anything beyond the first letter at or after char r with<br/>the underscore. Two passes would be necessary, one to strip that which is<br/>before, one to strip that which is after.<br/><br/>Of course, I can probably simplify things by handling the cases of when there<br/>is and is not a letter at the point of interest separately. If there is a<br/>letter there, the answer is already found.<br/><br/>It&#39;s not a big deal, I was just noodling...<br/><br/>Thanks for the rather heroic regexps though!<br/>Phil<br/><br/><br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> <br/>____________________________________________________________________________________<br/>Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.<br/>http://answers.yahoo.com/dir/?link=list&amp;sid=396545469<br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2471.html Wed, 27 Jun 2007 09:54:03 +0000 Re: regexp quickie by Ronald J Kimball On Wed, Jun 27, 2007 at 05:45:54AM -0700, Phil Carmody wrote:<br/>&gt; Say I had a string satisfying /^[A-Z_]{6}$/, but not equal to &#39;______&#39;<br/>&gt; and I wish to extract from that the 1 or 2 letters which are closest to<br/>&gt; the n-th character in the string. Is there a simple regexp to perform<br/>&gt; that task?<br/>&gt; <br/>&gt; e.g.<br/>&gt; if the string=A_Z_K_ then:<br/>&gt; if n=1, then I want &#39;A&#39; (or &#39;AA&#39;, not fussed)<br/>&gt; if n=2, then I want &#39;AZ&#39;<br/>&gt; if n=3, then I want &#39;Z&#39; (or &#39;ZZ&#39;, not fussed)<br/>&gt; if n=4, then I want &#39;ZK&#39;<br/>&gt; if n=5 or 6, then I want &#39;K&#39; (or &#39;KK&#39;, not fussed)<br/>&gt; <br/>&gt; I can see how to do it with the concatenation of two matches from two<br/>&gt; substrs, but that&#39;s barely simpler than a naive loop over each character<br/>&gt; forwards and backwards.<br/><br/>Well, I wouldn&#39;t exactly call this regex simple... But I have come up with<br/>one that does it:<br/><br/>for (qw/ A_Z_K_ A_____ _____K /) {<br/> print &quot;$_\n&quot;;<br/> for my $n (1 .. 6) {<br/> my $r = $n - 1;<br/> print &quot;$n: &quot;;<br/> /^(?(?=.{0,$r}[A-Z]).{0,$r}|.*)([A-Z])(?(?&lt;!^..{$r}).*?([A-Z]|$))/<br/> &amp;&amp; print &quot;$1 $2&quot;;<br/> print &quot;\n&quot;;<br/> }<br/>}<br/><br/>This has the advantage of always putting the matched characters in $1 and<br/>$2. (Note that $1 is always set; if there is no letter at or before the<br/>position, $1 will contain the first letter after the position and $2 will<br/>be empty.)<br/><br/><br/>Here are two other approaches:<br/><br/>/^.{$r}([A-Z])/ || /^.{0,$r}([A-Z]).*?([A-Z]|$)/ || /^.*([A-Z])/<br/> &amp;&amp; print &quot;$1 $2&quot;;<br/>is simpler, but uses three separate regular expressions.<br/><br/>/^.{$r}([A-Z])|^.{0,$r}([A-Z]).*?([A-Z]|$)|^.*([A-Z])/<br/> &amp;&amp; print $1 || $4 || &quot;$2 $3&quot;;<br/>uses a single regular expression, but the results will be in $1, or in $2<br/>and $3, or in $4. (And if digits were allowed the print logic would need<br/>to be modified.)<br/><br/><br/>Ronald<br/><br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2470.html Wed, 27 Jun 2007 08:01:48 +0000 regexp quickie by Phil Carmody Say I had a string satisfying /^[A-Z_]{6}$/, but not equal to &#39;______&#39; and I<br/>wish to extract from that the 1 or 2 letters which are closest to the n-th<br/>character in the string. Is there a simple regexp to perform that task?<br/><br/>e.g.<br/>if the string=A_Z_K_ then:<br/>if n=1, then I want &#39;A&#39; (or &#39;AA&#39;, not fussed)<br/>if n=2, then I want &#39;AZ&#39;<br/>if n=3, then I want &#39;Z&#39; (or &#39;ZZ&#39;, not fussed)<br/>if n=4, then I want &#39;ZK&#39;<br/>if n=5 or 6, then I want &#39;K&#39; (or &#39;KK&#39;, not fussed)<br/><br/>I can see how to do it with the concatenation of two matches from two substrs,<br/>but that&#39;s barely simpler than a naive loop over each character forwards and<br/>backwards.<br/><br/>Phil<br/><br/>() ASCII ribbon campaign () Hopeless ribbon campaign<br/>/\ against HTML mail /\ against gratuitous bloodshed<br/><br/>[stolen with permission from Daniel B. Cristofani]<br/><br/><br/> <br/>____________________________________________________________________________________<br/>Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.<br/>http://sims.yahoo.com/ <br/> http://www.nntp.perl.org/group/perl.golf/2007/06/msg2469.html Wed, 27 Jun 2007 05:46:06 +0000 Re: New Golf by Yanick Champoux On Sunday 11 February 2007 14:17, Andrew Savige wrote:<br/>&gt; `/anick wrote:<br/>&gt; &gt; Ooooh... A Roman-to-decimal rehash of the Fonality tournament.<br/>&gt; &gt; Aah.. Emm... Do you mind if we pursue this conversation later on?<br/>&gt; &gt; I suddenly remember I have things to do...<br/>&gt;<br/>&gt; Thanks `/ for bringing that to my attention. I need another golf game<br/>&gt; like a hole in the head. ;-)<br/><br/> Ooops. Sorry, I didn&#39;t mean to tempt you back into the time-warping hell of <br/>golf addiction. <br/><br/> This being said, if you need help to wean off this addiction, I recommend <br/>joining me to my current retreat. The staff is not terribly convivial (Sister <br/>Gertrude, I am pained to say, has bedside manners as rough as her <br/>five-o&#39;clock shadow), but the accomodations are superlative (everything -- <br/>not only the couches but all furnitures and walls -- is soft, plushy and <br/>padded) and the drinks to kill for (my current favorite is the Barbituric <br/>Sunrise).<br/><br/>&gt; &gt; And if I discreetly, very discreetly scoot close to that group and perk<br/>&gt; &gt; my ear, I&#39;d probably hear them passionately bemoan how those darned<br/>&gt; &gt; foreigners are butchering that old, venerable sport that Golf is...<br/>&gt;<br/>&gt; Yep, I just stumbled on another butchering on the discussion board<br/>&gt; http://codegolf.com/boards/conversation/view/98:<br/>&gt;<br/>&gt; &quot;Milk holes in the tests as much as you want&quot;<br/>&gt;<br/>&gt; Compare that abomination to the gentlemanly conduct of the traditional<br/>&gt; game, where exploiting holes in the test program risks excommunication<br/>&gt; and where the proper response is to alert the (human) referee with a<br/>&gt; test case plugging the hole. You can&#39;t replace the traditional human<br/>&gt; golf referee with a robot.<br/><br/> I&#39;ll give you that this approach -- while being understandable considering <br/>the desire to have the competition being self-arbitrated -- lacks the panache <br/>and gentlemanish flair of our traditional Perl golfs. Nonetheless, I still <br/>maintain that they provide a good driving range where one can keep his or her <br/>swing in shape for the next big event (and sink vast amounts of time that <br/>could otherwise been used for worthy causes). <br/><br/>Joy,<br/>`/anick<br/> http://www.nntp.perl.org/group/perl.golf/2007/02/msg2468.html Tue, 13 Feb 2007 19:54:42 +0000 Re: New Golf by Andrew Savige `/anick wrote:<br/>&gt; Ooooh... A Roman-to-decimal rehash of the Fonality tournament.<br/>&gt; Aah.. Emm... Do you mind if we pursue this conversation later on?<br/>&gt; I suddenly remember I have things to do...<br/><br/>Thanks `/ for bringing that to my attention. I need another golf game<br/>like a hole in the head. ;-) As you might have guessed, I could not<br/>restrain myself from gazing at the magic of the Earthman code lamp<br/>from the opposite direction.<br/><br/>Though I really enjoyed that eye-popping experience, I&#39;m now ready for<br/>the post mortem, to enjoy all the weird and wonderful approaches of the<br/>other contestants ... except there isn&#39;t one. Oh well, I notice many<br/>others have complained about this and the site owners have promised to<br/>close challenges and publish the solutions eventually ... when no doubt<br/>we&#39;ll see a rash of Ton/Mtve &quot;deep post mortem&quot; improvements to the<br/>winning solutions. :-)<br/><br/>&gt; And if I discreetly, very discreetly scoot close to that group and perk<br/>&gt; my ear, I&#39;d probably hear them passionately bemoan how those darned<br/>&gt; foreigners are butchering that old, venerable sport that Golf is...<br/><br/>Yep, I just stumbled on another butchering on the discussion board<br/>http://codegolf.com/boards/conversation/view/98:<br/><br/> &quot;Milk holes in the tests as much as you want&quot;<br/><br/>Compare that abomination to the gentlemanly conduct of the traditional<br/>game, where exploiting holes in the test program risks excommunication<br/>and where the proper response is to alert the (human) referee with a<br/>test case plugging the hole. You can&#39;t replace the traditional human<br/>golf referee with a robot.<br/><br/>Cheers,<br/>/-\<br/><br/><br/>Send instant messages to your online friends http://au.messenger.yahoo.com <br/> http://www.nntp.perl.org/group/perl.golf/2007/02/msg2467.html Sun, 11 Feb 2007 11:17:52 +0000