Created
August 8, 2019 09:06
-
-
Save jadiunr/a7181897fe2f0abddf572d60ca164e41 to your computer and use it in GitHub Desktop.
BLYAT
This file contains hidden or 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
use strict; | |
use warnings; | |
use feature 'say'; | |
use Data::Dumper; | |
my $S = <>; chomp($S); | |
my $out = []; | |
for my $S_group ($S =~ /(R+L+)/g) { | |
my $r_children = 0; | |
my $l_children = 0; | |
my $r_count = () = $S_group =~ /R/g; | |
my $l_count = () = $S_group =~ /L/g; | |
if ($r_count % 2 == 0) { | |
$r_children += $r_count / 2; | |
$l_children += $r_count / 2; | |
} else { | |
$r_children += $r_count - int($r_count / 2); | |
$l_children += int($r_count / 2); | |
} | |
if ($l_count % 2 == 0) { | |
$r_children += $l_count / 2; | |
$l_children += $l_count / 2; | |
} else { | |
$r_children += int($l_count / 2); | |
$l_children += $l_count - int($l_count / 2); | |
} | |
for (1..$r_count) { | |
if ($_ == $r_count) { | |
push(@$out, $r_children); | |
} else { | |
push(@$out, 0); | |
} | |
} | |
for (1..$l_count) { | |
if ($_ == 1) { | |
push(@$out, $l_children); | |
} else { | |
push(@$out, 0); | |
} | |
} | |
} | |
say "@$out"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment