Re: TIMTOWTDI/golf - counting backwards
by japhy (Canon) on Jan 28, 2002 at 20:19 UTC
|
perl -le'$_=__________;_ while s/_/print length;""/e'
And even better:
perl -le'__________=~/^.+(?{print@+})^/'
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by Masem (Monsignor) on Jan 28, 2002 at 20:16 UTC
|
Probably want to get this variation out of the way... :-)
sort { $b <=> $a } ( (length '.' ) .. (length '..........') );
(Specifically the sort context)
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by gmax (Abbot) on Jan 28, 2002 at 20:20 UTC
|
# 1 2 3
#23456789012345678901234567890123456
$a=ord(L)-ord(A);print$a.$/while$a-- # wrong one
$a++for(a..j);print$a--.$/for(a..j)
update 1 sorry the first one prints from 10 to 0.
Fixed the second one.
update 2
These ones are too long, but intriguing.
perl -e '$b++;$a=hex--$b.xA;print$a--.$/for(a..j)'
perl -e '$a=++$b.$[;print$a--.$/for(a..j)'
update 3
This one seems to be short enough (30)
# 1 2 3
#23456789012345678901234567890
$a=hex(A);print$a--.$/for+a..j
$a=hex+A;print$a--.$/for+a..j # (29) with a warning
_ _ _ _
(_|| | |(_|><
_|
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by jmcnamara (Monsignor) on Jan 28, 2002 at 20:49 UTC
|
45 chars. It uses revers but not reverse.
#23456789_123456789_123456789_123456789_12345
perl -le'$=/=split//,revers;print$=--while$='
--
John.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by chipmunk (Parson) on Jan 28, 2002 at 20:48 UTC
|
35 characters for the whole command line:
perl -le'$a=ord$/;print$a--while$a'
Note: will not work on a Mac. :)
| [reply] [Watch: Dir/Any] [d/l] |
|
Note: will not work on a Mac. :)
...works fine on my Mac, chipmunk.
What's wrong with yours? :-)
[localhost:~/Music] bbking% uname -a
Darwin localhost 1.4 Darwin Kernel Version 1.4: Sun Sep 9 15:39:59 PD
+T 2001; root:xnu/xnu-201.obj~1/RELEASE_PPC Power Macintosh powerpc
[localhost:~/Music] bbking% perl -le'$a=ord$/;print$a--while$a'
10
9
8
7
6
5
4
3
2
1
| [reply] [Watch: Dir/Any] [d/l] |
Re (tilly) 1: TIMTOWTDI/golf - counting backwards
by tilly (Archbishop) on Jan 28, 2002 at 20:40 UTC
|
I am unclear. Are we talking a command line program or a function?
#23456789_123456789_123456789_12345678
perl -le'$_=@{[a..k]};print while--$_'
sub f {
#23456789_123456789_123456789_12
@_=a..j;(print@_.$/),pop while@_
}
UPDATE
jmcnamara pointed out that I was miscounting. Fixed. | [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by broquaint (Abbot) on Jan 28, 2002 at 20:23 UTC
|
sub f {
($x,$y)=@_;print$x--while$x>=$y
}
So that's a hole in 32, although it only works for numbers, so it's not a literal implementation of .. reversed.
broquaint
Update: I may have misunderstood the original question so here's my second (possibly more accurate?) shot
perl -le '$_=ord$/;print$_--while$_'
Which comes to 26, and satisfies chipmunk's need for ouput :o)
Update 2: I've just noticed my solution is exactly the same aforementioned monk, except I've used $_ instead of $a as my var name (I had hoped to exploit $_ in some way ...). Spooky. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
I tried running your solution, but it didn't produce any output...
| [reply] [Watch: Dir/Any] |
Re: TIMTOWTDI/golf - counting backwards
by jmcnamara (Monsignor) on Jan 28, 2002 at 21:59 UTC
|
33 chars. Is that the winner?:
#23456789_123456789_123456789_123
perl -le'print$=+$=-ord for+n..w'
--
John.
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by trs80 (Priest) on Jan 28, 2002 at 21:25 UTC
|
Here are my four variations:
$c=ord"\cJ";while($c){print$c--.$/};
$c=ord"\cJ";print$c--.$/for(a..j);
for($c=ord"\cJ";$c;$c--){print$c.$/};
$c=ord"\cJ";map{print$c--.$/}(a..j);
UPDATE: I had blindly followed the example and used
the \cJ when in fact it was just a \n. Also gmax pointed
out that my first example could be shorten by moving
the while statement. So here is a revised entry:
$c=ord"\n";print$c--.$/while$c;
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by Aristotle (Chancellor) on Jan 28, 2002 at 23:46 UTC
|
I started out trying to golf but ended up with what I think is a remarkable obfu instead.. :-) perl -pe'BEGIN{$i=$j=ord$/}$_=($i--||exit).chr$j' </dev/urandom
____________ Makeshifts last the longest. | [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by Juerd (Abbot) on Jan 28, 2002 at 21:48 UTC
|
Here's my first _serious_ try ;) [depends on ord($/) to be 10]
including command line:
# 1 2 3
#2345678901234567890123456789012345678
perl -le'print-!$|*$a+++ord$/for a..j'
Generic Perl (needs $/):
# 1 2 3
#234567890123456789012345678901
print-!$|*$a+++ord$/,$/for a..j
So far, I beat japhy by 2 :)
Superior to me is chipmunk, who didn't only spot my mistake in the root of this thread, but also has a version that's 3 characters shorter than mine.
2;0 juerd@ouranos:~$ perl -e'undef christmas'
Segmentation fault
2;139 juerd@ouranos:~$
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
#23456789_123456789_123456789_12345
perl -le'$x=@_=a..j;print$x--for@_'
sub f {
#23456789_123456789_12345678
$x=@_=a..j;print$x--.$/for@_
}
UPDATE
The answer to the question is "tradition". :-)
UPDATE 2
jmcnamara pointed out that I was miscounting. Fixed. | [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by jynx (Priest) on Jan 29, 2002 at 00:03 UTC
|
Hmm,
are we still not allowed numeric operators (like last time?) Here's my shortest, followed by a rehashing of what i did last time, which is essentially a variation on the sort{$b<=>$a} trick. The lack of \w characters would be more interesting, i think i'll try one if i get some free time today...
#1 (at 35 chars)
map{print@_.$";pop@_}@_=($")x ord$/
#2
$$_=~/((((((((((.))))))))))/for$|..ord$/;print map
$_.$",sort{chr$b cmp chr$a}grep/\d/&$||$_,keys%::
enjoy,
jynx
Update: i have a version with no \w characters which can be found below | [reply] [Watch: Dir/Any] [d/l] [select] |
|
In order to free up my scratchpad, here's my entry for the no \w characters portion of this contest. There are numeric operators, but no underscores (which was a trick unto itself). The invocation of the script is not counted towards the "no \w character limit", or at least i didn't count it...
Well, ok, the first version uses 4 letters ('e', 'v', 'a', and 'l') and the second version reuires a special invocation. And no, neither of them are remotely strict or warning compliant. But hey, it's the best i could do. i'd be interested in seeing other's attempts (should they choose to go insane and try this as well :)
enjoy,
jynx
# 1
# requires no special invocation, uses 'e','v','a','l'
%!=('!'=>$|+@{[$"]},'@'=>$|+@{[$",$"]});($;{'!'})=$::{'"'}=~/\*.(.)/
;$;{'^'}=$;{'#'}=$;{'!'};$;{'~'}=++$;{'^'};$;{'='}=++$;{'^'};$;{'('
}=++$;{'^'};$;{'!'}=($;{'*'}=++$;{'^'}).$;{'!'};$;{'*'}++;$;{'*'}++
;$;{'='}.=++$;{'*'};($;{'@'})=$::{'"'}=~/\*..(.)/;$;{'&'}=$;{'@'};$;
{'&'}++;$;{'&'}++;$;{'!'}.=++$;{'&'};($;{'*'})=$::{'@'}=~/\*(.)/;$;
{'#'}=$;{'*'}.$;{'#'};($;{'&'})=$::{'$'}=~/\*...(.)/;$;{'@'}.=$;{'&'
};$;{'%'}=$;{'$'}=++$;{'&'};$;{'('}=$;{'%'}.$;{'('};$;{'*'}=++$;{'&'
};$;{'@'}=$;{'*'}.$;{'@'};$;{'#'}.=$;{'&'};$;{'$'}=$;{'*'}.$;{'$'}.
$;{'&'};$;{'*'}++;@;=$;{'('}=~/(.)(.)/;$;{'('}=$;[$|].++$;{'*'}.$;[
$!{'!'}];$;{'='}.=$;{'*'};@;=$;{'@'}=~/(.)(.)(.)/;$;{'@'}=$;[$|].$;
{'*'}.$;[$!{'!'}].$;[$!{'@'}];$;{'~'}=++$;{'*'}.$;{'~'};$;{'@'}.=++
$;{'*'};@;=$;{'~'}=~/(.)(.)/;$;{'~'}=$;[$|].++$;{'*'}.$;[$!{'!'}];@;
=$;{'!'}=~/(.)(.)(.)/;$;{'!'}=$;[$|].++$;{'*'}.$;[$!{'!'}].$;[$!{'@'
}];($;{'*'})=$::{'"'}=~/\*(.)/;
eval
$;{'~'}.$".$;{'^'}.'{'.$;{'!'}.$".$;
{'$'}.'}';$;{'^'}->($;{'~'}.$".$;{'%'}.'{'.$;{'('}.$".$;{'$'}.'}');$;
{')'}=$;{'^'}->($;{'='}.'($=+'.$;{'^'}->($;{'('}.'"#"').')');$;{'^'}
->($;{'~'}.$".$;{'&'}.'{'.$;{'@'}.'@'.$;{')'}.'}');$;{'^'}->($;{'~'}
.$".$;{'*'}.'{'.$;{'#'}.'{'.$;{'&'}.'(@'.$;{')'}.'.$");'.$;{'$'}.'@'
.$;{')'}.'}@'.$;{')'}.'}');$;{'*'}->($",$",$",$",$",$",$",$",$",$")
# 2
# call using: perl -e 'sub e{eval"@_"}do"./foo"'
# where 'foo' is the filename where the code is stored
%!=('!'=>$|+@{[$"]},'@'=>$|+@{[$",$"]});($;{'!'})=$::{'"'}=~/\*.(.)/
;$;{'^'}=$;{'#'}=$;{'!'};$;{'~'}=++$;{'^'};$;{'='}=++$;{'^'};$;{'('
}=++$;{'^'};$;{'!'}=($;{'*'}=++$;{'^'}).$;{'!'};$;{'*'}++;$;{'*'}++
;$;{'='}.=++$;{'*'};($;{'@'})=$::{'"'}=~/\*..(.)/;$;{'&'}=$;{'@'};$;
{'&'}++;$;{'&'}++;$;{'!'}.=++$;{'&'};($;{'*'})=$::{'@'}=~/\*(.)/;$;
{'#'}=$;{'*'}.$;{'#'};($;{'&'})=$::{'$'}=~/\*...(.)/;$;{'@'}.=$;{'&'
};$;{'%'}=$;{'$'}=++$;{'&'};$;{'('}=$;{'%'}.$;{'('};$;{'*'}=++$;{'&'
};$;{'@'}=$;{'*'}.$;{'@'};$;{'#'}.=$;{'&'};$;{'$'}=$;{'*'}.$;{'$'}.
$;{'&'};$;{'*'}++;@;=$;{'('}=~/(.)(.)/;$;{'('}=$;[$|].++$;{'*'}.$;[
$!{'!'}];$;{'='}.=$;{'*'};@;=$;{'@'}=~/(.)(.)(.)/;$;{'@'}=$;[$|].$;
{'*'}.$;[$!{'!'}].$;[$!{'@'}];$;{'~'}=++$;{'*'}.$;{'~'};$;{'@'}.=++
$;{'*'};@;=$;{'~'}=~/(.)(.)/;$;{'~'}=$;[$|].++$;{'*'}.$;[$!{'!'}];@;
=$;{'!'}=~/(.)(.)(.)/;$;{'!'}=$;[$|].++$;{'*'}.$;[$!{'!'}].$;[$!{'@'
}];($;{'*'})=$::{'"'}=~/\*(.)/;$;{'~'}.$".$;{'^'}.'{'.$;{'!'}.$".$;
{'$'}.'}';$;{'^'}->($;{'~'}.$".$;{'%'}.'{'.$;{'('}.$".$;{'$'}.'}');$;
{')'}=$;{'^'}->($;{'='}.'($=+'.$;{'^'}->($;{'('}.'"#"').')');$;{'^'}
->($;{'~'}.$".$;{'&'}.'{'.$;{'@'}.'@'.$;{')'}.'}');$;{'^'}->($;{'~'}
.$".$;{'*'}.'{'.$;{'#'}.'{'.$;{'&'}.'(@'.$;{')'}.'.$");'.$;{'$'}.'@'
.$;{')'}.'}@'.$;{')'}.'}');$;{'*'}->($",$",$",$",$",$",$",$",$",$")
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by belg4mit (Prior) on Jan 29, 2002 at 05:12 UTC
|
Here's my attempt (without peeking):
perl -e '$i=print map ord,qw"m W A +";print print++$i'
That's 44 characters
--
perl -pe "s/\b;([st])/'\1/mg"
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by insensate (Hermit) on Jan 29, 2002 at 03:19 UTC
|
perl -le'@j=(A..K);print$#j--while$#j'
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by BrentDax (Hermit) on Jan 29, 2002 at 03:47 UTC
|
Don't laugh--it's my first golf. 55 chars, appears to follow the rules.
$,=$";print sort{$b<=>$a}(ord(b)-ord a)..(ord(k)-ord a)
UPDATE: This occurred to me about five minutes after that one. 45 chars.
$,=$";print sort{$b<=>$a}map{ord()-ord a}b..k
=cut
--Brent Dax
There is no sig. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
sort{$b<=>$a}@arr
Can be golfed to:
sort{$b-$a}@arr
-Blake
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by particle (Vicar) on Jan 29, 2002 at 05:26 UTC
|
okay, 43 characters. not a winner. but it works under strict and warnings, and i just love the way it looks.
$_="$[thisisperl";print length while chop;
~Particle
| [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by petral (Curate) on Jan 29, 2002 at 06:01 UTC
|
perl -le'$^=~s#.#$_=$'\'';print s/.|$//g#ge'
or 5.6:perl -le'$^=~s/.$/!print@+/e while$^'
update: but this works with 5.005:perl -le'$_=$^;s||s/.$/!print length/e|ge'
  p | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by redsquirrel (Hermit) on Jan 31, 2002 at 17:14 UTC
|
This was a fun one I whipped up real quick, it's definitely not a winner (43), but fun to write:
perl -e'print index xwvutsrqpon,$_ for n..w'
--Dave | [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by belden (Friar) on Jan 31, 2002 at 08:45 UTC
|
Using hex seems to be an abuse of the rules, but what the
heck: gotta start golfing sometime. At 30 characters:
#23456789_123456789_123456789_
$_=hex a;print$_--,"\n"while$_
Update: juerd pointed out that I can't count. Fixed.
(I was claiming 34 characters.)
blakem's hint brings me down to 28 characters
#23456789_123456789_12345678
$_=hex a;print$_--,$/while$_
blyman
setenv EXINIT 'set noai ts=2' | [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
In golf, "\n" is spelled $/
-Blake
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: TIMTOWTDI/golf - counting backwards
by demerphq (Chancellor) on Jan 31, 2002 at 16:51 UTC
|
I suspect this may have been already done, but without looking at any other replies I get 38 chars.
UPDATE pulled 3 chars off by using $/ instead of "\cJ"... Yowzer! chimpmunk++!
#12345678901234567890123456789012345678
unshift@a,++$;while$;<ord"\cJ";print@a
unshift@a,++$;while$;<ord$/;print@a
Now to see the other solutions... :-)
Yves / DeMerphq
--
When to use Prototypes? | [reply] [Watch: Dir/Any] [d/l] |
Re: TIMTOWTDI/golf - counting backwards
by stefp (Vicar) on Feb 02, 2002 at 01:34 UTC
|
map{print+substr-"$_$/",1}-ord"\cJ"..-ord"\cA"
I need the substr() to get read of spurious pluses
--
stefp -- check out TeXmacs
wiki | [reply] [Watch: Dir/Any] [d/l] |