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 ...


44

SWI-Prolog, 62 47 41 bytes X*Y:-X+Y;Y+X;X==Y. X?Y:-not(X*Y),X*Z,Y*Z. Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the ...


29

Deadfish, 18 This was actually the first language I tried before I considered infix operators. I'm posting it now for the sheer hilarity of the idea that Deadfish could be useful for something. iii ios sii For those who don't know Deadfish, i is increment, s is square and o is output, with the accumulator starting at 0 (there's also a 4th instruction d ...


27

C, 315 302 bytes t,i;double o,w,h,x,y,k,a,b,c;double g(N,S)double N,S[][2];{for(t=0;t<N;t++)k+=S[t][1];k/=N;for(i=0;i<9;i++){o=w=h=0;for(t=0;t<N;t++)x=S[t][0],y=S[t][1],a=y-k,c=k*k-2*k*y+x*x+y*y,o+=-a/sqrt(x*x+a*a),w+=x*x/pow(c,1.5),h+=3*x*x*a/pow(c,2.5);a=h/2;b=w-h*k;c=o-w*k+a*k*k;k=(-b+sqrt(b*b-4*a*c))/h;}return k;} This is far from pretty, and ...


27

PARI/GP - 24 1%1 8 2+3 PARI/GP ignores spaces between digits, so that 1 8 2, for example is treated as 182. The same could work for perl by replacing the spaces with underscores. I haven't exhausted the entire search space, so there may be better candidates. A program can be fed to gp as gp -q -f program.gp, or interactively in the repl. Output 1%1 8 2+...


25

Python REPL and many more, 22 23 6+7 *5% 6%4 Key observation: If you colour the grid like a checkerboard, the path alternates grid colours as it goes and starts and ends on the same colour. Still brute forcing for better. Trying with +*% (and even ** for languages where ^ is exponentiation) didn't turn up anything better, unfortunately. I also tried ...


21

C# - 423 375 bytes Complete C# program, accepts input via STDIN, outputs "True" or "False" to STDOUT as appropriate. I could not bare to leave that Linq in there... thankfully its removal paid off! It now keeps track of seen and visited cells in an array (given it only ever looks at a finite number of them anyway). I also re-wrote the directional code, ...


18

Python3 with numpy, scipy and matplotlib edit: I tried to keep the groups in the same relative position between events, hence the sorted_event function. New function to calculate the y position of the characters (coords). Every alive event is plotted two times now, so the characters stick together better. Added legend and removed axes label. import math ...


18

CJam, 34 31 bytes 8,q{~2*f{_@-_zF8b&,@@+8,=*}0-}/ Did this on my phone, so I'll have to put up an explanation later. Output is nonempty iff truthy. Try it online | Test suite Explanation The new code shifts the layout a little: 2 3 4 1 . 5 0/8 7 6 Even numbers correspond to string positions and odd numbers correspond to crank ...


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

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``{%;=!/ /;...


17

Wolfram Language (Mathematica), 26 25 bytes Tr[#//.x_:>#.#.Clip@x]<1& Try it online! How it works Given an adjacency matrix A, we find the fixed point of starting with B=A and then replacing B by A2B, occasionally clipping values larger than 1 to 1. The kth step of this process is equivalent up to the Clip to finding powers A2k+1, in which the (...


16

ES6, Node.js / Chrome, 989 977 931 892 889 887 bytes s=>"Bakerloo,Central,Circle,District,Hammersmith & City,Jubilee,Metropolitan,Northern,Piccadilly,Victoria,Waterloo & City".split`,`.filter((_,i)=>parseInt('7c1w0o741s3k39w22c020c080we80y3l0a8w0t3xhs2olc7g0km87w0176r8ao2e4g0q5w0eeb753mekwx1k18'.substr(" 5Kd5_9 5c4^5];`3]3 4]4^<`Y`0^5h3 9 ;&...


15

PHP, 138 133 129 bytes PHP beats Mathematica - a rare occurence. for(;$s=fgets(STDIN);$s>G?print$$a[$b]?$s<L:$s>L&&@array_intersect_key($$a,$$b):$$a[$b]=$$b[$a]=1)[,$a,$b]=explode(" ",trim($s)); prints 1 for truthy, empty string for falsy. Run with -nr or test it online. needs PHP 7.1 for the list assignment; user names are case sensitive ...


15

7 5 vertices, 14 10 edges (Graph made with this online tool and paint.) A-F are our six nodes, and J is a helper node. The three 1-nodes enforce that opposite nodes are different, while the 2-node makes sure that A, C and E can neither be all mines, nor all empty. Edit: -2 vertices thanks to CalculatorFeline and H.PWiz!


14

Mathematica, 201 bytes f@g_:=EdgeCount@g<9||!(h=g~IsomorphicGraphQ~CompleteGraph@#&)@5&&!h@{3,3}&&And@@(f@EdgeDelete[g,#]&&f@EdgeContract[g,#]&/@EdgeList@g);And@@(f@Subgraph[g,#]&/@ConnectedComponents[g=Graph[#<->#2&@@@#]])& This evaluates to an unnamed function, which takes an edge list like {{0, 3}, {...


14

Mathematica, 165 bytes ContourPlot[Cos@Tr[Boole[Norm[{x,y}-#2]<#]Pi&@@@#4],{x,0,#},{y,0,#2},PlotPoints->5!,AspectRatio->Automatic,Frame->False,ContourShading->RGBColor@@@#3,Contours->{0}]& Pure function taking four arguments: the width, the height (both integers), an ordered pair of triples of numbers between 0 and 1 (representing ...


14

Mathematica 8+, 266 bytes t=Merge[Cases[<<ExamplePages/TripPlanning.nb,_@v__~_~{_->l_}:>(#->l&/@{v}),-1],Union@@#&]; x(r=t@@Nearest[Keys@t]@StringReplace[__~~"d Lane"|"ket"->"Royal Oak"]@x;DeleteCases[ If[x<>r[[1]]//StringFreeQ@"sm",{},{"Circle"}]⋃r,"Overground"|"Docklands Light Rail"]) This solution originally had the ...


13

TI-BASIC, 20 fMin(sum(abs(iX-Ans)),X,~E99,E99 Takes input on the homescreen of your TI-83 or 84 series calculator in this form (You can type a 2: first, which would be ignored): {5.7+3.2i,8.9+8.1i}:[program name] If the houses are always less than a billion km away from the origin, E99 can be replaced with E9 for a size of 18 bytes. Were there a golfing ...


13

J, 15 2 + 1 * 3 * 2 + 3 This outputs only valid numbers, but a lot are duplicates. The unique values are 17 11 16 28 31 23 13 10 21 33 18 24 22 29 27. You can definitely do better by changing operators and the integers involved. 2+1*3*2+3 -> 17 2+1*3+3*2 -> 11 2+1*3+2*3 -> 11 2+3*2+3*1 -> 17 2*3+1*3+2 -> 16 2*2+3+1*3 -> 16 2*2+3*1+3 ->...


13

CJam, 59 bytes q_'.e=\N/{)'?=\S/>_,(%}%/(__,*{(2$z~@f=.*\m*|}/ff{1$e=>:=N} This finishes instantly for both test cases. It either prints the second name name of the question or 1 (both truthy), or 0 (falsy). Try it online in the CJam interpreter. Idea Because of the distinction between classes and members, the challenge boils down to creating a ...


13

Mathematica, 34 bytes Tr[1^#&@@FindClique[#<->#2&@@@#]]& Basically FindClique does the job and "finds a largest clique in the graph g." All the other stuff is converting input-list into graph Input [{{2, 5}, {2, 3}, {4, 17}, {1, 3}, {7, 13}, {5, 3}, {4, 3}, {4, 1}, {1, 5}, {5, 4}}] Output 4 Input [{{1296, 316}, {1650,...


12

GolfScript (53 bytes) ])~{:^1>{.-1:H)-,:T;{..H):H*T@-:T+^%!{;}*}%}{^+}if}/, Online demo I haven't actually golfed this yet, but I have discovered that it's not very easy to eliminate the H and T variables so this might be a local minimum. Takes input on stdin in the format [0 1 2 3]. Leaves output on stdout. Ungolfed: ])~{ :^1>{ # array of ...


12

Pyth, 41 35 hfqQu@+G+VM*s_BM*F_BMTGQ]hQ)maVhQdt Exits on error if there are no valid leapers, giving the empty string if STDERR is ignored. Try it here or run a Test Suite Saved 6 bytes thanks to isaacg! Basically just finds all leaper candidates by selecting each valid leaper from the first tile to each other tile. Then for each of these, it makes all ...


12

Python 2, 92 87 bytes a=lambda n:n<2or sum((k%d<1)*d*a(d)*a(n-k)for k in range(1,n)for d in range(1,1+k))/~-n In plain english: to compute a(n) we calculate d*a(d)*a(n-k) for every divisor d of every positive integer k smaller than or equal to n, sum all these, and divide by n-1. To make it run faster, run in Python 3 (replacing / with // in the ...


12

Haskell, 68 bytes t 0=[""] t 1=["0"] t n=['(':x++y++")"|k<-[1..n-1],x<-t k,y<-t$n-k-1] Terminal nodes are represented by 0, unary and binary nodes by (e) resp. (ee), so the two three-node trees are given as (00) and ((0)). Examples: *Main> t 5 ["(0(00))","(0((0)))","((0)(0))","((00)0)","(((0))0)","((0(0)))","(((0)0))","(((00)))","((((0))))"] *...


12

CMD (Batch), 50 + 20 + 135 = 205 bytes FRIEND.CMD @for %%f in (%1.%1 %1.%2 %2.%2 %2.%1)do @set %%f=1 KNOW.CMD @call echo(%%%1.%2%% Prints 1 for friends, a blank line for strangers. SUGGEST.CMD @call set k=0%%%1.%2%% @set k=1&if %k%==0 for /f "tokens=2 delims=.=" %%f in ('set %1.')do @call set k=%%k%%%%%%f.%2%% @echo(%k:~1,1% Prints 1 or a blank ...


11

Ruby, 58 55 44 characters p$*.permutation.find{|i|i*?,!~/(.),(?!\1)/i} Yet another ruby implementation. Uses also case insensitive regex (as Ventero's old solution) but the test is done differently. Previous version: p$*.permutation.find{|i|(i*?,).gsub(/(.),\1/i,"")!~/,/}


11

Ruby 2.0, 133 characters A collaboration with @Ventero. Always a good sign when it starts breaking the syntax highlighter! This is a recursive flood-fill solution. Reads from STDIN and outputs to STDOUT: f=->*a{a.product([~n=$_.to_i,-1,1,n+1]){|p,d|a|=[p]if$_[p+=d]<?.}!=a ?f[*a]:a.size} gets(p).scan(/ /){$*<<f[$`.size]} p$*.max<f[~/X/] ...


11

Ruby, 204 191 172 characters c,*r=gets.split o=[0]*8 s=->x,y,p{y>14?o[x]+=p :(r.index("#{x},#{y+=1}")?(x<1?s[x+1,y,p]:(x>6?s[x-1,y,p]:(s[x-1,y,p*0.55]+s[x+1,y,p*0.45]))):s[x,y,p])} s[4,0,1] p o[c.to_i] It recursively simulates all possibly outcomes while keeping track of each individual outcome's probability, then it adds that probability to a ...


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