Re: New golf game (for the extremely bored)
by chipmunk (Parson) on Feb 08, 2002 at 17:49 UTC
|
Two solutions of 38 characters:
# 1 2 3
#2345678901234567890123456789012345678
perl -le'print+(H,T)[rand 2]for a..gr'
perl -le'print 1<rand 2?H:T for a..gr'
| [reply] [d/l] |
|
| [reply] [d/l] |
|
Can someone explain that "a..gr" thing to me please?
I'm baffled.
--
($_='
jjjjjjuuuuuuuuusssssssssttttttttt annnnnnoootttttthhhhheeeeeerrrrrr
pppeeeerrrrrrrrrrrrllllllllllllll haaaaccccccckkkkkkkeeeeeeeerrrrrr')
=~y/[a-z]//s;print; | [reply] |
|
>Can someone explain that "a..gr" thing to me please?
Same as 1..200, really ;)
Basically you just use letters instead of numbers.
a..z yields the 26 characters of the alphabet,
a..az yields those and another 26 prefixed with a
a..bz yields those and another 26 prefixed with b
and so on. Same system, more "numbers" ...
Incidentally a..gr yields 7*26 + 18 "numbers".
update :
as crazyinsomniac pointed out, the range-operator is discussed in more detail in perlman:perlop.
| [reply] |
Re: New golf game (for the extremely bored)
by jmcnamara (Monsignor) on Feb 08, 2002 at 17:07 UTC
|
#23456789_123456789_123456789_123456789 (39)
perl -le'print+(H,T)[rand 2]for+1..200'
--
John.
| [reply] [d/l] |
Re: New golf game (for the extremely bored)
by japhy (Canon) on Feb 08, 2002 at 17:14 UTC
|
This one works, but it requires you send it 201 lines of input. perl -pe'$_=(H,T)[rand 2],201..die'
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] [d/l] |
Re: New golf game (for the extremely bored)
by broquaint (Abbot) on Feb 08, 2002 at 17:36 UTC
|
# 1 2 3 4234567
perl -le'print qw(h t)[rand>.5?0:1]for 1..200'
Mmmm, ternary conditional operatery goodness ...
Potted at 47.
broquaint | [reply] [d/l] |
Re: New golf game (for the extremely bored)
by jynx (Priest) on Feb 08, 2002 at 20:09 UTC
|
it's not a best entry, but here's another way to do it:
#23456789_123456789_123456789_123456789_123456789_
perl -e'print chr(rand>.5?84:72)for-1..198'
jynx | [reply] [d/l] |
Re: New golf game (for the extremely bored)
by Necos (Friar) on Feb 08, 2002 at 17:33 UTC
|
Using John's trick, you can do:
perl -e "print+(H,T)[rand(2)]for(1..200)"
Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com | [reply] [d/l] |
Re: New golf game (for the extremely bored)
by vek (Prior) on Feb 08, 2002 at 17:05 UTC
|
Of course you meant to write:
perl -e "for(1..200) {print ['H', 'T']->[rand(2)];}"
didn't you ;) | [reply] [d/l] |
|
Nope. Since the for() loop is only one line, it'll work without the semicolon. As a matter of fact, I could have easily have done...
perl -e "print ['H','T']->[rand(2)] for(1..200)"
Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com | [reply] [d/l] [select] |
|
Ha ha, Necos++ you're right of course, I mistyped it when I tried to run it. Coupled with the fact that I've just spent the last 3 hours debugging a co-workers program that had missing semi-colons (I've got missing semi-colons on the brain!!)
| [reply] |
Re: New golf game (for the extremely bored)
by Anonymous Monk on Feb 11, 2002 at 19:32 UTC
|
2 36 char ways, but I cheated... you get 0's and 1's instead of H's and T's
perl -e'map{printf"%.0f",rand}a..gr'
perl -e'map{printf"%d",rand 2}a..gr' | [reply] |
Re: New golf game (for the extremely bored)
by Anonymous Monk on Feb 11, 2002 at 21:27 UTC
|
Two nearly-identical (just swapped print) 36-char long ones.. 'cept these print H & T unlike the above 2
perl -e'map{print rand>.5?H:T}a..gr'
perl -e'print map{rand>.5?H:T}a..gr' | [reply] |
Re: New golf game (for the extremely bored)
by Anonymous Monk on Feb 11, 2002 at 21:31 UTC
|
Actually I was thinking that the 'x' operator would be the shortest way to do this... i was trying stuff like:
perl -e'print+(H,T)rand 2x200'
'cept the rand doesn't run every 'x', only the first time, so I either get 200 H's or 200 T's. is it possible to evaluate the rand on each concatenation? | [reply] |