#!/usr/local/bin/perl -w $argc = @ARGV; if ( $argc != 4 ) { die "Usage verify_vdw \n"; } $fileName = $ARGV[0]; $colorNum = $ARGV[1]; $maxLength = $ARGV[2]; $fullLength = $ARGV[3]; open(RESULTFILE, $fileName) or die "Can't open file: $fileName\n"; @color_value = ([]); @value_index = (); for ( $i = 1; $i <= $colorNum; $i++ ) { $value_index[$i] = 0; } $currentBlock = 0; $num = 0; while ($line = ) { $currentBlock++ if ( $line =~ /^.*Block.*/ ); while ( $line =~ /^\s*(\d+)(.*)/ ) { $color_value[$currentBlock] [$value_index[$currentBlock]++] = $1; $line = $2; $num++; } } if ( $colorNum != $#color_value ) { die "Wrong \# of colors\n"; } if ( $num != $fullLength ) { die "Not all integers from [1..$fullLength] occurred\n"; } @sorted = ([]); for ( $i = 1; $i <= $colorNum; $i++ ) { @{$sorted[$i]} = sort {$a <=> $b} @{$color_value[$i]}; } $findSeq = 1; for ( $i = 1; $i <= $colorNum; $i++ ) { $maxDiff = int($sorted[$i][$#{$sorted[$i]}] / ($maxLength-1)); for ( $j = 0; $j < $#{$sorted[$i]}; $j++ ) { for ( $k = 1; $k <= $maxDiff; $k++ ) { $findSeq = 1; for ( $ele = 1; $ele <= $maxLength-1; $ele++ ) { $nextValue = $sorted[$i][$j] + $k * $ele; $findNext = 0; for ( $search = $j+1; $search <= $#{$sorted[$i]}; $search++ ) { if ( $sorted[$i][$search] == $nextValue ) { $findNext = 1; last; } } if ( $findNext == 0 ) { $findSeq = 0; last; } } if ( $findSeq == 1 ) { print STDOUT "not a solution, "; print STDOUT "here is the problem: \n"; print STDOUT "start = [Block:$i,Value:$sorted[$i][$j]], "; print STDOUT "step = $k \n"; last; } } if ( $findSeq == 1 ) { last; } } if ( $findSeq == 1 ) { last; } } if ( $findSeq != 1 ) { print STDOUT "It IS a correct solution!\n"; }