My daughter had the following assignment for her math homework. Imagine six friends living on a line, named E, F, G, H, J and K. Their positions on the line are as indicated (not to scale) below:
Thus, F lives five units from E, and two units from G, and so forth.
Your assignment: craft a program that identifies a path that visits each friend exactly once with a total length of n units, taking the locations of the friends and n as inputs. It should report the path if it finds it (for example, for length 17 it might report "E,F,G,H,J,K", and it should exit gracefully if no solution exists. For what it's worth, I completed an ungolfed solution in Mathematica in 271 bytes. I suspect it's possible much more concisely than that.
[0, 5, 7, 13, 16, 17]
and62
) so that you can make sure it's not specifically hard-coded to this case. \$\endgroup\$"[0, 5, 7, 13, 16, 17], 62"
and an output"(7, 16, 0, 17, 5, 13)"
ok? \$\endgroup\$