DEV Community

Cover image for Oversized Pancake Flipper - Google Code Jam

Oversized Pancake Flipper - Google Code Jam

Lorenzo Mele on April 10, 2017

Google Code Jam If you're a programmer and you don't know Google Code Jam, you should definitely go and check that. It's basically a c...
Collapse
 
purcola profile image
Pablo Urcola

Wow! Nice solution. I have been thinking about it for a while and I still have two open quiestions:

  • Does it work in any case?
  • Does it find the optimal solution (minimum flips)?

The first one seems to be true (at least the cases tested) but I can't see why. I am not so sure about the second one.
Can you give me any clue about them?

Due to my background I would go for a graph search based solution. The nodes of the graph are the state of the row of pancakes and the neighbors of a node are those states reachable by a flip action.
It is not the fastest one, but it is exhaustive and the solution is optimal.

Collapse
 
greenkey profile image
Lorenzo Mele
  • Does it work in any case?

I cannot show you the mathematical explanation but I have some hints.
Let's take the example of the post but reversed:

-++-+---
***
+---+---
 ***
+++++---
     ***
++++++++
Enter fullscreen mode Exit fullscreen mode

These are exactly the same flips made above.

I think the key point here is that you should never touch happy pancakes, unless forced to do so because of a nearest unhappy one.

Collapse
 
aammfe profile image
Abdul Hanan

This is not fair !!
I was trying to solve it with other ways.
solution is so simple that its raising Questions..?

does its a complete solution ?

  • theoretically I can see its not optimal in finding of minimum flips
  • theoretically with complex and long input(where cursor should move backward as well) its incomplete solution !
Collapse
 
ozadari profile image
ozadari

Huh, I can't believe the solution is so simple in the end!
I tried to solve it using XOR and discrete mathematics :(
Thanks for the post!

BTW you got a typo ("at the and")

Collapse
 
greenkey profile image
Lorenzo Mele

Yes, that was my thought too!

(thanks for the typo ;) )

Collapse
 
wingliu0 profile image
wingliu

How many rounds do I need to pass if i want to have a job in google🤔

Collapse
 
greenkey profile image
Lorenzo Mele

I don't know... I think you should be notable (anything that means) :)