# Tag Info

54

Snails, 13 bytes !(t\P(o\ ),o~ Try it online! Prints 0 for insecure prisons and the size of the input's bounding box for secure prisons. The idea is to ensure that we can't find a path from a P to an out of bounds cell (~) moving only orthogonally (o) through spaces. The t is a teleport so that regardless where we attempt the match it tries all possible ...

45

Python 2, 208 205 200 bytes A=lambda n:n and A(~-n/3)+[-n%3]or[] f=lambda x,y:f(A(x),A(y))if x<[]else["SSNEW"[m::3]for m in y[len(x):]]if x==y[:len(x)]else min([["NNSWE"[m::3]]+f(x[:~x[::-1].index(m)],y)for m in set(x)],key=len) A function, f, taking a pair of node numbers, and returning the shortest path as a list of strings. Explanation We start by ...

33

Matlab, 255 245 231 bytes This expects the image name first, then y and then x. I=@input;i=imread(I('','s'));[r,c]=size(i);m=zeros(r,c);m(I(''),I(''))=1;M=m;d=m;K=[1,2,1];for k=1:r*c;d(m&~M)=k;M=m;m=~~conv2(m,K'*K>1,'s');m(~i)=0;end;z=max(d(:));v=[1,1,3];imshow(ind2rgb(d,hsv(z)).*repmat(m,v)+repmat(~d&i,v),[]) I implemented the flood filling (...

31

Hexagony, 2437 bytes The long-awaited program is here: (.=$>({{{({}}{\>6'%={}{?4=$/./\_><./,{}}{<$<\?{&P'_("'"#<".>........_..\></</(\.|/<>}{0/'$.}_.....><>)<.$)).><$./$\))'"<$_.)><.>%'2{/_.>(/)|_>}{{}./..>#/|}.'/$|\})'%.<>{=$_.\<))<>(|\4?<.{.%.|/</{=...... 19 Perl, 216 215 bytes Includes +2 for -0p Give input on STDIN. Use % for external walls, # for internal walls, 0 for empty spaces, 8 for mice and r for the starting position. The whole boards must be padded so it forms a rectangle. You can transform and run the examples as: cat dynamite.txt | perl -p0e 's/.+/a^=&/egr;s//sprintf"%-*s",lengtha,&/... 18 Python, 1,291 1,271 1,225 bytes As Martin noted, this problem can be largely reduced to his excellent rubber band challenge. Using that challenge's terminology, we can take as the second set of nails the points of intersection between the circles on the boundary of the enclosed area: As the rubber band we can take any path P between the two endpoints that ... 18 Pyth, 43 bytes ?}QKhu?Jf}QTGJsm+Ld+yedsMfnhT\0.pedGQ]]1KY Demonstration. This is starts by generating all possible double or rearrange sequences. However, since I actually wanted to see it finish, I added a short circuit. It either runs until it finds a solution, or for a number of iterations equal to the input, at which point it gives up and returns [].... 18 Mathematica (version 9), 165 bytes The nice, short ConvexHullMesh function that Greg Martin used was only introduced in Mathematica version 10, so I thought I'd make an attempt without it, using my ancient Mathematica version 9. I managed to get it slightly shorter, though! It's a function that takes and returns a list of strings (with ., # and o as the ... 17 JavaScript (ES6) - 122 124 148 162 172 178 187 190 193 208 bytes Many thanks to Optimizer and DocMax for helpful suggestions on how to improve this code: F=a=>(D=(x,y,d)=>!D[i=[x,y,d]]&&(D[i]=1,x-=~d%2,y-=~-~d%2,x*y==49||!((x|y)&8||a[y][x])&&(D(x,y,d)||D(x,y,~-d%4))),D(-1,0)) Returns true (truthy) for solvable and false (falsy) ... 17 Python 2, 291 bytes def f(M): Y=map(max,M).index("S");X=M[Y].find("S");V={()};Q=[(0,0,0,1,"")] while Q: try:x,y,u,v,p=s=Q.pop(0);c=(Y>=y<=X-2*x)*ord(M[Y-y][X-2*x-y]) except:c=0 if c==69:return p if{c%2*s[:4]}-V:V|={s[:4]};Q+=(x+u,y+v,u,v,p+"F"),(x,y,-v,u+v,p+"R"),(x,y,u+v,-u,p+"L") return"Invalid maze!" A function, f, taking the ... 17 Perl, 150 149 146 145 141 140 138 136 135 133 130 126 125 124 Added +7 for -F -Xn0i An initial attempt. Run with the map on STDIN and the directions after the -i option, e.g. perl -F -Xn0iRL incomplete.pl .....A .#.### B....C ##.#.# D....E ##F### Close STDIN with ^D or ^Z or whatever works on your operating system. incomplete.pl: %P=0;^I=~s{%;=!/ /;... 16 ColorScorePlayer, preliminary score ≈ 22 This is the bot you see at work in the GIF in the challenge. This was our test bot throughout the development phase. It uses the genome to store a quality score for each of the 16 colours. Then it makes the forward move that moves it onto the colour with the best score (and never moves onto -1). In case of a tie, a ... 16 C# (.NET Core), 485 480 474 470 421 408 bytes The absolutely wrong tool and approach, but nonetheless... 7 bytes (and more) saved with the useful tips from TheLethalCoder. 4 bytes saved by returning an integer. 4 more bytes saved thanks (once again) to TheLethalCoder by replacing ' ' with 32 in the comparisons. LOTS of bytes saved by refactoring the code. ... 15 Perl 5, 69 bytes -10 bytes thanks to @Grimy. -2 bytes thanks to @Neil. 77 byte of code + -p0 flags. / /;_=s/(P| )(.{@{-}})?(?!\1)(?1)/P2P/s?redo:!/\A.*P|P.*\Z|^P|P/m Try it online! Some short explanations: The idea is to put a P everywhere the prisoners can go. If any P is on the first/last line, or the first/last column, then the prisoners can go ... 15 J, 42 bytes v(+}.<.}:)&.>/@{.[:</.(2#v=._1+1#.){.!._] Try it online! How it works v(+}.<.}:)&.>/@{.[:</.(2#v=._1+1#.){.!._] v=._1+1#. Sum of two dimensions - 1; assign to v (v is a verb) (2# ){.!._] Extend the given ... 14 Slip, 47 bytes a(?,[-+]*((/<|\>)[|+]*(/>|\<)[-+]*)*:) Test it here. Yay for undocumented features... Explanation Slip is basically a two dimensional regex syntax and by default Slip programs print the subset of the input that they matched. In this case I'm simply matching a valid path. To prevent printing the entire path, I'm usng ... 13 JavaScript, 863 834 785 781 bytes Saved 29 bytes thanks to ETHproductions Saved 53 bytes thanks to Jordan L=[] f=(S,r="",R="",p=0,s=S.replace(RegExp(r),R),l=((.|\n){{s.split [0].length}}),q=p+1,o=p+2,n=p+50)=>s in L|p>999?1e3:!/M/.test(s,L[s]=0)&/E/.test(s)?p:Math.min(...[[/ E/,"me",q],[/ E/,"de",o],[/ME/,"ce",q],[/E /,"em",q],[/E /,"ed",o],[... 13 JavaScript (ES7), 140 139 138 bytes Takes input as a matrix of integers with the following mapping:$-1$= 🔵 (any portal)$0$=$X$(empty)$1$= 🌄 (mountain)$2$= 🐢 (turtle)$3\$ = 🍓 (strawberry) m=>(R=g=(t,X,Y,i)=>m.map((r,y)=>r.map((v,x)=>r[(u=0,t?v-t:(x-X)**2+(y-Y)**2<3?v-3?~v?v:u--:R=R<i?R:i:1)||g(u,x,y,u-...

12

FirstRacer Java (5825 + 305*10 = 8875) Just to have a start. Needs 305 segments on City. This Java program does it pipelined: read the image A* (A star) 2.1 Build the A* search landscape. 2.2. Track back looking only for the best *direct* 8 neighbor cells (N,S,E,W,NE,NW,SE,SW). This finds the shortest track t0 pixelwise. stay on t0 and optimize it for ...

12

ColorFarSeeker, C++ ≈ 74.7 This challenge is really quite fun and simple if you try it. Don't get put off by the long description. Just visit the GitHub and check things out... everything will be much clearer! :) The C++ simulator is highly recommended for its speed. Even after I've finished translating my python program to C++, the python simulation ...

12

Perl 6, 259 295 bytes {my \a=S:g/(.)$0+/{$0 x($/.comb+.5)*2/3}/;sub f (\c,\v,*@p) {with (c ne any v)&&a.lines».comb[+c[0];+c[1]] ->$_ {for (/\s/??10011221!!/I/??a~~/^\N*I|I\N*$/??2101!!1012!!'').comb X-1 {f [c Z+$^a,$^b],(|v,c),@p,chr 8592+$++} take @p if /U/}} [~] (gather f a~~/(\N+\n)*(.)*I/,[]).min(+*)[1,3...*]} How it works my \a = S:g/ (.) ...

12

Python 2, 113 107 105 99 95 bytes a,b=input() i=0 print a for x in a: while x-b[i]:a[i]=x=(x+(x-b[i])%10/5*2-1)%10;print a i+=1 Try it online! Takes input as lists of integers Saved: -6 bytes, thanks to Joel -4 bytes, thanks to Jitse

11

Python, 599 chars import os,sys from math import* I=os.read(0,999) O=[] h=v=0 for i in I: if'#'==i:O+=[(h,v,h+1,v+1),(h+1,v,h,v+1)] if'O'==i:O+=[(h,v+1,h-2,v+3)];T=(h,v+5,h-2,v+7) if'}'==i:e=h+.5;c=v+.5 h+=1 if'\n'==i:v+=1;h=0 def X(K,L): A,B,C=K;p=L[0];q=L[2]-p;r=L[1];s=L[3]-r;A,B,C=A*q*q,2*A*p*q+B*q-s,A*p*p+B*p+C-r;d=B*B-4*A*C return 0 if d<0 ...

11

Python 2.7, 352 344 281 bytes from math import* def l(a,b,n): a*=1.;b*=1. r=set() for i in range(1,n+3): t=[] for k in range(1,i): for h in[0,.5]: x=(i-k-h) if 1-(x/k in r):r.add(x/k);t+=(x*a,k*b), d=(a*n+1)**2+(b*n+1)**2 for x,y in t: if x*x+y*y<d:d=x*x+y*y;o=degrees(atan(y/x)) return o -16 bytes thanks to @Dschoni Explanation: ...

11

Slip, 38 27 25 bytes S>(=<<P{1,5}>P>P*)+#E Requires input to be padded to a rectangle such that there are spaces in every cell Mario needs to traverse (potentially with a leading line full of spaces). Prints either a string representing the valid path (which includes S, E and all the = walked on except the last) or nothing if no path ...

11

(But go upvote Notatree's solution, it's better!) Mathematica, 168 bytes (x_~n~y_:=Min[Norm[x-#]&/@y];i=#;p=i~Position~#&;t=p["#"|"."]~Select~#&;(i~Part~##="o")&@@@t[#~n~t[ConvexHullMesh[Join[s=p@"#",#+{.1,.1}&/@s]]~RegionMember~#&]==1&];i)& Pure function taking a 2D array of characters as input and returning a 2D array of ...

10

C++, 5.4 (deterministic, optimal) Dynamic programming solution. Provably optimal. Very fast: solves all 20 testcases in 0.2s. Should be especially fast on 64-bit machines. Assumes the board is less than 32,000 places in each direction (which should hopefully be true). This racer is a little unusual. It computes the optimal path at the starting line, and ...

Only top voted, non community-wiki answers of a minimum length are eligible