31
$\begingroup$

An entry in Fortnightly Topic Challenge #35: Restricted Title 1. Inspired by the title of this xkcd comic, but in no way related or affiliated beyond the shared name.


It's a well known fact that any animal without legs finds it quite impossible to jump. In fact, such creatures can't even leave the ground to pass by another of their kind.

Below is one such pair. A duo of serpents, trapped as it were, on a flat surface. The grammatically challenged among us might even call them...

Snakes on a Plane! 2

[Cue theme music...]

Snakes on a Plane! 2

Here's a few other surprising facts about snakes:

  1. They freaking love apples. Like, it's all they eat.
    • Interestingly, whilst they don't necessarily take it in turns eating apples (they sometimes do, but often one snake will eat several apples while the other rests), they're still super fair and overall, will share available apples evenly.
  2. When a snake eats an apple, it immediately starts to grow.
    • The first apple it eats, it grows by one, the second by two, third by three, and so on.*
    • When growing, a snake's tail doesn't extend out as you might expect, instead the tail remains fixed as its head continues to move, stretching it forward.
  3. You know how when you were a kid and people told you snakes weren't slimy? They lied. In fact, they're super slippery (how do you think they move without legs?).
    • Once moving in a given direction, a snake can't stop at all unless it collides with something (a grey wall, a boundary, or another snake - apples don't stop them, and lava... well... see Fact #6).
  4. Snakes have limited energy to push themselves along.
    • They start the day with the energy to initiate movement seven times (once moving they glide smoothly without expending energy, as per Fact #3, above).
    • Eating an apple instantly gives them more energy, but with diminishing returns. The first apple gives enough energy to initiate six additional movements, the second gives five, the third four, and so on.*
  5. Snakes are surprisingly bad at physics, so rather than try to predict where and how fast other snakes are sliding (given they can't stop themselves once they've started), they simply rest whilst another snake in the same territory is moving.
    • They're very patient and don't mind waiting for each other, which means it's common to see one snake move many times across the plane, whilst the other takes a break.
  6. Snakes are allergic to lava. Don't go in the lava.

What set of movements can the two snakes on a plane make in order to eat all the apples?


Hint (15 June):

When is the best time to get the bottom right apple? How are you going to get in there? Having answered those questions, which snake is going to collect it?


Technical Details

*Here's a table providing the exact results of eating each apple (applied independently to each snake):

Apple No.        0  1  2  3  4  5  6
Snake Length     5  6  8 11 15 20 26
Movement Energy  7 +6 +5 +4 +3 +2 +1

Edit (5 June): I've updated the facts above a couple of times to improve clarity, but to boil it down completely without flavour, the rules are as follows:

  • Each snake is independent and has its own separate energy/length/movements/apples
  • A solution attempt succeeds the instant both snakes have eaten six apples, and fails if either snake runs out of energy or gets trapped without having eaten six apples, or if either touches lava
  • Movement
    • Only one snake moves at a time, but they don't have to take turns (i.e. one can move many times while the other remains still)
    • When a snake starts moving, it continues in a straight line, square by square, whilst the square in front does not contain: a snake, a grey block, or the boundary of the grid
    • Snakes can only initiate a limited number of moves, but any given move uses exactly one energy regardless of length
    • Each apple provides energy for additional movements (gained the instant they enter the square), as per the table above
  • Growth
    • When a snake eats an apple it begins growing immediately to the length given in the table above
    • Growth occurs incrementally from the head as it moves out the apple's square, with the tail remaining in place until the new length is reached
    • Growth can span several movements if the snake is blocked mid-growth
    • Multiple growths can compound if an additional apple is eaten before the first growth spurt has completed
$\endgroup$
15
  • 3
    $\begingroup$ Yes, I know this is a name clash, but I was 90% done when Sleafar posted his version and didn't want to throw this one away (plus title dupes are specifically allowed, as per the challenge rules). $\endgroup$
    – Alconja
    Jun 4, 2018 at 6:44
  • 4
    $\begingroup$ Snakes on a Plane! 2 2! $\endgroup$
    – noedne
    Jun 4, 2018 at 6:48
  • 4
    $\begingroup$ @noedne - the sequel sequel literally no one was clamoring for! So good it gets two exclamation points! (Actual note: the "!!" in the title is only there because PSE wouldn't allow the exact name dupe, and can be ignored) $\endgroup$
    – Alconja
    Jun 4, 2018 at 6:51
  • 3
    $\begingroup$ @noedne - I think it's probably better to just leave it. Dodgy character tricks can break things like search/hnq/mobile rendering/etc. $\endgroup$
    – Alconja
    Jun 4, 2018 at 6:58
  • 2
    $\begingroup$ RE your first sentence: have you ever put a fish on the ground? No legs; plenty of jumping. $\endgroup$ Jun 4, 2018 at 20:55

3 Answers 3

18
+100
$\begingroup$

After eating about 1000 apples, I finally found a solution.

I used Ahmeds online tool to solve this puzzle.

step1 step2 step3 step4 step5 step6 step7 step8 step9 step10 step11 step12 step13 step14 step15 step16

$\endgroup$
1
  • $\begingroup$ Very nicely done! Especially considering this is (IMO) a more complicated solution than my own (though it's unsurprising there's more than one solution). I've posted my originally intended path/logic below in case you're curious. $\endgroup$
    – Alconja
    Jun 18, 2018 at 5:13
25
+100
$\begingroup$

This is not an answer, however it could be helpful to try the puzzle online:

https://www.openprocessing.org/sketch/558659

Edit:

I feel like I don't deserve the bounty, but it is much appreciated. Thanks a lot.

$\endgroup$
3
  • 1
    $\begingroup$ That's awesome. Any way you can get it to print out a list of moves as you do them? I managed to get blue to 6 apples in a good position but i didn't track how. :( $\endgroup$
    – Bobson
    Jun 5, 2018 at 15:22
  • 5
    $\begingroup$ Awesome, this now appears to follow all rules correctly and is definitely solvable (I've deleted my previous, obsolete comment). Though I note you didn't include any fireworks on successful completion. :P $\endgroup$
    – Alconja
    Jun 6, 2018 at 6:28
  • 2
    $\begingroup$ Lovely work. I love processing :c) Haven't used it in quite some time though.... Maybe I should pick it up again. $\endgroup$
    – BmyGuest
    Jun 8, 2018 at 20:44
5
$\begingroup$

Original/alternate solution from OP

This is an alternate solution to the accepted answer above. It represents the "original" solution as designed by the OP, with some of the logic and educated guessing I had intended solvers to take.


Initially, it can be deduced that:

The top right apple can't be collected without trapping the snake, so it must be the end point for one snake. The neighbouring apple in the top right, however can be collected early if necessary. The bottom right apple must be collected early (1st or 2nd apple for a given snake), unless it is another terminal.

From here on, we can't make any completely concrete deductions, but we can make some pretty reasonable assumptions...

The most probable way to enter the bottom right region is to hit the central-right block from the right hand side (collecting the apple at the same time), then head down. Therefore the snake to do this must have collected no other apples prior (lest the get stuck in the bottom region), meaning the blue snake has to get it (the green snake will almost certainly collect an apple on its first move).

So, how do we get the blue snake into that position?

Obviously there's multiple ways to do it (eg. see Sleafar's solution), but either way, it relies on the realisation that you need to position the green snake to be running horizontally either above or below the target block, to create a wall for the blue snake to pivot off.
step 1
step 2

From here the next few steps are fairly obvious, given that there's not a huge number of possible ways forward.

step 3

From here, my solution is simpler to deduce than Sleafar's because the green snake is longer and most of the apples are contained in the centre region. So, targeting apples aggressively:

step 4
step 5

By now it's pretty clear where blue is going, and green still needs two more apples, so we just need to find a way to leverage blue's position and close things out:

step 6
fin

$\endgroup$

Your Answer

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

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