Discussion:
YN golf
Uri Guttman
2008-03-31 22:50:24 UTC
Permalink
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 ------ ***@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 ---------
Rick Klement
2008-03-31 23:34:58 UTC
Permalink
Post by Uri Guttman
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'
--
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
perl -le 'print for glob"{Y,N}"x5'
--
Rick Klement
Philippe Bruhat (BooK)
2008-03-31 23:54:40 UTC
Permalink
Post by Rick Klement
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))
Chris Dolan
2008-04-01 04:37:05 UTC
Permalink
Post by Philippe Bruhat (BooK)
Post by Rick Klement
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}$/.
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
Philippe Bruhat (BooK)
2008-04-01 07:10:27 UTC
Permalink
Post by Chris Dolan
Post by Philippe Bruhat (BooK)
Post by Rick Klement
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}$/.
Not true. The {} notation doesn't care whether files of that name
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))
Josh Goldberg
2008-03-31 23:12:12 UTC
Permalink
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'
Post by Uri Guttman
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'
--
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com---------
Zed Lopez
2008-03-31 23:22:08 UTC
Permalink
Post by Uri Guttman
perl -le 'print join "\n", map {tr/01/NY/; $_} map unpack( "b5", chr), 0 .. 31'
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 http://www.MemeMachineGo.com/
Zed Lopez PO Box 12546 Berkeley CA 94712
John W. Krahn
2008-04-01 06:17:07 UTC
Permalink
Post by Uri Guttman
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'
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
Allen, Greg
2008-04-01 10:37:02 UTC
Permalink
Magoo!

-----Original Message-----
From: John W. Krahn [mailto:***@telus.net]
Sent: Tuesday, April 01, 2008 7:17 AM
To: ***@perl.org
Subject: Re: YN golf
Post by Uri Guttman
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'
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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.
shmem
2008-04-11 09:25:54 UTC
Permalink
Post by Uri Guttman
=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=
}

Loading...