From: Matt S Trout Date: Sun, 10 May 2009 18:00:57 +0000 (+0100) Subject: add days remaining checker X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a51e36e5b9f3728713761343b7a6b078e5cc7efa;p=engit%2FIron-Munger.git add days remaining checker --- diff --git a/answer.pl b/answer.pl index 6422217..2946b91 100644 --- a/answer.pl +++ b/answer.pl @@ -4,6 +4,7 @@ use autobox::DateTime::Duration; sub check_post_gap ($aperture, $days, @posts) { return @posts if @posts <= $aperture; my @next_post = splice(@posts, 0, $aperture); + return 0 if DateTime->now - $next_post[-1]->at > $days->days; my $success = $aperture; foreach my $post (@posts) { return $success if $next_post[0]->at - $post->at > $days->days; @@ -14,6 +15,11 @@ sub check_post_gap ($aperture, $days, @posts) { return $success; } +sub check_time_remaining ($aperture, $days, @posts) { + my $cand = (@posts > $aperture ? $posts[$aperture - 1] : $posts[-1]); + return $days->days - (DateTime->now - $cand->at)->in_units('days'); +} + sub successful_sequential_posts (@posts) { return max( check_post_gap(1, 10, @posts), # 10 days between posts