View difference between Paste ID: kE6S3Fir and uigVYdHZ
SHOW: | | - or go back to the newest paste.
1
#!/bin/perl
2
use strict;
3
4
my $prio_vals   = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
length($prio_vals) >= @ARGV+1 || die 'too many groups';
6
7
my $symbols     = join '', @ARGV;
8
my %letterprios = ();
9
my $cur_prio    = 1;
10
11
foreach my $s (@ARGV)
12
{
13
	for(my $i = 0; $i < length($s); $i++)
14
	{
15
		$letterprios{substr($s, $i, 1)} = substr($prio_vals, $cur_prio, 1);
16
	}
17
	$cur_prio++;
18
}
19
20
sub gen_code
21
{
22
	my $r = '';
23
	for(my $i = 0; $i < length($_[0]); $i++)
24
	{
25
		$r .= $letterprios{substr($_[0], $i, 1)}||0;
26
	}
27
	return join '', reverse sort split(//, $r);
28
}
29
30
my %words_with_prio = ();
31
while(<STDIN>)
32
{
33
	next if /([$symbols]).*\1/ or /[a-zA-Z]/;
34
	my $s = join '', sort split(//);
35
  	if($s =~ /.*[$symbols]{3,}.*/)
36
	{
37
		chomp;
38
		$words_with_prio{gen_code($_)} = $_;
39
	}
40
}
41
42
foreach my $c (reverse sort keys %words_with_prio)
43
{
44
	print "$words_with_prio{$c}\n";
45
}