By way of exercise, are there any cool tricks for getting it down below
68 chars?
for(;$i++<10;){print"\n$i little indian",$i%3?' ':'s';}print"boys";
--
Grant Robinson -- ClariNet Communications Corp, Sunnyvale, CA
Well, if you're willing to produce incorrect output, you can make
the program arbitrarily small. Grant's version does
cockroach% perl -e 'for(;$i++<10;){print"\n$i little indian",$i%3?" ":"s";}print"boys";'
1 little indian
2 little indian
3 little indians
4 little indian
5 little indian
6 little indians
7 little indian
8 little indian
9 little indians
10 little indian boyscockroach%
There's an extra leading newline, and no trailing one, plus the words
are incorrect. *pew*
Here's the shortest one I could come up with:
for(;$i++<10;){print"$i little",$i%3?"":" indians",$i<10?"\n":" indian boys\n"}
*phew*, just under 80 chars!
--
==============================================================================
Hal Pomeranz pome...@imagen.com pome...@cs.swarthmore.edu
System/Network Manager "We are islands to each other, building
QMS Imagen Division hopeful bridges on a troubled sea." --Rush
for(1..10){printf"$_ little %s\n",$_%3?$_<10?"":"indian boys":"indians"}
Getting more than a little obfuscated now...
Hate to follow up my own post, but you always think of these things
afterwards... *sigh*
for(1..10){print"$_ little",$_%3?"":" indians",$_<10?"\n":" indian boys\n"}
I should also note that this won't work before pl35 since I'm dropping
the trailing semi inside the block to save chars.
Much too much time on my hands...
>1 little indian
>2 little indian
>3 little indians
>4 little indian
>5 little indian
>6 little indians
>7 little indian
>8 little indian
>9 little indians
>10 little indian boyscockroach%
>
>There's an extra leading newline, and no trailing one, plus the words
>are incorrect. *pew*
Whoops.
I thought the problem seemed too simple to merit much attention! It did
solve the problem I though it was trying to solve (to which I plead memory
fault, the "little indians" song never was a big hit where I come from!)
>Here's the shortest one I could come up with:
>
>for(;$i++<10;){print"$i little",$i%3?"":" indians",$i<10?"\n":" indian boys\n"}
>
>*phew*, just under 80 chars!
Congrats.
reverse one of the ? tests and we chop off another one:
for(1..10){printf"$_ little %s\n",$_%3?$_>9?"indian boys":"":"indians"}
______________________________________________________________________________
o...@ccwf.cc.utexas.edu "Two roads diverged in a wood, and I -
I chose to climb the nearest tree.
And that has made all the difference."
two more:
for(1..10){printf"$_ little %s\n",$_%3?$_>9?"indian boys":"":indians}
Of course if Perl 5 has a function called indians then... :-)
Roland
--
Roland J. Schemers III | Networking Systems
Systems Programmer | 414 Sweet Hall +1 (415) 723-6740
Distributed Systems Operations | Stanford, CA 94305-3090
Stanford University | sche...@Slapshot.Stanford.EDU
--
Robert Withrow, Tel: +1 617 598 4480, Fax: +1 617 598 4430, Net: wi...@rwwa.COM
R.W. Withrow Associates, 21 Railroad Ave, Swampscott MA 01907-1821 USA
one more:
for(1..10){printf"$_ little %s\n",$_%3?/0/?"indian boys":"":indians}
-----
Paul Fernquist pf...@technix.mn.org
--
Paul Fernquist
uunet: pf...@technix.mn.org
email: ...!uunet!cs.umn.edu!kksys!edgar!technix!pfern
for(1..10){printf"$_ little%s\n",$_%3?/0/&&" indian boys":" indians"}
Of course, this may be compressible too.
- Jim
> Jin> for(1..10){printf"$_ little indian%s\n",$_%3?/0/?" boys":"":"s"}
>And this can be shortened by two more characters by using a
>short-circuit && instead of ?: for a total of 62 characters.
>for(1..10){printf"$_ little indian%s\n",$_%3?/0/&&" boys":"s"}
Both of these are wrong though I believe...
1 little indian
2 little indian
3 little indians
4 little indian
5 little indian
6 little indians
7 little indian
8 little indian
9 little indians
10 little indian boys
It should be:
1 little
2 little
3 little indians
4 little
5 little
6 little indians
7 little
8 little
9 little indians
10 little indian boys
like Paul (and other's) have coded.
--Michael
--
Michael Graff <expl...@iastate.edu> Speaking for myself, not
Project Vincent Voice: (515)294-4994 for ISU or the ISUCC
Iowa State Univ Comp Center Fax: (515)294-1717
Ames, IA 50011 -=*> PGP key on pgp-pub...@pgp.iastate.edu <*=-
Michael> In <JSC.93Ju...@monolith.mit.edu> j...@monolith.mit.edu (Jin S Choi) writes:
> Jin> for(1..10){printf"$_ little indian%s\n",$_%3?/0/?" boys":"":"s"}
>And this can be shortened by two more characters by using a
>short-circuit && instead of ?: for a total of 62 characters.
>for(1..10){printf"$_ little indian%s\n",$_%3?/0/&&" boys":"s"}
Michael> Both of these are wrong though I believe...
My goof. I realized this just after I posted it, and issued a cancel,
but it seems not to have gotten out in time. How embarassing.
--
Jin Choi
j...@athena.mit.edu
Well, I could only squeeze two more characters out of this solution, down
to 66:
for(1..10){printf"$_ little %s\n",$_%3?/0/&&"indian boys":indians}
or
for(1..10){print"$_ little ",$_%3?/0/&&"indian boys":indians,"\n"}
--silver--
sil...@metonymy.ots.utexas.edu
That's what I thought.
> So the expression ought to be:
>
> for(1..10){printf"$_ little%s\n",$_%3?/0/&&" indian boys":" indians"}
How about:
for(1..10){print"$_ little ",$_%3?/0/&&"indian boys\n":"indians\n"}
This gives a format that denotes the rhythym better, and includes a
further optimisation.
Can anybody beat 67?
--
for(1..10){print"$_ little ",$_%3?/0/&&"Perl hackers \n":"hackers\n"}
"You know this was going to be my last time, but you idiots
were working on the wrong problem. Now get back down there
and do something real."
--
Bill Eldridge bi...@cognet.ucla.edu 310-206-3960 (3987 fax)
More! Better! Faster! (80's motto) x x x x
Hot, Toxic, and Shallow! (90's motto) x xx x x
Free Rorschach Sig! (interpretation extra) x xx xx x
>this ain't the shortest but hey!
>for(1..10){s/$/ little /;/[3690]/&&s/ $/ whiteys,\n/;/0/&&s/s,/ boys. ;)/;print}
The first time I tried running this, it bombed out, but
the I changed the flags to:
#!/usr/bin/perl -pc
and it ran perfectly. Even too perfectly. Kind of eery.
Bill