The first thing I noticed about your post was the statement:
This node compares approaches in the range ( O(N) .. O(N2) ).
and I thought WTF? It's a statement that doesn't make sense.

You do not seem to realize that expressing a complexity in "big-Oh" notation doesn't give you more information than an asymptotic upper bound. Stating an algorithm has an O(N2) run time complexity doesn't mean the algorithm actually grows quadratically. Searching in an unsorted array, for instance, has a run-time complexity of O(N2). It also has a run-time complexity of O(N).

So, I read your post more carefully. You're using a lot of woolly words, but it doesn't seem to be more than a logical expansion of how the FAQ tells you how to intersect arrays. Your memory requirements seem to be Ω(dN), where N is the number of people involved, and d the number of days to be considered. No naïve algorithm would use more. What I don't understand is why you need to rescan the file a second time - you do store all the names anyway.

For the amount of text and code, I'm not really impressed. Here's a program that does essentially the same (it doesn't print a bounding box). About half of the code has to do with formatting, not with actual calculations. Half of the remaining half is used for reading the data.

use 5.010; use warnings; use strict; my (@book, @people); while (<DATA>) { chomp; next if /^#/ || !/\S/; my ($name, $days) = split; my @days = split /,/, $days; foreach my $day (@days) { push @{$book[$day]}, $name; } push @people, [$name, \@days]; } foreach my $info (@people) { my ($name, $days) = @$info; my %matches; foreach my $day (@$days) { my @match = grep {$_ ne $name} @{$book[$day]} or next; $matches{$day} = \@match if @match; } show $name, $days, \%matches; } sub show { my ($name, $days, $matches) = @_; printf "%-20s %s\n", $name, join ", ", @$days; unless (%$matches) { print " Sorry! No matches.\n"; } else { foreach my $day (@$days) { foreach my $name (@{$$matches{$day} || []}) { print " $name can meet you on the $day"; given ($day) { when (/1[0-9]$/) {print "th"} when (/1$/) {print "st"} when (/2$/) {print "nd"} when (/3$/) {print "rd"} default {print "th"} } print ".\n"; } } } print "\n"; } __DATA__ # name days Al 1,2 Bob 2,13 Chuck 12,4 Dick 3,7,30 Edgar 5,7 Fred 2,23 Greg 4,5,12 Harry 6 Ian 1,20 Jack 4,23

In reply to Re: Gay Dating; or, Thrifty Set Intersections with an Accumulator by JavaFan
in thread Gay Dating; or, Thrifty Set Intersections with an Accumulator by Xiong

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.