#!/usr/bin/perl open(FIL,"prob42data.txt"); $l = ; close(FIL); $l =~ s/\"//g; @w = split(',',$l); print $#w . " total words\n"; $lw = 0; for ($i = 0; $i <= $#w; $i++) { $ws = 0; for ($j = 0; $j < length($w[$i]); $j++) { $ws += (ord(substr($w[$i],$j,1)) - ord('A')) + 1; } if ($ws > $lw) { $lw = $ws; } } print "Highest possible triangle value: $lw\n"; $i = 1; $q = 1; $n = ";"; while ($q < $lw) { $q = .5 * $i * ($i + 1); $n .= "$q;"; $i++; } $wordcount = 0; for ($i = 0; $i <= $#w; $i++) { $ws = 0; for ($j = 0; $j < length($w[$i]); $j++) { $ws += (ord(substr($w[$i],$j,1)) - ord('A')) + 1; } if ($n =~ /\;$ws\;/) { $wordcount++; } } print "Total triangle words: $wordcount\n";