New answers tagged

2

Wolfram Language, 108 bytes Tr@MatrixPower[AdjacencyMatrix[4~KnightTourGraph~3~VertexDelete~{10,12}],#2,SparseArray[Mod[#,10,1]->1,10]]& Try it online! You know, there's probably a shorter solution for this, but I enjoy the mathematics of this one. This gets the adjacency matrix for the graph, raises it to the power of the number of jumps, and ...


5

Python 2, 83 bytes f=lambda s,n:n<1or sum(f(i,n-1)for i in range(10)if`i`+`s`in`0x20cb0e9fd6fe45133e`) Try it online! A recursive solution. Checks for pairs of digits that are a knight's move away by them being consecutive in the hardcoded string 604927618343816729406, written one byte shorter in hex. This string is a palindrome because the adjacency ...


2

T-SQL, 197 bytes Returns null for no solutions This can handle 25 hops in 10 seconds WITH C as(SELECT 0i,1*translate(@n,'37986','11124')x,1q UNION ALL SELECT-~i,y,q*(2+1/~(y*~-a))FROM(values(1,4),(1,2),(4,0),(2,1),(4,1),(0,4))x(a,y),c WHERE a=x AND i<@) SELECT sum(q)FROM C WHERE i=@ Try it online


4

Python 3, 88 bytes f=lambda s,n:n<1or sum(map(f,'46740 021268983 1634 9 7'[int(s)::10].strip(),[n-1]*3)) Try it online! -15 bytes thanks to ovs -2 bytes thanks to Jonathan Allan


2

Java 8, 137 129 bytes (s,h)->{for(;h-->0;){var t="";for(var c:s.getBytes())t+="46,68,79,48,309,,107,26,13,24".split(",")[c-48];s=t;}return s.length();} Can probably be golfed a bit more. Starting digit as a String input, amount of hops as an integer. Try it online. Explanation: (s,h)->{ // Method ...


2

05AB1E, 24 22 bytes F•žNjεEÿ¶^²è+%•5¡sèS}g Amount of hops as first input, and the starting digit as second input. Try it online or verify all test cases (except for the one with 20 hops, which times out). Explanation: F # Loop the first (implicit) input amount of times: •žNjεEÿ¶^²è+%• # Push compressed integer 46568579548530955107526513524 ...


4

Perl 5, (-p) 63 bytes eval's/./(46,68,79,48,390,"",170,26,13,24)[$&]/ge;'x<>;$_=y///c Try it online!


4

Jelly,  29  28 bytes ⁵ṗ’;;Ṣe“¡¿Ṅ\ȷḳ€°ị’Ds2¤ʋƝPɗ€S A dyadic Link accepting the number of hops on the left and the key on the right which yields the number of paths. Try it online! How? Forms all length hops decimal numbers, prepends key to each and counts how many have all valid neighbours by lookup in a compressed list. (Note: when hops is zero the fact ...


17

JavaScript (ES6),  86 74  72 bytes f=(p,n,k=10)=>n?k--&&(306>>(p*2149^k*2149)%71%35&1&&f(k,n-1))+f(p,n,k):1 Try it online! 71 bytes Much, much slower. f=(p,n,k=10)=>n?k--&&(306>>(p*2149^k*2149)%71%35&1)*f(k,n-1)+f(p,n,k):1 Try it online! Finding a hash function We are looking for a function \$h(p,k)\$ ...


4

Charcoal, 31 bytes FN≔⭆η§⪪”)‴↘S‴Peυ!&q]3⁰4”¶IκηILη Try it online! Link is to verbose version of code. Takes the number of hops as the first input. Too slow for large numbers of hops. Explanation: FN Input the number of hops and repeat that many times. ≔⭆η§⪪”)‴↘S‴Peυ!&q]3⁰4”¶Iκη Map over every character in the string and list its possible next hops....


6

Stax, 63 bytes ÷Qa9═wë•Θ╣äUuâ£▼+∙8WU▓kw≈▲!.┤α@∟┐₧╨═ºî⌂z▼0╬⌂6╕ú▄O&⌂¼^Mgâ╗╕.î¡☼: Run and debug it Takes input as <position before> <piece type> [<other pieces>] <position after>. Unpacked: ;x\EE-c:+"=+-"@s|aaE=s,h?$+Ydx]+MEsxh|I@|oc%vcaHX-xn^$'-?'+?z?,b'S<*!,h$*++y+ Run and debug it Explanation: The first part ...


1

05AB1E, 41 bytes Ç`+É•wH˜OÝ•44в*s11%©è•2ĀpakΩÕðβ•₂в2ä+sè®è Try it online or verify all test cases. Explanation: Ç # Convert the (implicit) input to a list of codepoint integers ` # Pop and push the four integers separated to the stack + # Add the top two together (column+row) É ...


2

JavaScript (Node.js), 84 bytes s=>[a=~"0628"[[C,P,F,R]=Buffer(s),i=P%11%7],b=-"63682"[i]||4][C&1]+(F+R&1?45-a-b:19) Try it online! How? The color, the piece, the file and the rank characters are turned into ASCII codes which are saved into \$C\$, \$P\$, \$F\$ and \$R\$ respectively. We compute the piece index \$i=(P \bmod 11)\...


Top 50 recent answers are included