Re: [spam?] YN golf

2008-03-31 Thread Josh Goldberg
Knocking a few chars off yours for perl -le 'print
join$/,map{y/01/NY/;$_}map unpack(b5,chr),0..31'

and shrunk a few more by removing the join and using sprintf:

perl -le 'print map{y/10 /YN/;$_}map{sprintf%5b$/,$_}0..31'

On Mon, Mar 31, 2008 at 3:50 PM, Uri Guttman [EMAIL PROTECTED] wrote:


 someone posted (and it wasn't homework) for an easy way to get all
 possible combos of YN (5 chars so 32 answers). he got some basic
 multiline answers but i think it makes for a great golf problem.

 here is my first pass which i am sure can be easily bested. i haven't
 even squeezed out the white spaces but it does work.

 golf away!

 uri

 perl -le 'print join \n, map {tr/01/NY/; $_} map unpack( b5, chr), 0
 .. 31'

 --
 Uri Guttman  --  [EMAIL PROTECTED]    http://www.sysarch.com--
 -  Perl Code Review , Architecture, Development, Training, Support
 --
 - Free Perl Training --- http://perlhunter.com/college.html-
 -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-



Re: Naming the @{[]} operator

2006-07-11 Thread Josh Goldberg

Let's just call it a rubber baby buggy bumper, then at least noone can say
it three times fast regardless of what goes inside.  It could be abbreviated
to R3B, as in The best way to deref that structure is to use an arr three
bee.

Taking that another step, it could be an R2D2 as well.  At least R2D2 saves
spaceships instead of just carrying produce and canned goods to the checkout
line, or hauling around a crying baby when you'd rather be at a pub.  What
did become of that robot once the rebellion was over?  Maybe R2D2 is a
shopping trolley now anyway.  He does have food service experience.

On 7/11/06, Smylers [EMAIL PROTECTED] wrote:



babycart is 3 syllables; shopping trolley is only 4 -- and again



Re: Self-recognizing programs and regular expressions

2005-03-08 Thread Josh Goldberg
How does this look?
^.[\\\[\]{}18.]{18}.$
On Mar 7, 2005, at 1:57 PM, Jasvir Nagra wrote:
The challenge then is to find a regular expression inequ or failing
that, the regular expression that accepts the smallest set of strings
including itself.  The score of an entry is the size of the set of
strings it accepts.  If two regular expressions find the same size set
of strings, the shorter regular expression wins.
I will summarise entries at
http://www.cs.auckland.ac.nz/~jas/toys/inequ.html#score
The par entry is:
Entry   Score
^.{6}$  255^6



Re: Self-recognizing programs and regular expressions

2005-03-07 Thread Josh Goldberg
but you can't replace one of the leading \'s in the regexp (at least in 
perl), so I counted 16.

On Mar 7, 2005, at 4:49 PM, Jasvir Nagra wrote:
I think its 255^2 + 8^17.  The two . account for 255^2 and there are
8^17 strings of length 17 with an 8 character alphabet.
On Mon, 2005-03-07 at 19:26 -0500, josh wrote:
sorry if some folks recieve this twice, my mail server is on the
fritz.
^.[\\[\]{}17.]{17}.$
I think, 255^2 + 8^16 possible strings?
my smtp capabilities are on the fritz, so my apologies if anyone
recieves
duplicate emails from me.

--
Jasvir Nagra
http://www.cs.auckland.ac.nz/~jas



Re: unhead

2004-09-24 Thread Josh Goldberg
Here's a little oneliner to skip the first 5 lines of the file 'foo':
perl -i5 -e '@_=STDIN;[EMAIL PROTECTED]'  foo
On Sep 24, 2004, at 7:17 AM, Jose Alves de Castro wrote:
You're probably all familiar with the commands head and tail, which
 let you extract the first or the last N lines of input or a file...
Imagine you want to print a file, but without the first N lines...
For N=1, one possibility would be:
print if $. - 1;
For any N, maybe this:
print if ($N+1)..0;
Any thoughts? Any other ideas? What would be the best way to do this?
Regards,
jac
--
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


Re: tough regex problem

2004-09-17 Thread Josh Goldberg
How about this?
return grep(/./s, $$bufref =~ m#(.*?)(?:$sep|\z)#gs) if wantarray;
Josh
On Sep 16, 2004, at 11:05 PM, Uri Guttman wrote:
in file::slurp i currently split the file into lines (or records based
on $/) using this code:
return split( m|(?=$sep)|, ${$buf_ref} ) if wantarray ;
where $sep is set from $/.
that works correctly and is fast. but it has one flaw, it can't do
paragraph mode since lookbehind can't handle variable width regexes as
\n\n+ is. so i am looking for an m// solution that properly splits a
buffer into records. it is not as easy as it seems. it has to behave
exactly like the split does. there are several corner cases such as an
empty file and a partial line ending a file. even a normal file of 
lines
is tricky as you don't want to return an bogus empty line after the 
last
real line. here are a few broken attempts to help you avoid pitfalls:

/(.*?$sep|.+)/sg# doesn't handle an empty file
/.*?(?:$sep|\z)/gs  # adds a bogus empty line at the end
i already passed this problem to a top regex person and he sent me the
second one above (obviously untested! :).
so fame, glory and an acknowledgement in the new release all go to the
valiant warrior who solves this.
let the fl^Wgames begin!
uri
--
Uri Guttman  --  [EMAIL PROTECTED]   
http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and 
Coding-
Search or Offer Perl Jobs    
http://jobs.perl.org



Re: Y2K Again ??

2004-05-14 Thread Josh Goldberg
$Yr = ($FieldA =~ /^(\d{2}).*/ and $1  20 ? 19 : 20).$1;
On May 14, 2004, at 8:25 AM, Rick Klement wrote:
Brian Morgan wrote:
Good evening everybody,
I have been working on a small database project and have come across
the
need to move some data from table A to table B, the year format in
table
A is \d{2}\D{8} and in table B \d{4}\D{8}
Since the records in table A range from 1970 - 2004.  I want to be
able
look at the date, and determine if it is a 2000 or 1900 date and make
the appropiate date change.
So here is my sollution (long):
#Pull the value out of the field
#For this example I don't care about the rest of FieldA I just want
the
1st 2 digits,
#but I need to preserve FieldA for later use in the program.
($Yr = $FieldA) =~ s/^(\d{2}).*/$1/;
if($Yr  20){
$Yr = 19$Yr;
}else{
$Yr = 20$Yr;
}
#Concat year to FieldB
I guess I am looking for a way to combine a substitution with the if
statement but haven't come up with a working solution.
Anyways, I am looking forward to see what the outcome is.
Brian
There is no need for a regex
$Yr = ($FieldA  20 ? 1900 : 2000) + $FieldA;
Or just get $FieldB directly if you don't need a separate $Yr
$FieldB = ($FieldA  21) + 19 . $FieldA;
--
Rick Klement



Re: limit the list

2002-11-20 Thread Josh Goldberg
On Wed, 20 Nov 2002 [EMAIL PROTECTED] wrote:

 join ', ', grep{ ($b.=$_) !~ /.{91}/ || ?.?  ($_ = 'etc.') } @names

 
that didn't work in my test, but it gave me an idea with map.  I know, I
used goto, but when I try to break from the BLOCK it says i'm not really
in a block inside map, even when I set it up as a block like the POD
shows.


@names = (
'foo',
'bar',
'baz',
'boo',
'zor',
);

$lim = 2;
$i=0;

map{$i++$lim?push @n,$_:$i!=$lim?{push @n,'etc.' and goto FOO}:''}@names;
FOO:
$names = join ', ',@n;
print Names: $names\n;




Re: Google

2002-10-27 Thread Josh Goldberg
that's not fun with perl...





Re: shortest test for truth false assignment

2002-05-22 Thread Josh Goldberg

how about 

do_something($a=0) if $a;


On Wed, 22 May 2002, Scott Wiersdorf wrote:

 My shortest try is this (10 characters w/o whitespace):
 
 if( $a%2 .. $a-- ) {
 do_something();
 ...
 }
 




Re: shortest test for truth false assignment

2002-05-22 Thread Josh Goldberg

If tr doesn't use patterns then please help me understand how it works 
in my test cases? 

btw a straight swap to s/// fails for true == 1 but works for true ==
'foo'.


#!/usr/bin/perl

for (1,'foo',0) {
$a = $_;
test();
test();
}
sub test {
print $a ;
if ($a=~tr/.[^0]+/0/cs) { do_something(); }
print $a\n;
}

sub do_something {
print  - ;
}

output:
1  - 0
0 0
foo  - 0
0 0

On Wed, 22 May 2002, Yanick wrote:

 On Wed, May 22, 2002 at 10:06:39PM -0400, Josh Goldberg wrote:
  I came up with another one.  This also works for values of true other
  than 1.
  
  if ($a=~tr/.[^0]+/0/c) { do_something(); }
 
   s/tr/s/, maybe ?
 
   (the transliterate operator doesn't use patterns, so
   the code above change every instances of '.' by a 0,
   of '[' by a '[' and so on and so forth...)
 
 
 Joy,
 `/anick
 
 -- 
 On the whole, human beings want to be good, 
 but not too good, and not quite all the time.
  -- George Orwell
 




Re: shortest test for truth false assignment

2002-05-22 Thread Josh Goldberg

ahhh, I get it now, thanks.

On Wed, 22 May 2002, Ronald J Kimball wrote:

 On Wed, May 22, 2002 at 09:54:52PM -0400, Yanick wrote:
  On Wed, May 22, 2002 at 10:06:39PM -0400, Josh Goldberg wrote:
   I came up with another one.  This also works for values of true other
   than 1.
   
   if ($a=~tr/.[^0]+/0/c) { do_something(); }
  
  s/tr/s/, maybe ?
  
  (the transliterate operator doesn't use patterns, so
  the code above change every instances of '.' by a 0,
  of '[' by a '[' and so on and so forth...)
 
 Actually, it translates every character that is *not* one of '.[^0]+' into '0'.
 
 /c complements the search list.
 
 When the search list is longer than the replacement list, the last
 character in the replacement class is repeated.
 
 Ronald
 
 




Re: shortest test for truth false assignment

2002-05-22 Thread Josh Goldberg

so then 

if($a=~tr/0/0/c) {do_something();}

should work for any value of true, right?

On Wed, 22 May 2002, Ronald J Kimball wrote:

 On Wed, May 22, 2002 at 09:54:52PM -0400, Yanick wrote:
  On Wed, May 22, 2002 at 10:06:39PM -0400, Josh Goldberg wrote:
   I came up with another one.  This also works for values of true other
   than 1.
   
   if ($a=~tr/.[^0]+/0/c) { do_something(); }
  
  s/tr/s/, maybe ?
  
  (the transliterate operator doesn't use patterns, so
  the code above change every instances of '.' by a 0,
  of '[' by a '[' and so on and so forth...)
 
 Actually, it translates every character that is *not* one of '.[^0]+' into '0'.
 
 /c complements the search list.
 
 When the search list is longer than the replacement list, the last
 character in the replacement class is repeated.
 
 Ronald
 
 




RE: shortest test for truth false assignment

2002-05-22 Thread Josh Goldberg


if($a){do_something($a=0)}
that's one stroke shorter

On Thu, 23 May 2002 [EMAIL PROTECTED] wrote:

 I don't believe that you'll be able to shorten:
 if($a){$a=0;do_something()}
 any further unless you're able to use the flip-flop instead of $a:
 if($|--){do_something()}
 
 All suggestions so far have been longer.




Re: isNumber( ) ??

2001-10-18 Thread Josh Goldberg

On Thu, 18 Oct 2001, Selector, Lev Y wrote:
 
 Any recommendations?
something like this perhaps?

ns21# cat t.pl 
#!/usr/bin/perl

sub isNumber {
!/\d/ ? 0 : $_ == 0 ? 1 : $_ * 1
}

for (  qw[ 0 abcdefg 1  -1.0  1.0e-10  10abc ]  ) {
  print $_ - , isNumber($_), \n;
}
ns21# perl t.pl
0 - 1
abcdefg - 0
1 - 1
-1.0 - -1
1.0e-10 - 1e-10
10abc - 10




RE: isNumber( ) ??

2001-10-18 Thread Josh Goldberg

there is the perlish behaviour done with 10abc...
if you give it 12abc34 it returns 12.  may or may not be expected
output...

but thanks!  first time
poster, long time lurker.

On Thu, 18 Oct 2001, Selector, Lev Y wrote:

 Wow!
 
 This is really elegant !!
 
 
 Warmest Regards
 
 Lev Selector
 
 
 
 
 -Original Message-
 From: Josh Goldberg [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, October 18, 2001 6:47 PM
 To: Selector, Lev Y
 Cc: '[EMAIL PROTECTED]'
 Subject: Re: isNumber( ) ?? 
 
 
 On Thu, 18 Oct 2001, Selector, Lev Y wrote:
  
  Any recommendations?
 something like this perhaps?
 
 ns21# cat t.pl 
 #!/usr/bin/perl
 
 sub isNumber {
 !/\d/ ? 0 : $_ == 0 ? 1 : $_ * 1
 }
 
 for (  qw[ 0 abcdefg 1  -1.0  1.0e-10  10abc ]  ) {
   print $_ - , isNumber($_), \n;
 }
 ns21# perl t.pl
 0 - 1
 abcdefg - 0
 1 - 1
 -1.0 - -1
 1.0e-10 - 1e-10
 10abc - 10