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


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

Test Cases

Guul Draz


Bala Ged



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

TI-BASIC, 84 82 bytes

Prompt Str1,Str2,X

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.

  • \$\begingroup\$ How can "GSMAOBT"allow you to establish which locations are directly connected to which? \$\endgroup\$ – DavidC Sep 28 '15 at 17:40
  • \$\begingroup\$ @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. \$\endgroup\$ – lirtosiast Sep 28 '15 at 17:58
  • \$\begingroup\$ Clever idea! Congrats. \$\endgroup\$ – DavidC Sep 28 '15 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.


Ruby 113/112

More bytes than TI Basic, but less characters.

p gets.to_i>(a[0]-a[1]).abs+v

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.