26
\$\begingroup\$

Today's Google doodle is about Celebrating 50 years of Kids Coding: The goal is program the path of a little bunny so that it can eat all the carrots. There are 4 types of blocks (see pictures below):

block description

From left to right:

  • O("...", k) = orange piece: these are for loops which executes k times the program "...".
  • G = green piece: go one step forward if you can, otherwise do nothing
  • Bl = blue piece: turn right and stay on the same block
  • Br = blue piece: turn left and stay on the same block

big program

The code above can be written as

O(O(G G Br, 4) Bl Bl, 23)

Each block (G, Bl, Br, O(...,k)) counts as 1 unit, so this program is of length 7. Note than the value of k is included inside the 1 unit of O.

There are 6 levels. To finish a level you need to eat all the carrots. It is not a problem if your program is not fully executed, the level finishes directly when you eat the last carrot.

We assume that all the 4 types of blocks are available in every level.

Your task is to find a single program which solves every level of the game.
Shortest program in blocks wins.

Screen shots of each level:
Level 1: level 1 screenshot
Level 2: level 2 screenshot
Level 3: level 3 screenshot
Level 4: level 4 screenshot
Level 5: level 5 screenshot
Level 6: level 6 screenshot

\$\endgroup\$
24
\$\begingroup\$

Not my answer

6 blocks

The user Alex found a shorter solution, of length 6. I can confirm that their solution works:

O(O(Br G G, 6) Br, 5)

6 blocks

They attempted to edit this question to add this answer, so I'm assuming they want it to be displayed here. I don't like how the reputation system works around here.

The message they left:

The editor doesn't have 10 rep, but does have a solution of length 6. O(O(RGG,6)R,5)

After a few days they responded again via editing the post with: "Thanks for doing this. Editing this was the only way I saw to get a message. I am happy it exists at all. Feel free to bring it into a new post if you want though."

Old answer

7 Blocks

O(O(G G Br, 4) G Br, 100)

Patience required.

Edit: The image was wrong. 7 blocks

\$\endgroup\$
  • \$\begingroup\$ Good find! I did try this approach but didn't happen on this particular combination before giving up and going for my 9 block solution. \$\endgroup\$ – Sparr Dec 10 '17 at 2:04
  • 2
    \$\begingroup\$ The user Alex claims to have found a shorter solution. \$\endgroup\$ – Jonathan Frech May 3 at 20:06
  • \$\begingroup\$ @JonathanFrech indeed he has! That 10-rep limit is annoying. I get that we have to prevent spam, but shouldn't new users have at least a moderated way of posting answers? Freedom of speech and stuff. \$\endgroup\$ – R.M May 4 at 10:38
  • \$\begingroup\$ @R.M I was also a bit irritated upon seeing the problem. I guess SE simply is not designed for one-off answers, as frustrating this probably is for Alex ... \$\endgroup\$ – Jonathan Frech May 4 at 13:07
  • 1
    \$\begingroup\$ Why did you edit this into your own old answer instead of posting it as a new answer? \$\endgroup\$ – Sparr May 5 at 18:54
12
\$\begingroup\$

Actually, I found a solution with 8 blocks

O(O(O(G,4)R,4)GGR,4)
\$\endgroup\$
6
\$\begingroup\$

Manually found, 9 blocks

O(O(GRGLGR,4)L,4)

I started with the obvious O(O(GGR,4)L,4) that solves levels 1-5 then tried a few variations adding effectively-null moves on those levels to find one that would complete level 6. The shortest was a simple right-forward-left in the middle of each "bridge" so the forward move had no effect.

\$\endgroup\$
  • 1
    \$\begingroup\$ This is probably optimal which means the challenge is already over. :( \$\endgroup\$ – totallyhuman Dec 6 '17 at 0:43
  • 6
    \$\begingroup\$ @totallyhuman turns out the community's not quite done with this yet :P \$\endgroup\$ – HyperNeutrino Dec 6 '17 at 3:31
  • \$\begingroup\$ "The obvious O(O(GGR,4)L,4)" disproves that the shortest solution for level 4 is 7, as shown in the game. \$\endgroup\$ – mik Dec 6 '17 at 11:00
  • 1
    \$\begingroup\$ @mik The game solutions don't rely on changing the loop size or moves that do nothing. \$\endgroup\$ – Neil Dec 6 '17 at 15:53
  • \$\begingroup\$ @totallyhuman you're forecasting was quite wrong :). Even more than a year after the question was posted, a better solution was found. \$\endgroup\$ – Surb May 5 at 13:02

protected by Community Dec 6 '17 at 3:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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