3
\$\begingroup\$

Related, both rope, nail and falling, but reversed and some other differences

Consider a loop of rope hanging on n nails on a row. Given a table showing whether the rope would fall down when each possible set of nails were removed, please provide a possible roping way. You may assume such a solution exist.

Here, "fall down" means the rope can be moved far away from the nails. That means, we treat a rope just placing on nails as "fall down".

We express a roping way as the space where the rope go up/down the line where nails are placed, left-most space as space 0 and right-most space as space n.

Sample input:

(whether removed or not)
Nail1 Nail2 Nail3 Nail4 Fall
  0     0     0     0     0
  0     0     0     1     0
  0     0     1     0     0
  0     0     1     1     0
  0     1     0     0     0
  0     1     0     1     0
  0     1     1     0     0
  0     1     1     1     0
  1     0     0     0     0
  1     0     0     1     0
  1     0     1     0     0
  1     0     1     1     1
  1     1     0     0     0
  1     1     0     1     0
  1     1     1     0     0
  1     1     1     1     1

Sample output

0 1 2 4

Explanation

In this case, if we draw a horizontal line through the nails, it intersects the rope at position 0, 1, 2, 4 in the order of the rope. Note that because the loop is closed, if you use this output format then the length of the output is always even.

Sample input:

(whether removed or not)
Nail1 Nail2 Fall
  0     0    0
  0     1    1
  1     0    1
  1     1    1

Sample output

1 2 0 1 2 0

Explanation

The way to input is quite free. You can input as function, map, array with removed nail set in fixed order, or other reasonable method. Inverting either or both nail logic and fall logic are also allowed. Output should be array-like, so string separated by some char is also allowed.

Code golf, shortest code win. Optimizing the length of the output but weaker in code length won't be accepted, but may be upvoted.

\$\endgroup\$
  • 2
    \$\begingroup\$ @NathanMerrill That challenge is quite different from this one. That challenge asks whether the roping done will cause the picture to fall, this challenge asks for a roping given all removals of nails which will cause the picture to fall. The challenge you linked mentions nothing of removing nails. \$\endgroup\$ – musicman523 Apr 27 '18 at 5:49
  • 1
    \$\begingroup\$ Are the nails always in a row? Also some explanation of the output format would be nice, it took me some while to get that the numbers describe the space between nails. \$\endgroup\$ – Laikoni Apr 27 '18 at 6:24
  • 8
    \$\begingroup\$ The point of the sandbox is to get feedback on the question in the form in which you will post it. If you make major changes then you should edit the sandbox answer. \$\endgroup\$ – Peter Taylor Apr 27 '18 at 7:23
  • 2
    \$\begingroup\$ @DeadPossum It turns into a rope placing on the left of the first nail \$\endgroup\$ – l4m2 Apr 27 '18 at 16:30
  • 1
    \$\begingroup\$ @DeadPossum When you remove the nail the remaining nail is entirely outside of the closed loop. I implore you to actually attempt is either on paper or on string. You will see that it most definitely does fall. \$\endgroup\$ – Wheat Wizard Apr 27 '18 at 16:49

Your Answer

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

Browse other questions tagged or ask your own question.