From: Matt S Trout Date: Sun, 10 May 2009 17:21:36 +0000 (+0100) Subject: refactor to not be so damn stupid X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38efa3f1fb080dde5909303abba558b914eafa81;p=engit%2FIron-Munger.git refactor to not be so damn stupid --- diff --git a/answer.pl b/answer.pl index 2173821..6422217 100644 --- a/answer.pl +++ b/answer.pl @@ -1,24 +1,22 @@ +use signatures; +use autobox::DateTime::Duration; -sub check_post_gap (@posts) { - my $next_post = shift(@posts); - my $success = 1; +sub check_post_gap ($aperture, $days, @posts) { + return @posts if @posts <= $aperture; + my @next_post = splice(@posts, 0, $aperture); + my $success = $aperture; foreach my $post (@posts) { - return $success if $next_post->at - $post->at > 7->days; - $success++; - $next_post = $post; - } - return $success; -} - -sub check_posts_rolling (@posts) { - return @posts if @posts <= 3; - my @next_post = splice(@posts, 0, 3); - my $success = 3; - foreach my $post (@posts) { - return $success if $next_post[0]->at - $post->at > 30->days; + return $success if $next_post[0]->at - $post->at > $days->days; $success++; shift(@next_post); push(@next_post, $post); } return $success; } + +sub successful_sequential_posts (@posts) { + return max( + check_post_gap(1, 10, @posts), # 10 days between posts + check_post_gap(3, 32, @posts), # 4 posts every 32 days + ); +}