Once upon a time I wanted to order custom tokens for a board game. They say they can do it, and then they present me their price list. I was confused because they charge per inch of head movement, and I have no idea how much will my tokens cost.

INPUT: a 2d grid:

  • |,-,\,/ are straight cuts. Each has a length of 1.
  • ,,, are 90 degree corner cuts. Each has length of 1.\$^1\$
  • #,@ are 45 and 135 degree corner cuts respectively. Each has a length of 1.20.
  • +,X are perpendicularly intersecting cuts. Each has a length of 1.
  • >,v,<,^ are the cut ends. Each has a length of:
    • 1.50, if the arrow points at the diagonal cut,
    • 1, if the arrow points at the beginning of next cut,
    • 0.50 otherwise.
  • ABC...UVWYZabc...xyz are the cut start points given in that order. They have a length of:
    • 0.50, if no other already made cuts are neighboring them,
    • 1.50, if if the cut begins next to the diagonal cut,
    • 1 otherwise.

OUTPUT: Distance that a head will move with up to 2 significant digits.

Assume that:

  • The company doesn't count distance from resting position to starting point of the first cut,
  • Each cut is made only once (intersections cut twice on the same character),
  • All grids are valid,
  • The head moves from the end of a cut to the beginning of another cut in a straight line.

Obviously no standard loopholes, and the shortest code in each language wins!


Output: 0

A> B>

Output: 4


Output: 16


Output: 7.5


Output: 11.4 (Note: First the head cuts bottom-left triangle, then moves its head to the beginning of top-right triangle cut. 45 degree corners take continuations first instead of new cuts.)

^  \  |

Output: 21.15

A-┐ ┌--┐ ┌-┐ ┌--┐ C-┐ ┌--┐ ┌-┐ ┌--┐
^ | |  | | | |  | ^ | |  | | | |  |
└-+-+--┘ └-+-+--┘ └-+-+--┘ └-+-+--┘
  | |      B |      | |      D |   
  └-┘      ^-┘      └-┘      ^-┘   

Output: 138.41

 X \
@ @-#

Output: 13.5

A> F> K> P> U> a>
B> G> L> Q> V> b>
C> H> M> R> W> c>
D> I> N> S> Y> d>
E> J> O> T> Z> e┐

Output: 104.29

\$^1\$ If needed, replace this with a set of your choice.

  • \$\begingroup\$ Can we use swap the 4 90 degree cut symbols for ASCII symbols (e.g. use 1,2,3,4) instead? \$\endgroup\$
    – Veskah
    Commented Dec 9, 2019 at 13:13
  • 2
    \$\begingroup\$ You should explain what you mean by "next to a diagonal cut". I thought it'd mean adjacent to # or @ (since 45° and 135° lines are diagonals), but this doesn't fit with the test cases. \$\endgroup\$
    – Grimmy
    Commented Dec 9, 2019 at 15:43
  • 1
    \$\begingroup\$ The output is defined as the distance that the head moves, but there's almost no explanation of how the head moves. Each character is associated with a "value"; are those actually distances? "The head moves from the end of the first cut to the beginning of the second cut in a straight line"; is that specific to the first cut, or true for all pairs of consecutive cuts? \$\endgroup\$
    – Grimmy
    Commented Dec 9, 2019 at 17:00


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.