Can I Choose Not to Fly?

TI-BASIC, 84 82 bytes

Prompt Str1,Str2,X
"GSMAOBT->Str3
{-3,-1,0,1,2,i,-2i
Ans(inString(Str3,sub(Str1,1,1))-Ans(inString(Str3,sub(Str2,1,1
X>real(Ans-iAns

I store the positions of each city on the complex plane, then calculate the Manhattan distance. Bala Ged is at 0+1i, Guul Draz is at -3+0i, and so on.

There would be a 75-ish byte solution if quotes could be in strings, but one of TI-BASIC's limitations prevents that.


Mathematica 153

This checks whether the required time to travel (the GraphDistance in Edgeweights, i.e. days), is less than or equal to the available time to travel, also in days. This sort of approach should work with much larger graphs, corresponding to a great many locations and connections.

s=StringTake;g=Graph[UndirectedEdge@@@Partition[Characters@"GSSMMBMAMTBAAO",2], 
EdgeWeight->{2,1,1,1,2,1,1}]
f[a_,b_,n_]:=GraphDistance[g,a~s~1,b~s~1]<=n

Tags:

Code Golf