From 0315074fc670cd81e9be6775ca918abaa2f3729f Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 18 Dec 2023 08:04:30 -0600 Subject: [PATCH] day 15 golf more, 710 effective bytes 727 bytes here; remove 9 newlines plus these 8 bytes: "$1,a,97,". Adds more time; now >26m. For grins and giggles, I tested how bad the O(n^3) effects are. Comparing the sample input (52 bytes, 11 elements): $ m4 -dae --trace=_ -DI=file -Dfile=tmp.15 day15.golfm4 2>&1 | wc 10195 17974 1841213 with my input (22969 bytes, 4000 elements): $ m4 -dae --trace=_ -DI=file -Dfile=day15.input day15.golfm4 2>&1 | wc 58172577 2885010715 625012937407 Yes, that really is 58 million calls, and making m4 parse over half a terrabyte of data JUST on the arguments and expansion of my macro (not to mention the parsing of the two index() and ifelse() per _() call). --- 2023/day15.golfm4 | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) rewrite 2023/day15.golfm4 (73%) diff --git a/2023/day15.golfm4 b/2023/day15.golfm4 dissimilarity index 73% index bc82d09..8b52557 100644 --- a/2023/day15.golfm4 +++ b/2023/day15.golfm4 @@ -1,11 +1,9 @@ -define(_,`ifelse(index($1,^),0,`shift($@)',$1,$,`eval($2)',$1,~,`substr$2',$1,@, -`_(^_(^_(^_(^_(^$@)))))',$1,&,($3+$2)*17%256,$1$3,?0,$2+,$1$3,>,,$1,>,`+($2)*(1+ -$4)*$5_(>,_(?,$2,_($,$4-$7+0))1,_(^_(@,$@)))',$1$3,-,,$1$2,-$3,`,_(^_(@,$@))', -$1,-,`,$3,$4,$5_(-,$2,_(^_(@,$@)))',$1$2,*1+,`,$3,$4,$5,$6,$7,$8,_(^',$1$3,*$6, -`,$3,$4,$5,_(^',$1,*,`,$6,$7,$8_(+,$3,$4,$5',$1$5,+,`,$2,$3,$4',$1,+,`_(*,_($,$3 -<$6)$@),_(@,_(@,,$@)))',$1$4,!,`$2) _($,_(>,1,_$3)',$1,!,`$2_(!,+_(%,0,,,$4,$3), -_(@,$@))',$1$4,%-,`_(&,$2,45),(^_(-,$3,_$6))',$1$4,%=,`_(&,_(&,$2,61),$5+48),(^ -_(+,$3,$2,$5,_$6))',$1,%,`_(%,_(&,$2,_($4)),$3$4,_(~,($5,0,1)),_(~,($5,1)),$6)', -$1,b,98,$1,c,99,$1,d,100,$1,f,102,$1,g,103,$1,h,104,$1,j,106,$1,k,107,$1,l,108, -$1,m,109,$1,n,110,$1,p,112,$1,q,113,$1,r,114,$1,s,115,$1,t,116,$1,v,118,$1,x, -120,$1,z,122,$1,a,97,$1,o,111)')_($,_(!,,,include(I))) +define(_,`ifelse(index($1,^),0,`shift($@)',$1,$,`eval($2)',$1,~,`substr$2',$1,@, +`_(^_(^_(^_(^_(^$@)))))',$1,&,($3+$2)*17%256,$1$3,?0,$2+,$1$3,>,,$1,>,`+($2)*(1+ +$4)*$5_(>,_(?,$2,_($,$4-$7+0))1,_(^_(@,$@)))',$1$3,-,,$1$2,-$3,`,_(^_(@,$@))',?, +$1,,$1,-,`,$3,$4,$5_(-,$2,_(^_(@,$@)))',$1$2,*1+,`,$3,$4,$5,$6,$7,$8,_(^',$1$3, +*$6,`,$3,$4,$5,_(^',$1,*,`,$6,$7,$8_(+,$3,$4,$5',$1$5,+,`,$2,$3,$4',$1,+,`_(*,_( +$,$3<$6)$@),_(@,_(@,,$@)))',$1$4,!,`$2) _($,_(>,1,_$3)',$1,!,`$2_(!,+_(%,0,,,$4, +$3),_(@,$@))',$1$4,%-,`_(&,$2,45),(^_(-,$3,_$6))',$1$4,%=,`_(&,_(&,$2,61),$5+48 +),(^_(+,$3,$2,$5,_$6))',$1,%,`_(%,_(&,$2,_($4)),$3$4,_(~,($5,0,1)),_(~,($5,1)), +$6)',$1,,,$1,a,97,index(bcdefghijklmnopqrstuvwxyz,$1)+98)')_($,_(!,,,include(I))) -- 2.11.4.GIT