Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Revenge of the pancakes
<>; # ignore first line of input
foreach(<>) {
chomp; # get rid of the newline
$t++; # increment case number (implicitly initialized to zero)
s/([+-])\1+/\1/g; # simplify stack of pancakes: consecutive similarly-facing pancakes are squashed together
s/\+$//; # if the last pancake is already facing the correct way: ignore it
$l=length; # get the height of the stack
print"Case #$t: $l\n" # print it
<>;while(<>){$t++;s/([+-])\1+/\1/g;s/\+?\n//;$l=length;print"Case #$t: $l\n"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment