File: extreme.pl

package info (click to toggle)
enca 1.21-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,948 kB
  • sloc: ansic: 10,297; sh: 5,858; xml: 2,132; makefile: 700; perl: 261
file content (61 lines) | stat: -rwxr-xr-x 924 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
use warnings;
use strict;

my @w1 = ( 0 ) x 0x100;
my @w2 = ( 0 ) x 0x100;
my $m;

open FH, "<".$ARGV[0];
while (<FH>) {
  my $ch = substr $_,0,1;
  my $count = substr $_,2;
  $w1[ord $ch] = $count;
}
close FH;

open FH, "<".$ARGV[1];
while (<FH>) {
  my $ch = substr $_,0,1;
  my $count = substr $_,2;
  $w2[ord $ch] = $count;
}
close FH;

for (my $i = 0; $i < 0x100; $i++) {
  my $x = $w1[$i];
  $w1[$i] -= 4*$w2[$i];
  $w2[$i] -= 4*$x;
}

$m = 1;
while ($m > 0) {
  my $j = 0;
  for (my $i = 1; $i < 0x100; $i++) {
    if ($w1[$i] > $w1[$j]) {
      $j = $i;
    }
  }
  $m = $w1[$j];
  if ($m > 0) {
    printf '0x%02x, (%u)'."\n", $j, $m;
    $w1[$j] = -1;
  }
}

print "\n";

$m = 1;
while ($m > 0) {
  my $j = 0;
  for (my $i = 1; $i < 0x100; $i++) {
    if ($w2[$i] > $w2[$j]) {
      $j = $i;
    }
  }
  $m = $w2[$j];
  if ($m > 0) {
    printf '0x%02x, (%u)'."\n", $j, $m;
    $w2[$j] = -1;
  }
}