#!perl -lp
y+ ++d;$*.=/\d/?"$_ ":($s=~s~^.*?(?=@{['|'x/\(/.'-|\+|'x/[*\/]/]}\(|$)~$_ ~,$&),$s=~s+\) . ++for/(?
|
I feel a bit embarassed flogging the same horse, but I am too tired to think of anything new. Gee, I thought Keith had given up, but he is right behind me now and I fear he will finish stronger.
#!perl -lp
y+ ++d;$*.=/\d/?"$_ ":($s=~s~^.*?(?=@{['^|'x/\(/.'-|\+|'x/[*\/]/]}\(|$)~$_ ~,$&),$s=~s+\) . ++for/(?
|
I hope `/ refs this one for I have smashed the refs 138 wall with my trusty one iron (much to my surprise I must admit).
#!perl -lp
y+ ++d;$*.=/\d/?"$_ ":($s=~s~^.*?(?=@{["[@{['-+'x/[*\/]/]}(]|\$"x!/\(/]})~$_ ~,$&),$s=~s+\) . ++for/(?
|
Caught the refs!!! Amazingly just by flogging the same ol' dead horse. Gee, Amir is moving up fast from behind. Recite litany against fear.
#!perl -lp
y~ ~~d;$x.=/\d/?"$_ ":($s=~s~@{[/\(/?v94:".*?(?=[@{['-+'x/[*\/]/]}(]|\$)"]}~$_ ~,$&),$s=~s~\) . ~~for/(?
|
That horse just keeps on going.
#!perl -lp
y~ ~~d;$x.=/\d/?"$_ ":($s=~s~@{[/\(/?v94:".*?(?=[@{['-+'x/[*\/]/]}(]|\$)"]}~$_ ~,$&),$s=~s~\) . ~~for/(?
|
Much cleaner now.
#!perl -lp
y~ ~~d;$x.=/\d/?"$_ ":
($s=~s~@{[/\(/?v94:".*?(?=[@{['-+'x/[*\/]/]}(]|\$)"]}~$_ ~,$&),
$s=~s~\) . ~~,for/(?
|
Getting slower and grottier. Time for a new approach.
#!perl -lp
y~ ~~d;$x.=/\d/?"$_ ":!/\(/&&
($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$&),
$s="$_ $s",$s=~s~-?\d+ |\)...~~for/(?
|
grotty 'next' ... gone! grotty 'substr' ... gone! ... solution still grotty :-( Oh well, at least I broke 150, which I never expected to. Mad Dutch described his stupendous 98 as "quick and dirty". I wonder, is it just plain filthy or is it *really* pornographic? I suppose Rick could take his revenge and label the person who created it as "clearly insane". :)
#!perl -lp
y~ ~~d;$x.=/\d/?"$_ ":
!/\(/&&($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$&),
/\d/||($s="$_ $s",$s=~s~\)...~~)
for/(?
|
Hurrah, exactly 100 strokes whittled from my first entry. Never whittled that much before. And puts me a nostril ahead of Chris Dolan. ^.^
#!perl -lp
y~ ~~d;/\d/&&($x.="$_ ",next),
/\(/||($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$x.=$&),
$s=/\)/?substr$s,2:"$_ $s"for/(?
|
By pure luck, I happened to be reading one of my favourite books, the shiny ball book by Joseph N Hall. He suggests on page 62, "Let's ignore white-space ... it could have been tr-ed out beforehand". Of course, "tr-ed" in golfspeak is "y-ed". ;) This simple idea just saved me 20 strokes. Amazing!
Took you long enough ;)
#!perl -lp
y~ ~~d;/\d/&&($x.="$_ ",next),
/\(/||($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$x.=$&),
$s=/\)/?substr$s,2:"$_ $s"for/(?
|
*cough* This game is improving my regex knowledge. Variable width look-behind would be nice; I wonder if Larry is going to do that for Perl 6.
#!perl -lp
$_=" @{[/\d+|\S/g]}";s~(?<=[^\d)] -) ~~g;
/\d/&&($x.="$_ ",next),/\(/||($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$x.=$&),
$s=/\)/?substr$s,2:"$_ $s"for/\S+/g;$_=$x.$s;chop
|
Just a pathetic regex tweak. I suck.
#!perl -lp
$_=" @{[/\d+|\S/g]}";s~(?<=^ -|[^\d)] -) ~~g;
/\d/&&($x.="$_ ",next),/\(/||($s=~s~.*?(?=[@{['-+'x/[*\/]/]}(]|$)~~,$x.=$&),
$s=/\)/?substr$s,2:"$_ $s"for split;$_=$x.$s;chop
|
Come on Keith!
#!perl -lp
$_="@{[/\d+|\S/g]}";s~(?<=[^\d)] -) ~~g;s~^- ~-~;
/\d/&&($x.=$_.$",next),$:='-+'x/[*\/]/,
/\(/||($s=~s~.*?(?=[$:(]|$)~~,$x.=$&),
$s=/\)/?substr$s,2:"$_ $s"for split;$_=$x.$s;chop
|
I am shocked to go sailing gaily path Keith.
#!perl -lp
$_="@{[/\d+|\S/g]}";s~(?<=[^\d)] -) ~~g;s~^- ~-~;
$x.="$_ "x/\d/,$s=/\(/.$s,/[\d(]/&&next,
$:='-+'x/[*\/]/,$s=~s~.*?(?=[$:1]|$)~~,$x.=$&,
$s=/\)/?substr$s,1:"$_ $s"for split;$_=$x.$s;chop
|
To my great surprise and delight, I have almost caught Keith! I am sure he will spurt away from me, however.
#!perl -lp
$_="@{[/\d+|\S/g]}";s~(?<=[^\d)] -) ~~g;s~^- ~-~;map{$x.="$_ "x/\d/;$s=/\(/.$s;$s=~s~(.*?)1~~,$x.=$1if/\)/;$s=~s~.*?(?=[@{['-+'x/[*\/]/]}1]|$)~~,$x.=$&,$s="$_ $s"if!/[\d()]/}split;$_=$x.$s;chop
|
Still flogging the same horse. Just one dirty trick after another (the latest being the default regex). I still think Mtv's Lemma holds the key to this game. Like Rick's Troppo Sort game, I suspect (from the leaderboard turnaround times) that the leaders are using a much slower algorithm than mine.
#!perl -lp
$_="@{[/\d+|\S/g]}";s;(?<=[^\d)] -) ;;g;s;^- ;-;;map{
$x.="$_ "x/\d/;$s=/\(/.$s;$s=~s/(.*?)1//,$x.=$1if/\)/;
if(/[-+*\/]$/){$s=~s/..//,$x.=$&while$s&&$s<1&$s=~/^[-+]/<=//;$s="$_ $s"}
}split;$_=$x.$s;chop
|
*Cough* there were a lot of blunders in my earlier efforts. And plenty more remain. Kept my original algorithm, just corrected some blunders and changed from array-based to string-based.
#!perl -lp
$_="@{[/\d+|\S/g]}";s;(?<=[^\d)] -) ;;g;s;^- ;-;;map{
$x.="$_ "x/\d/;$s=Y x/\(/.$s;$s=~s/(.*?)Y//,$x.=$1if/\)/;
if(/[-+*\/]$/){$s=~s/..//,$x.=$&while$s&&$s=~/^[-+]/<=/[-+]/&$s!~/^Y/;$s="$_ $s"}
}split;$_=$x.$s;chop
|
Dirty trick: changed '(' token to 'Y'. Since the actual letter is arbitrary, I naturally chose 'Y' to honour our esteemed referee, Dr `/anick Shampoo.
#!perl -n
$_="@{[/\d+|\S/g]}";s;(?<=[^\d)] -) ;;g;s;^- ;-;;map{
/\d/?push@o,$_:/\(/&&unshift@~,Y;if(/\)/){push@o,$:while($:=shift@~)!~Y}
if(/[-+*\/]$/){push@o,shift@~while@~&&$~[0]=~/[-+]/<=/[-+]/&$~[0]!~Y;@~=($_,@~)}
}/-?\d+|\S/g;push@o,@~;print"@o
"
|
Interesting problem (kudos to Juho), clumsy opening bid. I think this is the first time I've ever used unshift in a golf game (Ton would never approve ;) -- a sure sign something is wrong. I wonder what The Aliens are doing? I expect they're sitting around the campfire sucking hard on the Regex crack-pipe chanting "Mtv's Lemma, Mtv's Lemma, Mtv's Lemma ...".
253, and it's not signed André? Oh my. (okay, I know it's not right to use of my ref status to gloat, but then again, power corrupts and all that :) )
#!perl -n
$_="@{[/\d+|\S/g]}";s;([^\d)]) - ;$+ -;g;s;^- ;-;;
map{/\d/?push@o,$_:/\(/&&unshift@~,$_;
if(/\)/){push@o,$&while+shift(@~)=~/[^(]/}
if(/[-+*\/]$/){push@o,shift@~while@~&&$~[0]=~/[-+]/<=/[-+]/&$~[0]ne'(';@~=($_,@~)}
}/-?\d+|\S/g;
push@o,@~;print"@o
"
|