#!/usr/bin/env raku

unit sub MAIN (:v(:$verbose));

constant $DAY-AS-MINUTES = 24 * 60; # 1440

my $s     = 0;
my $e     = 0;
my $max   = 0;
my $count = 0;

for 0 .. $DAY-AS-MINUTES -1 -> $start
{
  next unless $start.is-prime;

  for $start + 1 .. $DAY-AS-MINUTES -> $end
  {
    next unless $end.is-prime;

    my $length = $end - $start;

    next unless $length.is-prime;

    my $new-max = $length > $max;
    
    say ": Prime time #{ ++$count }: $start ({ hhmm($start) }) - $end ({ hhmm($end) }) = $length min ({ hhmm($length) }) { $new-max ?? "-> new max" !! "" }" if $verbose;

    if $new-max
    {
      $s   = $start;
      $e   = $end;
      $max = $length;
    }
  }
}

say $max
  ?? "$s ({ hhmm($s) }) - $e ({ hhmm($e) }) = $max min ({ hhmm($max) })"
  !! "0";

sub hhmm($min)
{
  my ($m, $h) = $min.polymod(60);
  return sprintf("%02d:%02d", $h, $m);
}
