Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Friday January 28, 2005
01:06 PM

Triangles Challenge

[ #22933 ]

I didn't see a Perl solution in the Triangles Challenge. Everyone there seems to love Lisp.

Can anyone defend Perl's honor?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 30 minutes, 37 lines :-)

    Unfortunately, I now realized the contest is over, so I don't think I can submit my Perl solution... :-\
    • #!/usr/bin/perl
      use warnings;
      use strict;
      use Math::Combinatorics;

      my %points = (
              0 => [ 0 .. 10 ],
              1 => [ 0 .. 10 ],
              2 => [ 4, 6, 1, 3, 5, 0 ],
              3 => [ 5, 2, 1, 7, 9, 0 ],
              4 => [ 6, 2, 0, 7, 8, 1 ],
              5 => [ 0, 8, 10, 2, 1 ],
              6 => [ 10, 9, 1, 4, 2, 0 ],
              7 => [ 8,
      • Good job. It passes the second test shown on the page too.

        #!/usr/bin/perl
        use warnings;
        use strict;
        use Math::Combinatorics;

        # I removed the points 0, 2, 4, 6 and the line from 0 6
        # Resulting in the second example which has 15 triangles

        my %points = (
                0 => [ 0, 1, 3, 5, 7 .. 10 ],
                1 => [ 0, 1, 3, 5, 7 .. 10 ],
                3 => [ 5, 1, 7, 9, 0 ],
                5 => [ 0, 8, 10, 1 ],
                7 =>