Not that complicated, really, although it does seem a bit silly to do trigonometry where simple arithmetic would suffice.

#! /usr/bin/perl -wl my @times = qw( 17:00 19:00 11:00 13:00 23:00 01:00 10:30 13:00 19:40 01:20 16:00 02:00 ); # keep angles in range -pi .. pi sub _PI () { 2 * atan2(1, 0) } sub _TC () { 24 * 60 / (2 * _PI) } sub time2angle { map { my ($h, $m) = split /:/; _PI - (60 * $h + $m) / _TC } @_ } sub angle2time { map { my $m = int _TC * (_PI - $_); sprintf "%02d:%02d", $m / 60, $m % 60 } @_ } use List::Util qw( sum ); sub circ_avg { atan2 sum(map sin, @_), sum(map cos, @_) } for (; @times > 1; shift @times) { my @t = @times[0, 1]; print "@t => @{[angle2time circ_avg time2angle @t]}"; }

Thank you for the wikipedia link.


In reply to Re^2: Average start time handling midnight by oiskuu
in thread Average start time handling midnight by chrisjej

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.