-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.pl
80 lines (69 loc) · 1.19 KB
/
20.pl
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
76
77
78
79
80
#!/usr/bin/perl -w
use strict;
no warnings 'portable';
use Data::Dumper;
use feature 'say';
use Clipboard;
use List::Util qw/sum min max reduce any all none notall first product uniq/;
use Math::Cartesian::Product;
use Math::Complex;
use List::PriorityQueue;
use Memoize;
use Storable qw(dclone);
sub out {
my $out = shift;
if (ref($out)) {
print Dumper($out);
} else {
Clipboard->copy_to_all_selections($out);
print "$out\n";
}
}
my @I;
my $i=0;
while (<>) {
chomp;
push @I, $_;
}
out(mix(1,@I));
for my $el (@I) {
$el*=811589153;
}
out(mix(10,@I));
sub mix {
my $niter = shift;
my @A = @_;
my @B = (0..$#A);
for my $l (1..$niter) {
for my $i (0..$#A) {
my $x;
for my $j (0..$#A) {
if ($B[$j] == $i) {
$x = $j; last;
}
}
my $el = splice(@A,$x,1);
my $dest = ($x + $el) % @A;
splice(@A,$dest,0,$el);
splice(@B,$x,1);
splice(@B,$dest,0,$i);
}
}
my $z;
for my $i (0..$#A) {
unless ($A[$i]) {
$z = $i; last;
}
}
my $sum=0;
$z += 1000;
$z %= @A;
$sum += $A[$z];
$z += 1000;
$z %= @A;
$sum += $A[$z];
$z += 1000;
$z %= @A;
$sum += $A[$z];
return $sum;
}