Skip to content

Instantly share code, notes, and snippets.

@anthonyclays
Last active April 10, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonyclays/267a991ace5c81a6696215d80c47282a to your computer and use it in GitHub Desktop.
Save anthonyclays/267a991ace5c81a6696215d80c47282a to your computer and use it in GitHub Desktop.
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