refactor to not be so damn stupid
[engit/Iron-Munger.git] / answer.pl
CommitLineData
38efa3f1 1use signatures;
2use autobox::DateTime::Duration;
67e9aef2 3
38efa3f1 4sub check_post_gap ($aperture, $days, @posts) {
5 return @posts if @posts <= $aperture;
6 my @next_post = splice(@posts, 0, $aperture);
7 my $success = $aperture;
67e9aef2 8 foreach my $post (@posts) {
38efa3f1 9 return $success if $next_post[0]->at - $post->at > $days->days;
67e9aef2 10 $success++;
11 shift(@next_post);
12 push(@next_post, $post);
13 }
14 return $success;
15}
38efa3f1 16
17sub successful_sequential_posts (@posts) {
18 return max(
19 check_post_gap(1, 10, @posts), # 10 days between posts
20 check_post_gap(3, 32, @posts), # 4 posts every 32 days
21 );
22}