-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb79.pl
More file actions
75 lines (73 loc) · 1.81 KB
/
Prob79.pl
File metadata and controls
75 lines (73 loc) · 1.81 KB
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
#! usr/bin/perl
#Matthew Digman
use strict;
open FILE,'<keylog.txt' or die "unable to read from file: $!";
my %log_attempts;
for(<FILE>){
chomp;
$log_attempts{$_}=1;
}
my @attempts=keys %log_attempts;
sub functionally_identical{
my $a1=shift;
my $a2=shift;
my @array1=@{$a1};
my @array2=@{$a2};
OUTER:for(@array1){
my $seek=$_;
next unless(defined $seek);
for(@array2){
next OUTER if($seek==$_);
}
return 0;
}
OUTER:for(@array2){
my $seek=$_;
next unless(defined $seek);
for(@array1){
next OUTER if($seek==$_);
}
return 0;
}
return 1;
}
my %requirements;
$requirements{$_}=[[],[]] for(0,1,2,3,6,7,8,9);
for(@attempts){
my @nums=split '', $_;
push (@{@{$requirements{$nums[0]}}[1]},($nums[1],$nums[2]));
push (@{@{$requirements{$nums[1]}}[1]},($nums[2]));
push (@{@{$requirements{$nums[1]}}[0]},($nums[0]));
push (@{@{$requirements{$nums[2]}}[0]},($nums[0],$nums[1]));
}
my @needed=keys %requirements;
my @predicted_pass=(undef,undef,undef,undef,undef,undef,undef,undef);
while(@needed){
for(@needed){
if (!(defined $requirements{$_}->[0])&&!defined $predicted_pass[7]){
$predicted_pass[7]=$_;
$requirements{$_}=undef;
next;
}
if (!(@{$requirements{$_}->[1]})&&!defined $predicted_pass[0]&&!$_==0){
$predicted_pass[0]=$_;
$requirements{$_}=undef;
next;
}
my $seek=$_;
my @left=@{$requirements{$seek}->[0]};
my @right=@{$requirements{$seek}->[1]};
for(my $itr=1; $itr<7; $itr++){
my @copy=@predicted_pass;
my @f_left=splice @copy, $itr,0;
my @f_right=@copy;
if(functionally_identical(\@left, \@f_left)&&functionally_identical(\@right,\@f_right)){
$predicted_pass[$itr]=$seek;
$requirements{$seek}=undef;
next;
}
}
}
@needed=keys %requirements;
}
print @predicted_pass;