Skip to content

Instantly share code, notes, and snippets.

/main.p6 Secret

Created January 9, 2017 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/940e1d578e30609ca091550e948ab435 to your computer and use it in GitHub Desktop.
Save anonymous/940e1d578e30609ca091550e948ab435 to your computer and use it in GitHub Desktop.
my @lines = 'input.txt'.IO.lines;
my @stack;
for @lines -> $line {
for $line.comb.kv -> $i, $v {
if $v eq '(' {
@stack.push(($i, $v));
} elsif $v eq ')'{
if @stack.elems > 0 {
if @stack[*-1][1] eq '(' {
@stack.pop();
} else {
@stack.push(($i, $v));
}
} else {
say "wrong ($i, $v)";
}
}
}
}
say "@stack\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment