Code Comments
Programming Forum and web based access to our favorite programming groups.
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 ------ uri@stemsystems.com -------- 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 --------
-
Post Follow-up to this messageUri Guttman 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 ------ uri@stemsystems.com -------- 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 ---------[/col
or]
perl -le 'print for glob"{Y,N}"x5'
--
Rick Klement
Post Follow-up to this messageOn Mon, Mar 31, 2008 at 04:34:58PM -0700, Rick Klement wrote:
>
> perl -le 'print for glob"{Y,N}"x5'
>
Of course you have to run this in a directory that doesn't contain
any file matching /^[YN]{5}$/.
--
Philippe Bruhat (BooK)
The learned man makes a mistake but once... but the truly stupid keep
practicing until they get it right.
(Moral from Groo The Wanderer #75 (Epic))
Post Follow-up to this messageOn Mon, Mar 31, 2008 at 05:50:24PM -0500, Uri Guttman wrote:
> perl -le 'print join "\n", map {tr/01/NY/; $_} map unpack( "b5", chr), 0 .. 31'[/c
olor]
Also, I'm sure, easily bested:
perl -e 'for(0..31){$_=sprintf"%05b\n",$_;y/01/YN/;print}
marginally shorter not-to-hoyle hybrid:
seq 0 31|perl -pe '$_=sprintf"%05b\n",$_;y/01/YN/'
--
zed at-sign apricot dot com [url]http://www.MemeMachineGo.com/[/ur
l]
Zed Lopez PO Box 12546 Berkeley CA 94712
Post Follow-up to this messageOn Mar 31, 2008, at 6:54 PM, Philippe Bruhat (BooK) wrote:
> On Mon, Mar 31, 2008 at 04:34:58PM -0700, Rick Klement wrote:
>
> Of course you have to run this in a directory that doesn't contain
> any file matching /^[YN]{5}$/.
Not true. The {} notation doesn't care whether files of that name
actual exist. I tested like so on Mac:
% touch YYYYY
% perl -le 'print for glob"{Y,N}"x5'
YYYYY
YYYYN
YYYNY
YYYNN
YYNYY
YYNYN
YYNNY
YYNNN
YNYYY
YNYYN
YNYNY
YNYNN
YNNYY
YNNYN
YNNNY
YNNNN
NYYYY
NYYYN
NYYNY
NYYNN
NYNYY
NYNYN
NYNNY
NYNNN
NNYYY
NNYYN
NNYNY
NNYNN
NNNYY
NNNYN
NNNNY
NNNNN
Post Follow-up to this messageOn Mon, Mar 31, 2008 at 11:37:05PM -0500, Chris Dolan wrote:
> On Mar 31, 2008, at 6:54 PM, Philippe Bruhat (BooK) wrote:
>
> Not true. The {} notation doesn't care whether files of that name
> actual exist. I tested like so on Mac:
I was pretty sure I tried the same manipulation to obtain all permutations
of some series of strings, and that it didn't work as expected when one of
the permutations actually existed as a file in the current directory.
After a quick check, you are right and I was too. :-)
What I tried was:
$ touch YYYYY
$ perl -le 'print for glob"[YN]"x5'
YYYYY
I computed my permutations with square brackets (which is one character
shorter, but more fragile).
--
Philippe Bruhat (BooK)
To flaunt your strength is to make it your weakness.
(Moral from Groo The Wanderer #25 (Epic))
Post Follow-up to this messageUri Guttman 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'[/c
olor]
perl -le'y/01/NY/&&print,for+map+unpack(b5,chr),0..31'
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Post Follow-up to this messageMagoo=21=20 -----Original Message----- From: John W. Krahn =5Bmailto:krahnj=40telus.net=5D=20 Sent: Tuesday, April 01, 2008 7:17 AM To: fwp=40perl.org Subject: Re: YN golf Uri Guttman 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. >=20 > 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. >=20 > golf away=21 >=20 > uri >=20 > perl -le 'print join =22=5Cn=22, map =7Btr/01/NY/; =24_=7D map unpack( = =22b5=22, chr), 0 .. 31' perl -le'y/01/NY/&&print,for+map+unpack(b5,chr),0..31' John --=20 Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - = - - - - - - - This message is intended only for the personal and confidential use of the = designated recipient(s) named above. If you are not the intended = recipient of this message you are hereby notified that any review, = dissemination, distribution or copying of this message is strictly = prohibited. This communication is for information purposes only and = should not be regarded as an offer to sell or as a solicitation of an = offer to buy any financial product, an official confirmation of any = transaction, or as an official statement of Lehman Brothers. Email = transmission cannot be guaranteed to be secure or error-free. Therefore, = we do not represent that this information is complete or accurate and it = should not be relied upon as such. All information is subject to change = without notice.
Post Follow-up to this messageFrom=20the keyboard of Uri Guttman [31.03.08,17:50]:
>=20
> 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.
>=20
> 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.
>=20
> golf away!
>=20
> uri
>=20
> perl -le 'print join "\n", map {tr/01/NY/; $_} map unpack( "b5", chr), 0 =
=2E. 31'
from mtve:
perl -le 'y/12/NY/-5||print for 0..2x5'
(can't do any better...)
0--gg-
--=20
_($_=3D" "x(1<<5)."?\n".q=B7/)Oo. G=B0\ /
/\_=AF/(q /
---------------------------- \__(m.=3D=3D=3D=3D=B7.(_("always off the crow=
d"))."=B7
");sub _{s./.($e=3D"'Itrs `mnsgdq Gdbj O`qkdq")=3D~y/"-y/#-z/;$e.e && print=
}
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.