# Can I Choose Not to Fly?

Inspired by a chat conversation I lurked.

I am an adventurer on the far away land of Zendikar. I truly enjoy traveling the land. Bushwhacking, weathering the roil and encountering strange and exotic flora and fauna are the highlights of any good adventure. Unfortunately, my duties as an adventurer do not always allow me to stop and smell the lotuses. Occasionally I am crunched for time and must hop on my kitesail and fly to my destination. I just glide over the land without being able to enjoy it.

# The Challenge

Write a program that will let me know if I can choose not to fly. The program will take three inputs: my current location, my destination, and the maximum permitted travel time in days. Using the information below, determine if my travel time on foot is less than my maximum allowed travel time. If it is and I can travel on foot, return a truthy value. If the land travel time is as long as or longer than the maximum time, return a falsey value.

Guul Draz is two days away from Sejiri, its only neighboring territory.

Sejiri is one day away from Murasa and two days from Guul Draz.

Murasa is one day from Bala Ged, one day from Akoum, two days from Tazeem, and one day from Sejiri.

Bala Ged is two days from Akoum and one day from Murasa.

Akoum is one day from Ondu, one day from Murasa and two days from Bala Ged.

Ondu is one day from Akoum, its only neighboring territory.

Tazeem is two days from Murasa, its only neighboring territory.

Every location is connected, but not always directly. For example, going from Tazeem to anywhere requires you to travel to Murasa first. There are no real branches in the path either. Protip: Only go to Bala Ged if it is one of your endpoints. Here is a rough map if you're lost:

                        Bala Ged --
|       \
Guul Draz ---- Sejiri -- Murasa -- Akoum -- Ondu
|
|
Tazeem


# Scoring

This is code golf, so shortest program wins. Standard loopholes apply.

# Test Cases

Guul Draz
Ondu
5

False

Bala Ged
Akoum
3

True

Tazeem
Sejiri
1

False

• Wait, I actually won this one? Someone who knows an actual golfing language could win in like 20 bytes. Oct 7, 2015 at 20:18
• @ThomasKwa Well it's been a while and nobody's done it. If a shorter one comes along I'll change the accepted answer. Oct 7, 2015 at 20:24

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

• How can "GSMAOBT"allow you to establish which locations are directly connected to which? Sep 28, 2015 at 17:40
• @DavidCarraher The travel time happens to be equal to the Manhattan distance between some positions I assign them. So Guul Draz can be at (-3,0), Sejiri at (-1,0) and so on. Sep 28, 2015 at 17:58
• Clever idea! Congrats. Sep 28, 2015 at 18:31

# 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


# Ruby 113/112

More bytes than TI Basic, but less characters.

v=0
a=(0..1).map{c=gets[0];(d="BT".index(c))&&v+=1+d;"GGSMAO".index(c.tr('BT',?M))}
p gets.to_i>(a[0]-a[1]).abs+v

v=0
a=(0..1).map{c=gets[0];(d="BT".index(c))&&v+=1+d;"OAMSSGGGBBBBBBT".index(c)%6}
p gets.to_i>(a[0]-a[1]).abs+v


Two slightly different solutions, on the same principle:

There's no point in considering the direct route between Bala Ged and Akoum, because the route via Murasa is the same length.

The main left-right string of places can be considered by taking the indices in a string and finding the difference between them.

For B and T, we need to add an extra 1 or 2. This is held in the variable v. The two versions differ in the way that B and T are made to give the same index in the main string as M. In the first, it's done by replacement B or T --> M in the input. In the second it's done by modulo (I prefer the first one, but the second one's a byte shorter.)

# 05AB1E, 44 bytes

"GSMAOBT"D2FsIнk])εyy0Qi¼ëy4›i2¼y5-½]α¾+³-d


Try it online!

A little too long to be proud of

"GSMAOBT"   push the first letters of each city
D           duplicate this
2F          do 2 times:
s           swap the two previous stack entries
I           get next input
н           get the first letter of that
k           push the index of that letter in "GSMAOBT"
]
)           push both indexes in a list

ε           for each entry of that list
y           push the current value for that entry
y0Qi        if current entry == 0 (Guul Draz)
¼           increment counter (will be added to the distance in the end)
ë           else
y4›i        if current entry > 4 (Bala Ged or Tazeem)
2           set current list entry = 2 (Murasa)
¼           increment counter
y5-½        if entry = 4 (Tazeem), increment counter another time
]
push both indexes on the stack separated
α           get absolute difference of them
¾+          add the counter variable to that
³-d         check, if it's equal or smaller than the maximum time