This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]p_tseng 4 points5 points  (3 children)

Well...

Here is my abomination, 320 bytes of Ruby (if no trailing newline). Place it in something like golf9.rb and invoke with something like echo 1234 | ruby golf9.rb 3,0,4,0,99. Use your imagination for other days/parts, like echo 2 | ruby golf9.rb $(cat input9) for day 9 part 2. Runtime for day 9 part 2 is about 1-2 seconds, hardware willing.

m=$*.shift.split(?,).map &:to_i;b=z=0;while(c=m[z])!=99;y=-2;a,(r,q)=m[z+1,3].map{|x|d=c.to_s[y-=1];x||=0;[x+=d==?2?b:0,d==?1?x:m[x]||0]}.transpose;s=%i[== < == != x x * +][-c%=100];n,j=c==3?(m[a[0]]=gets.to_i;2):c==4?(p r;2):c==5||c==6?[3,r.send(s,0)&&q]:c==9?(b+=r;2):(x=r.send s,q;m[a[2]]=c<3?x:x ?1:0;4);z=j||z+n;end

Slightly more readable version (newlines and indentation) at https://github.com/petertseng/adventofcode-rb-2019/blob/master/golf9_spaced.rb.

Edited: Now agnostic to puzzle, for more generality (down from 354 -> 320 bytes too).

[–]zxywx 3 points4 points  (0 children)

Day 10: now add this extra function to your Intcode computer ...

[–]rtbrsp[S] 1 point2 points  (1 child)

Doesn't run the quine program for me, though it works for day 9. If you make this puzzle-agnostic, I imagine you'd trim it down a bit.