#!/usr/bin/env perl

use strict;

#
#  timezone => number of people
#
my %tz = (
    10 => 1,
     6 => 1,
     1 => 3,
     0 => 2,
    -5 => 7,
    -8 => 18,
);

my @tz = sort { $a <=> $b } keys %tz;

#
#  hour => weighting
#
my %hour = (
    0  => 0,
    1  => 0,
    2  => 0, 
    3  => 0,
    4  => 0,
    5  => 0,
    6  => 2,
    7  => 3,

    8  => 8,
    9  => 9, 
    10 => 9,
    11 => 9,
    12 => 8,
    13 => 9,
    14 => 9,
    15 => 9,
    16 => 9,
    17 => 9,

    18 => 4,
    19 => 2,
    20 => 2,
    21 => 2,
    22 => 1,
    23 => 1,
);


sub round_hour
{
    my ($hour, $tz) = @_;
    return (24 + $hour + $tz) % 24;
}



sub score_hour
{
    my ($hour, $tz) = @_;
    $hour = round_hour($hour, $tz);
    return $hour{$hour};
}


my @results;


    #
    #  value each hour for a TimeZone
    #
    for (my $hour = 0; $hour < 24; $hour++)
    {
	my $result;
	$result->{hour} = sprintf "%02d:00", $hour;

	foreach my $tz (keys %tz)
	{
	    my $score = score_hour($hour, $tz) * $tz{$tz};
	    $result->{total} += $score;
	    $result->{score}{$tz} = $score;
	}

	push @results, $result;
    }


    #
    #  table of results ..
    #
    foreach my $tz (@tz)
    {
	printf "%5d ", $tz;
    }

    print "\n";

    foreach my $result (sort { $b->{total} <=> $a->{total} } @results)
    {
    	my $hour = $result->{hour};

	foreach my $tz (@tz)
	{
	    printf "%02d:00 ", round_hour($hour, $tz);
	}

	print $result->{total} . "\n";
    }
