This works well if may not be efficient. It finds the first entry of largest block.#!/usr/local/bin/perl -w use strict; my $string = 'abbbcddddfegrgrgddeeeeedd'; my @chars = split //,$string; my $hold = ''; my $currentSequence = ''; my $longestSeq = ''; my $currentPosition = 0; my $longestSequenceStartPosition; foreach (@chars){ my $currentCharacter = $_; $currentPosition += 1; if($hold eq $currentCharacter){ $currentSequence .= $currentCharacter; } else{ if(length($longestSeq) < length($currentSequence)){ $longestSeq = $currentSequence; $longestSequenceStartPosition = ($currentPosition -1) - length +($longestSeq); } $currentSequence = $currentCharacter; } $hold = $currentCharacter; } print "$string\n"; print "$longestSeq\n"; my $answer = '-' x length($string); substr($answer,$longestSequenceStartPosition,length($longestSeq)) = $l +ongestSeq; print "$answer\n";
$string = 'abbbcddddfegrgrgddeeeeedd'; $answer = '------------------eeeee--'I want to do it in a better way, find all the blocks, starting from largest to smallest and want to extend to 2-D and 3-D and may be higher dimensions. This is not from a programming contest or a homework
Edit kudra, 2002-10-04 Removed unclosed pre tag
In reply to Block Search by artist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |