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

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


8

Python 2, 236 235 227 212 bytes def f((x,y),G,M,U=[]): R=1-(len(M[0])-1>x>0<y<len(M)-1);H=[(u+cmp(x,u),v+cmp(y,v)*(u==x))for u,v in G];d,e=0,1 for _ in' '*4*(R<1>((x,y)in H)):J=z,w=x+d,y+e;d,e=-e,d;R|=M[w][z]>(J in U)<f(J,H,M,U+[J]) return R Try it online! -15 bytes thx to Bubbler As input, takes a tuple (x,y) as jimmy's ...


7

C, score 2.397x10^38 Man this took way too long to do, most likely due to my choice of language. I got the algorithm working fairly early, but ran into a lot of problems with memory allocation (couldn't recursively free stuff due to stack overflows, leak sizes were huge). Still! It beats the other entry on every test case, and might even be optimal gets ...


7

Haskell, 82 73 bytes r=read.reverse.show f 1=0 f a=1+(minimum$f(a-1):[f$r a|r a<a,mod a 10>0]) Try it online! Simplest recursion method. -9 bytes thanks to Christian Sievers


6

Python, 2.62 * 10^40 This algorithm just floodfills (BFS) the plane starting from the black parts of the image, where for each new pixel we record what black part it was flooded from. As soon as we have two neighbouring pixels with different black parts as ancestors, we basically merge these two black parts by joining them through the ancestors of the two ...


6

Jelly, 15 bytes _æ%5ḣT$ṂṠ⁸_%⁵ðƬ A dyadic Link accepting the start-code on the left and the target-code on the right as lists of integers (in \$[0,9]\$, lengths equal but otherwise arbitrary) which yields a list of lists of the codes from start-code to target-code. Try it online! How? _æ%5ḣT$ṂṠ⁸_%⁵ðƬ - Link: list of integers, s; list of integers, t ...


6

Python 2, 199 bytes def g(I,G,W,w,h): u,v=I.real,I.imag;R=1-(w-1>u>0<v<h-1);H=[z+cmp(u,z.real)+cmp(v,z.imag)*(u==z.real)*1jfor z in G] for d in(R<1>(I in H+W))*range(4):J=I+1j**d;R|=(J in W)<g(J,H,W+[I],w,h) return R Try it online! Rewrite of Chas Brown's solution using complex numbers. All the coordinates are represented as a ...


5

Python 3: 1.7x10^42 1.5x10^41 Using Pillow, numpy and scipy. Images are assumed to be in an images folder located in the same directory as the script. Disclaimer: It takes a long time to process all the images. Code import sys import os from PIL import Image import numpy as np import scipy.ndimage def obtain_groups(image, threshold, structuring_el): ...


5

APL (Dyalog Unicode), 59 57 bytesSBCS {v⍳+\v[⍺],↓⍉↑(|⍴¨×)⊃⍵⍺-.⊃⊂v←9 11∘○¨+\0,0j1*{⍵/⍨⌈⍵÷2}⍳⍺⌈⍵} Try it online! -2 bytes thanks to @ngn. Anonymous function that accepts two endpoints as left and right arguments. Ungolfed & how it works The queen moves diagonally first, so it is sufficient to pre-compute the coordinates of each number up to max(start,...


5

Python 2, 441 431 341 bytes from itertools import* G=input() W=len(G[0]) H=len(G) A=[0]*5 E=enumerate for y,r in E(G): for x,C in E(r):A[C]=[x,y] for L in count(): for M in product(*[zip('UDLR'*2,'LRDU ')]*L): x,y=A[0] for m in M: x+='R'in m;x-='L'in m;y+='D'in m;y-='U'in m if(x,y)==A[3]:x,y=A[2] if 1-(W>x>-1<y<H)or G[y][x]&...


5

Python 3, 163 bytes def f(g,s=[]):w=len(g[0])+1;k=' '.join(g)+w*' ';*p,x=s or[k.find('#')];return' '<k[x]and{x}-{*p}and[min(f(g,s+[x+a])or len(k)for a in(-1,1,-w,w)),len(p)]['+'<k[x]] Try it online! Uses # for start and @ for end. Finds all paths along + and returns the shortest. Each path ends when either a space is encountered, the range is ...


5

JavaScript (ES6), 219 bytes Takes input as a list of lists of characters. a=>((g=(X,Y,D,n=o=0)=>!(a+0)[n++]|a.some((r,y)=>r.some((c,x)=>D=='975'[i='-| #+$'.indexOf(c),x-X+1]-'450'[y-Y+1]?i-3?i-2?i>3?[3,0,7,4].some(d=>D^d^4&&g(x,y,d,n)):~i&&i^D&1?0:g(x,y,D,n):0:o=-n:X+1|i<5?0:g(x,y,2))))(),~o) Try it online! How? ...


5

C++, 140 159 147 145 bytes Edit: new solution without standard library, using a recursive function and pointer magic (constant 20 experimentally determined and not the same on other compilers) Edit 2: -2 bytes thanks to ceilingcat int*s,S,*G,x;int F(int Z,int*p=&x){int W=1,a=(*p)++,r=0;for(;r=r*10+a%10,a/=10;);G?W=r,p<=G?G=&W,S++,p=s:0:p=s=G=&...


4

JavaScript (ES6),  73 72  70 bytes Saved 2 bytes thanks to @tsh Takes input as 2 arrays of digits in curried syntax (a)(b). Returns a string. a=>g=b=>b.some(x=>d=x-(a[++i]%=10),i=-1)?a+` `+g(b,a[i]+=d/5<5/d||9):b Try it online! Commented a => // a[] = initial combination g = b => // b[] = target ...


4

Ruby, 115 182 163 bytes ->s{z=('00'..'99').map{|x|x=~/[09]/||s[(x[1].ord+48).chr+x[0]]};(11..18).map &g=->x{z[x]||[x-11,x-9,x+z[x]=9,x+11].map(&g)};s=~/^([a-h][1-8])*$/&&(z[81,9]-[9])[8]} Try it online! Returns 1 for strong and nil for weak. (The +67 bytes was for taking into account "backtracking.") ->s{ z= ...


4

Python 3 (+ numpy), 183 bytes Assuming the input can be passed in as a numpy character array, here is a different approach. It works by calculating a distance matrix from the start point by repeatedly 'diffusing' distances along roads. Uses '#' for start and '@' for end. from numpy import* def f(A): B=(A!=" ")-1+(A=="#") for _ in nditer(A):B=pad(B,1);B+=(...


3

APL (Dyalog Unicode), 60 bytesSBCS Full program. Prompts for character matrix from stdin. Prints 1 or 0 to stdout. Requires zero-indexing (⎕IO←0) which is default on many systems. P←{' '0∊⍨s←(×⍨≢⍺)⊃,⍵:1∊⍵⋄s} 1∊⊢⌿{P⌺3 3⊢(⍴⍵)⍴1@0P⌺3,⍵}⍣≡3/3⌿⎕ Try it online! (space characters replaced by ░ for clarity) The method here is basically to seed fill from the top ...


3

JavaScript (ES7),  162 156  154 bytes m=>(M=g=(x,y,n,k)=>m.map((r,Y)=>[r[x+1]]+[m[y+1]]?r.map((v,X)=>r[1/v&&(x-X)**2+(y-Y)**2==1&&g(X,Y,u=v+n,k<u?k:u,r[X]=g),X]=v):M=M>k?M:k))(0,0,0)|M<0?2-M:2 Try it online! Commented m => ( // m[] = input matrix M = // ...


3

Python 2, 208 202 bytes lambda s:2-f(s) def f(s,x=0,y=0): if x>-1<y<s[y:]>[]<s[y][x:]!="">s[y][x]:k=s[y][x];s[y][x]="";return k+min(0,max([len(s[y+1:]+s[y][x+1:])and f(eval(`s`),x+a/3-1,y+a%3-1)for a in 7,1,5,3])) return-9e9 Try it online! Python 2, 217 211 bytes i=input() X,Y=len(i[0]),len(i) s=[[0]*4+[i]];r=[] for m,l,x,y,g in s: ...


3

APL (Dyalog Unicode), 144 132 129 118 133 132 130 124 117 bytesSBCS Thank you very much to Ven and ngn for their help in golfing this in The APL Orchard, a great place to learn the APL language. ⎕IO←0. Golfing suggestions welcome. Edit: -12 bytes thanks to Ven and ngn by changing how n is defined and switching from 1-indexing to 0-indexing. -3 due to ...


3

Javascript (ES6), 208 bytes Recursive, depth-first search. A breadth-first approach would be probably faster, but less golfy. Input: a multi line string, using 1 for ghosts, 4 for solid objects, 6 for Jimmy and 2 for empty space. f=(s,l=-~s.search` `,j=s.search(6),g=[...s],x=j%l)=>j<l|!g[j+l]|!x|x>l-3||(g[j]=6,![...g].some((a,i)=>a&1&&...


3

Jelly, 16 bytes Recursion might well end up being less bytes. ṚḌ;‘))Fṭ 1Ç¡ċ€ċ0 A monadic Link accepting a positive integer which yields a non-negative integer Try it online! Or try a faster, 17 byte version How? ṚḌ;‘))Fṭ - Helper Link: next(achievable lists) ) - for each (list so far): ) - for each (value, V, in that list): Ṛ - ...


2

Python 2, 330 318 313 309 370 bytes import numpy as n b=n.ones([8,8]) q=r=1 s=input() l=len(s) def g(x,y=0,p=0): if b[y,x]and p<32: if y<7: if x<7: g(x+1,y+1,p+1) if y:g(x+1,y-1,p+1) if x: g(x-1,y+1,p+1) if y:g(x-1,y-1,p+1) else:global q;q=0 ...


2

Python 2, 391 397 403 422 bytes M=input() from networkx import* a=b=c=d=0 N,h,w,S=[-1,0,1],len(M),len(M[0]),[] for i in range(h): for j in range(w): I,m=(i,j),M[i][j] if m>7:c,d=a,b;a,b=I if m<0:Z=I if m==5:F=I S+=[I+I] S+=[(a,b,c,d),(c,d,a,b)] print len(shortest_path(from_edgelist([((A+p,B+q),(C,D))for A,B,C,D in S for p,q in[(p,q)for p in ...


2

Python 2, 490 476 474 def f(p): a=[set(ord(c)-33 for c in s)for s in"* )+ *, +- ,. -/ .0 / \"2 !#13 \"$24 #%35 $&46 %'57 &(68 '7 *: )+9; *,:< +-;= ,.<> -/=? .0>@ /? 2B 13AC 24BD 35CE 46DF 57EG 68FH 7G :J 9;IK :<JL ;=KM <>LN =?MO >@NP ?O BR ACQS BDRT CESU DFTV EGUW FHVX GW JZ IKY[ JLZ\\ KM[] LN\\^ MO]_ NP^` O_ R QS RT SU TV ...


2

Jelly, 47 43 bytes p®§Qæ%L}>Ƈ0ịƇ =⁶oŻ$€µZL;1;N$©ṛF1çƬFṀ’:®Ḣ‘=L Try it online! A full program that takes a list of strings as its argument and returns 1 if the bottom line is reachable and 0 if not. Explanation Helper link Test moves up, down left and right and extend reachable position list. Left argument: most recently added reachable position ...


2

Jelly, 25 bytes _æ%5+⁹⁹rḊ€%⁵J;Ɱ"$ẎṄḢ}⁺¦¥ƒ Try it online! Full program.


2

Python 2, 101 97 bytes a,c=input() print a for i in 0,1,2: while a[i]!=c[i]:a[i]=(a[i]+(a[i]-c[i])%10/5*2-1)%10;print a Try it online! 3 bytes thx to Joel. Takes input as lists of ints.


2

JavaScript (ES7),  131  130 bytes Takes input as a matrix of characters. Expects 1 for the starting point and 2 for the arrival. m=>(M=g=(X,Y,n)=>m.map((r,y)=>r.map((c,x)=>(X-x)**2+(Y-y)**2^1?c^1||g(x,y,r[x]=g):1/c?c^2|M>n?0:M=n:r[g(x,y,r[x]=~-n),x]=c)))()|-M Try it online!


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