Try to update to more modern perl
This commit is contained in:
parent
760478942b
commit
8ea36e4fbf
|
|
@ -2,19 +2,19 @@
|
|||
use v5.40;
|
||||
|
||||
sub day1_1( $filename ) {
|
||||
open(my $FH, '<', $filename) or die $!;
|
||||
open my $fh, '<', $filename;
|
||||
|
||||
my @list1;
|
||||
my @list2;
|
||||
|
||||
my $counter = 0;
|
||||
while(<$FH>) {
|
||||
my @data = split(" ", $_);
|
||||
while(my $line = readline $fh) {
|
||||
my @data = split " ", $line;
|
||||
if (@data == 2) {
|
||||
push(@list1, $data[0]);
|
||||
push(@list2, $data[1]);
|
||||
push @list1, $data[0];
|
||||
push @list2, $data[1];
|
||||
} else {
|
||||
print("More than two data points found at: $counter\n");
|
||||
print "More than two data points found at: $counter\n";
|
||||
return -1;
|
||||
}
|
||||
$counter++;
|
||||
|
|
@ -23,30 +23,21 @@ sub day1_1( $filename ) {
|
|||
@list1 = sort @list1;
|
||||
@list2 = sort @list2;
|
||||
|
||||
if ($#list1 != $#list2) {
|
||||
if (@list1 != @list2) {
|
||||
print("indices don't match\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
my $total = 0;
|
||||
for( my $i = 0; $i<=$#list1; $i++) {
|
||||
foreach my $i ( 0 .. $#list1) {
|
||||
$total += abs($list1[$i] - $list2[$i]);
|
||||
}
|
||||
|
||||
close($FH);
|
||||
close $fh;
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
sub round( $num ) {
|
||||
my $base = int($num);
|
||||
if($num - $base >= 0.5) {
|
||||
$base++;
|
||||
}
|
||||
|
||||
return $base
|
||||
}
|
||||
|
||||
sub find_count($item, $is_sorted, @list) {
|
||||
if($is_sorted != 1) {
|
||||
@list = sort @list;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user