Last active
April 10, 2016 08:38
-
-
Save anthonyclays/267a991ace5c81a6696215d80c47282a to your computer and use it in GitHub Desktop.
Revenge of the pancakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<>; # 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<>;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