-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwutil.pm
75 lines (70 loc) · 1.19 KB
/
wutil.pm
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use Math::BigInt;
package wutil;
##########################
# cromstring returns the "cromulence string"
# this is => h1i2s2t1
sub cromstring
{
my $x = lc($_[0]); $x =~ s/[^a-z]//gi;
my $cromString = "";
if ($x !~ /[a-z]/) { return 1; } #trivially true
@z = split(//, $x);
my @which;
for (@z)
{
#print "Adding $_: @which\n";
@which[ord($_)-97]++;
}
if (($_[1] == -1) || ($_[1] == 0))
{
$bgcd = Math::BigInt::bgcd(@which) . "=GCD...";
for (0..25)
{
if (@which[$_])
{
@which[$_] /= $bgcd;
}
}
}
for (0..25)
{
if (@which[$_])
{
$c = chr($_+97);
$cromString .= "$c@which[$_]";
}
}
if ($_[1] == 1)
{
$bgcd = Math::BigInt::bgcd(@which) . "=GCD...";
if ($bgcd == 1)
{
print "not perfect anagram";
$lowestInt = 0;
for (0..25)
{
if (@which[$_])
{
if (!$lowestInt) { $lowestInt = @which[$_]; }
elsif (@which[$_] < $lowestInt) { $lowestInt = @which[$_]; }
}
}
print "\nCulprit(s): ";
for (0..25)
{
if (@which[$_] % $lowestInt)
{
$rem = @which[$_] % $lowestInt;
print chr($_+97) . "($rem) ";
}
}
print "\n";
}
else
{
print "Perfect anagram";
}
}
return $cromString;
}
1;