-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchal10.pl
56 lines (42 loc) · 1.15 KB
/
chal10.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
#!/usr/bin/perl
use strict;
open my $FILE, "chal10Input.txt" or die $!;
chomp(my @input = <$FILE>);
close $FILE;
my $jolt = 0;
my $currentAdapter = 1;
my $oneDifCount = 0;
my $twoDifCount = 0;
my $threeDifCount = 1;
while ($currentAdapter != 99999) {
$currentAdapter = findAdapterForJolt($jolt, @input);
if($currentAdapter == 99999) {
print "$oneDifCount <=> $twoDifCount <=> $threeDifCount\n";
exit;
}
print "[+] Found $currentAdapter\n";
if($currentAdapter == ($jolt+1)) {
print "oneDifCount $currentAdapter && $jolt +1\n";
$oneDifCount++;
} elsif ($currentAdapter == ($jolt+2)) {
print "twoDifCount $currentAdapter && $jolt +2\n";
$twoDifCount++;
} elsif($currentAdapter == ($jolt+3)) {
print "threeDifCount $currentAdapter && $jolt +3\n";
$threeDifCount++;
} else {
die "Something went wrong...";
}
$jolt = $currentAdapter;
}
sub findAdapterForJolt() {
my $jolt = shift;
my @input = @_;
my $lowestPossibleAdapter = 99999;
foreach my $adapter (@input) {
if($adapter < $jolt + 4 && $adapter > $jolt && $adapter < $lowestPossibleAdapter) {
$lowestPossibleAdapter = $adapter;
}
}
return $lowestPossibleAdapter;
}