Fun puzzle. Here is my kind of hybrid answer. 4 nested loops + some regex to weed out straight lines.

use strict; use warnings; my $data = { A => [qw/B C D E F I G J/], B => [qw/A C D E F H J I/], C => [qw/A B F I D E/], D => [qw/A C B G J E/], E => [qw/A D C B G H I J/], F => [qw/A C B I H J/], G => [qw/D A E H I J/], H => [qw/F B I J G E/], I => [qw/B F C A H G E J/], J => [qw/A B F H I E/], }; my $line = qr/[ACFI]{3}|[ADGJ]{3}|[BCDE]{3}|[BFHJ]{3}|[EGHI]{3}/; my $triangles = {}; for my $p1 (keys %$data) { for my $p2 (@{$data->{$p1}}) { for my $p3 (@{$data->{$p2}}) { next if $p3 eq $p1; for my $p4 (@{$data->{$p3}}) { if ($p4 eq $p1) { my $tri = join( "", sort @{[$p1,$p2, $p3]}); $triangles->{$tri}++ unless $tri =~ $line; } } } } } print $_,"\n" for sort keys %$triangles; print 0+keys %$triangles;


___________
Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;

In reply to Re: How many triangles does your perl script "see"? by eric256
in thread How many triangles does your perl script "see"? by Skeeve

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.