diff --git a/pom.xml b/pom.xml
index 6267f8a..daec67e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@
versions-maven-plugin
2.18.0
- file://${session.executionRootDirectory}/versionRules.xml
+ file://${session.executionRootDirectory}/version-rules.xml
diff --git a/src/main/java/com/mattrixwv/adventOfCode24/ProblemSelector.java b/src/main/java/com/mattrixwv/adventOfCode24/ProblemSelector.java
index 403000c..69539f6 100644
--- a/src/main/java/com/mattrixwv/adventOfCode24/ProblemSelector.java
+++ b/src/main/java/com/mattrixwv/adventOfCode24/ProblemSelector.java
@@ -7,12 +7,14 @@ import java.util.Scanner;
import java.util.StringJoiner;
import com.mattrixwv.adventOfCode24.days.Problem;
+import com.mattrixwv.adventOfCode24.days.Problem1;
+import com.mattrixwv.adventOfCode24.days.Problem2;
public class ProblemSelector{
private static final Scanner input = new Scanner(System.in);
//Holds the valid problem numbers
- protected static final List PROBLEM_NUMBERS = List.of(0);
+ protected static final List PROBLEM_NUMBERS = List.of(0, 1, 2);
private ProblemSelector(){
@@ -24,9 +26,11 @@ public class ProblemSelector{
public static Problem getProblem(Integer dayNumber){
Problem day = null;
switch(dayNumber){
+ case 1 : day = new Problem1(); break;
+ case 2 : day = new Problem2(); break;
default: throw new InvalidParameterException();
}
- //return day;
+ return day;
}
//Print the description of a problem
diff --git a/src/main/java/com/mattrixwv/adventOfCode24/days/Problem1.java b/src/main/java/com/mattrixwv/adventOfCode24/days/Problem1.java
new file mode 100644
index 0000000..aa0ae44
--- /dev/null
+++ b/src/main/java/com/mattrixwv/adventOfCode24/days/Problem1.java
@@ -0,0 +1,66 @@
+package com.mattrixwv.adventOfCode24.days;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Scanner;
+
+import com.mattrixwv.Stopwatch;
+
+
+public class Problem1 extends Problem{
+ private static final String inputFileName = "days/Problem1.txt";
+
+
+ public Problem1(){
+ super();
+ description = "Find the sum of the differences between the sorted elements of the left and right columns in the file.";
+ result = "Unresolved";
+ }
+
+
+ public String runSolution(){
+ Stopwatch timer = new Stopwatch();
+ timer.start();
+
+ int totalDifference = 0;
+
+ ArrayList column1 = new ArrayList<>(1000);
+ ArrayList column2 = new ArrayList<>(1000);
+
+
+ //Read elements from the file into memory
+ try(Scanner scanner = new Scanner(this.getClass().getClassLoader().getResourceAsStream(inputFileName))){
+ scanner.useDelimiter("\\s+");
+
+ while(scanner.hasNext()){
+ String token1 = scanner.next();
+ String token2 = scanner.next();
+
+ column1.add(Integer.parseInt(token1));
+ column2.add(Integer.parseInt(token2));
+ }
+ }
+
+ //Sort the two lists of ids
+ Collections.sort(column1);
+ Collections.sort(column2);
+
+ //Get the difference between the corresponding elements in the two lists
+ for(int cnt = 0;cnt < column1.size();++cnt){
+ totalDifference += Math.abs(column1.get(cnt) - column2.get(cnt));
+ }
+
+ //Save the results
+ timer.stop();
+ result = "The sum of the differences of the two columns is " + totalDifference + ".\nIt took " + timer.toString() + " to run the algorithm.";
+
+ return result;
+ }
+}
+
+/*
+Find the sum of the differences between the sorted elements of the left and right columns in the file.
+The sum of the differences of the two columns is 1666427.
+It took 10.285 milliseconds to run the algorithm.
+*/
diff --git a/src/main/java/com/mattrixwv/adventOfCode24/days/Problem2.java b/src/main/java/com/mattrixwv/adventOfCode24/days/Problem2.java
new file mode 100644
index 0000000..16681b2
--- /dev/null
+++ b/src/main/java/com/mattrixwv/adventOfCode24/days/Problem2.java
@@ -0,0 +1,84 @@
+package com.mattrixwv.adventOfCode24.days;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Scanner;
+
+import com.mattrixwv.Stopwatch;
+
+public class Problem2 extends Problem{
+ private static final String inputFileName = "days/Problem1.txt";
+
+
+ public Problem2(){
+ super();
+ description = "Find the similarity score between the two columsn of numbers";
+ result = "Unresolved";
+ }
+
+
+ @Override
+ public String runSolution(){
+ Stopwatch timer = new Stopwatch();
+ timer.start();
+
+ int totalSimilarityScore = 0;
+
+ ArrayList column1 = new ArrayList<>(1000);
+ ArrayList column2 = new ArrayList<>(1000);
+
+
+ //Read elements from the file into memory
+ try(Scanner scanner = new Scanner(this.getClass().getClassLoader().getResourceAsStream(inputFileName))){
+ scanner.useDelimiter("\\s+");
+
+ while(scanner.hasNext()){
+ String token1 = scanner.next();
+ String token2 = scanner.next();
+
+ column1.add(Integer.parseInt(token1));
+ column2.add(Integer.parseInt(token2));
+ }
+ }
+
+ //Sort the two lists of ids
+ Collections.sort(column1);
+ Collections.sort(column2);
+
+ //Get the similarity score of each elements and keep a running sum
+ //The similarity score is the element in column 1 multiplied by the number of times it appears in column 2
+ for(Integer num : column1){
+ int count = count(num, column2);
+ totalSimilarityScore += (num * count);
+ }
+
+ //Save the results
+ timer.stop();
+ result = "The similarity score between the two columns of numbers is " + totalSimilarityScore + ".\nIt took " + timer.toString() + " to run the algorithm.";
+
+ return result;
+ }
+
+ //Get the number of times a number appears in the list
+ private int count(int num, List list){
+ int cnt = 0;
+
+ for(Integer n : list){
+ if(n == num){
+ ++cnt;
+ }
+ if(n > num){
+ break;
+ }
+ }
+
+ return cnt;
+ }
+}
+
+/*
+Find the similarity score between the two columns of numbers
+The similarity score between the two columns of numbers is 24316233.
+It took 17.875 milliseconds to run the algorithm.
+*/
diff --git a/src/main/resources/days/Problem1.txt b/src/main/resources/days/Problem1.txt
new file mode 100644
index 0000000..295e7d5
--- /dev/null
+++ b/src/main/resources/days/Problem1.txt
@@ -0,0 +1,1000 @@
+38450 56790
+94765 36795
+89694 26251
+96083 99006
+57068 30577
+32031 60133
+97652 26657
+85752 40654
+66117 44144
+29274 30512
+73274 84130
+15357 56848
+79851 19968
+68766 87545
+67087 66672
+19642 37292
+27123 85780
+98928 19402
+48657 36964
+68163 68163
+74320 70436
+68369 93818
+63293 10589
+70014 13744
+58505 92715
+79235 72633
+42118 84297
+89553 49028
+54588 42667
+74947 89737
+95994 68163
+40886 27795
+89808 48152
+51059 71866
+29828 47181
+26337 92715
+75448 87890
+26971 12395
+71808 80599
+29493 61319
+47055 43873
+50770 96410
+14156 68842
+56759 54054
+38923 26343
+12572 34357
+88675 40823
+78193 39871
+41580 42667
+38011 85234
+27994 39871
+98468 21775
+53338 68111
+27553 35842
+77017 80913
+47383 93294
+79266 78275
+74356 77328
+22139 87671
+84119 39187
+77267 66964
+97361 23225
+58958 10638
+17232 96076
+26441 75500
+49244 64695
+58905 39871
+15329 69637
+56453 42667
+44121 36077
+36651 39871
+22517 45430
+36899 71230
+44144 88757
+14168 30512
+75698 26657
+53259 91167
+95206 30577
+53817 34357
+67800 77328
+48808 99593
+35316 55943
+25220 54492
+23135 34357
+64270 19402
+62121 77328
+90797 94795
+49815 92715
+39585 72810
+83592 69042
+57529 54279
+36396 35842
+50313 11918
+41827 94458
+58012 42667
+66853 95424
+59067 66672
+29841 34357
+25699 99289
+75721 58905
+15845 86480
+68449 65563
+78811 40412
+77447 45365
+84481 68163
+67243 48342
+40596 78376
+18530 55403
+16485 30577
+18820 80617
+10705 26657
+92870 32227
+63712 26657
+71445 71866
+27313 80913
+60286 56912
+40149 29131
+74223 86480
+30240 44070
+57108 76095
+42911 44144
+30976 76095
+26657 17110
+77509 36380
+76095 30914
+64592 94578
+97195 95571
+27060 16139
+60414 85294
+29255 45894
+74160 47530
+35318 59173
+59140 95571
+53239 25992
+47530 46078
+66911 59604
+28261 27795
+78688 83703
+78682 77328
+16916 56912
+80432 82570
+48514 62025
+44320 98398
+87488 71139
+23810 68163
+83225 55084
+52412 22240
+71961 76095
+76949 65702
+54333 37419
+46121 12587
+40001 30512
+28005 46617
+43356 27795
+94967 62701
+98138 69042
+58625 35550
+24459 52266
+34147 25961
+96300 21588
+47061 77328
+50297 71866
+19355 68163
+96284 40450
+41466 84017
+72578 24354
+91238 20765
+87100 92715
+22792 71767
+49305 82403
+50026 95295
+71866 13340
+77297 93959
+79510 63708
+72670 94771
+24090 39871
+71170 58905
+24188 45664
+15286 68163
+71137 81703
+66672 19402
+64757 39871
+40097 34357
+66347 39871
+11349 91362
+96456 92715
+60810 46298
+30775 24294
+46875 87235
+74042 87418
+98242 91925
+20464 35280
+11216 92533
+51584 19789
+29479 22783
+25274 27795
+76193 57068
+63580 95571
+80770 92715
+46436 33662
+78670 94935
+24606 36795
+50913 34357
+87427 96279
+20527 69042
+39190 35842
+12482 77261
+59815 99289
+58857 47887
+26313 84479
+28707 18124
+85620 34357
+22793 80913
+18901 61965
+26137 68163
+17778 39871
+33813 31786
+82136 69042
+29410 27795
+45844 80913
+79750 58401
+95419 20872
+40640 51108
+56250 95571
+46252 26508
+90620 39871
+60057 62139
+35869 56912
+84211 63802
+72937 46436
+80322 21794
+52793 34357
+74580 35842
+25536 69042
+50585 59650
+21269 65327
+85698 39220
+80071 46392
+36306 14161
+66725 67333
+33487 27165
+27786 47530
+93519 22622
+55574 97473
+65632 81795
+75140 25442
+21376 42667
+56970 39871
+94632 77261
+59040 13889
+98256 96213
+66819 17432
+32205 67735
+23862 91732
+35302 39112
+34357 30512
+16783 44692
+50804 86480
+82254 80253
+75852 39978
+42052 79753
+56085 56912
+72548 78082
+72709 94294
+27187 31138
+45506 58568
+46995 80913
+83699 72574
+49924 70436
+99855 66672
+62856 56084
+28739 36148
+17311 34650
+50379 51376
+56636 90184
+70872 74758
+86900 42527
+57857 39871
+92352 70111
+11595 26657
+33278 38217
+79985 19402
+51838 96864
+79422 91362
+15836 25261
+85535 71866
+71491 86480
+18081 97179
+47876 47308
+97371 88031
+22201 74539
+11364 17756
+94451 72603
+61063 86480
+13448 28943
+20391 59145
+61615 37956
+45636 30577
+53957 58947
+85177 30914
+81213 56912
+48248 14944
+45113 39688
+82427 85733
+33323 29457
+67505 47530
+26670 69416
+79620 70436
+22783 30577
+75102 65563
+10610 86480
+30914 42631
+53004 95284
+73145 88017
+30678 30577
+12762 99289
+86499 22109
+13832 91362
+89930 62592
+93980 86977
+53089 59415
+68341 33662
+25812 61965
+77380 22827
+78760 10051
+98000 91362
+78359 96086
+32489 77261
+94527 38980
+33226 35842
+61775 30926
+31168 54492
+95196 60512
+28708 21619
+99934 95865
+55576 15173
+40679 96922
+77996 92715
+74121 27578
+80739 39841
+27324 91362
+83292 84113
+26406 76095
+81713 61946
+88520 26657
+71675 89157
+30129 86760
+37014 56814
+33970 68326
+32494 79036
+39139 22783
+76214 69081
+76953 95865
+35040 66371
+17949 55561
+81520 35842
+62508 89829
+54572 35842
+79509 19402
+24891 66672
+45794 66672
+85379 91362
+79782 80913
+73528 66298
+14064 69042
+71965 28826
+60533 39871
+22163 80913
+20833 71986
+84152 30577
+71152 37179
+24562 71476
+50251 30577
+95527 77590
+88201 56912
+87781 91109
+44210 92715
+43999 92715
+90557 44144
+26041 70436
+33246 13019
+82762 17806
+54561 26657
+31699 77328
+24806 48798
+97294 26657
+57582 97051
+38956 68163
+91638 65213
+44169 80913
+29835 92715
+57045 93451
+56421 21138
+98128 69042
+24605 36264
+23870 63516
+97003 64704
+11739 83574
+89513 80913
+20925 61438
+14761 90325
+23754 33662
+42102 22783
+38734 40082
+39825 56912
+81566 30512
+84612 30512
+90484 22783
+22889 22783
+54768 77328
+48764 81529
+12481 95865
+90546 90454
+38087 68163
+49010 30914
+92728 74197
+81313 23403
+74535 16503
+36939 68163
+51987 42762
+62840 71866
+43761 33662
+58282 92715
+63257 33662
+48410 92487
+57997 81716
+14800 82109
+77328 76473
+82570 30926
+48271 14229
+69127 30577
+34386 35842
+69197 95571
+10827 57032
+82708 65563
+95057 13049
+44966 33377
+21933 22783
+42772 56789
+19232 98930
+53262 76095
+32302 38996
+14637 41139
+91419 86478
+66541 86480
+15810 51561
+75596 83362
+63247 47395
+96073 22783
+40948 35040
+77261 57068
+33418 17716
+30512 86480
+69148 87719
+62854 35014
+98389 30926
+23120 33590
+56653 81140
+49957 58356
+30593 17708
+57670 69077
+44904 30926
+10003 59688
+17583 22783
+35032 80913
+17608 23816
+20288 82570
+43214 88279
+79347 79311
+94845 35842
+24989 63095
+84669 67448
+74014 98215
+13045 27795
+64782 77328
+87683 22783
+36451 68163
+59285 85570
+99210 94373
+66649 30914
+53952 80913
+83188 34357
+88672 45650
+21214 44144
+24393 19402
+88027 66672
+75510 70374
+61965 56521
+50081 59608
+84120 24816
+84090 49853
+90580 28974
+37942 45203
+20157 27378
+82710 62252
+15745 80913
+39765 29190
+66955 68163
+31533 95577
+18316 46335
+48785 11243
+19970 33662
+26109 70173
+41210 85121
+45968 19402
+19444 37680
+64435 46680
+34213 61965
+21211 19671
+75654 65563
+89852 55220
+19610 77328
+53810 34368
+18740 93310
+39042 70436
+50333 14352
+56479 98509
+62955 36393
+45736 62875
+88746 68163
+16507 14233
+70514 57068
+15217 33242
+69123 59998
+24278 30914
+45495 34707
+15905 83611
+13582 54081
+83066 65927
+21087 76095
+32035 71866
+50502 76095
+80402 16047
+54701 50057
+25184 79622
+52595 92715
+13794 36821
+10548 73363
+86251 65563
+57065 87659
+35617 69042
+40607 26657
+54492 58961
+56644 77328
+45679 96959
+14251 12051
+71806 68163
+42346 91362
+48325 57102
+51980 24331
+98014 92715
+39611 30577
+79247 39871
+87735 63608
+93919 30512
+32619 66672
+31659 49528
+27614 49927
+96264 35040
+17373 66672
+79122 80913
+36904 33534
+78239 64891
+25085 86802
+16451 36795
+43848 77278
+65380 30926
+69891 56912
+88097 76095
+53472 30926
+85315 71866
+67185 47530
+30926 36278
+38001 75190
+87330 46332
+19192 65563
+63847 35842
+10483 33659
+75527 34259
+63424 57068
+28256 68975
+81540 42957
+93018 19454
+75634 92715
+71643 73598
+72464 22819
+74651 38339
+61692 39786
+40829 58905
+63414 33662
+51580 19402
+54813 39871
+63005 90404
+80646 36866
+64628 22180
+94761 47743
+79054 33662
+74941 66672
+84955 92863
+78409 33577
+54178 65563
+56533 39814
+18900 67503
+55216 19240
+66854 53566
+88094 44610
+60806 83748
+27368 66672
+58081 65083
+21266 30577
+62229 26657
+22785 36169
+38447 95571
+69547 19402
+12256 13551
+34249 41587
+43430 80913
+83343 30512
+53434 92774
+63321 80913
+33819 95865
+38690 44769
+47509 33662
+62269 66672
+53247 31660
+88548 58905
+42667 30512
+92265 60686
+94540 76095
+72984 71866
+62111 23007
+75974 35704
+54383 44838
+79046 44144
+10383 36795
+77274 34819
+90101 86480
+90466 94388
+56335 47650
+34056 30577
+65220 74822
+30577 22783
+85922 76425
+88914 97485
+59974 99451
+59682 45251
+42802 76095
+93454 86480
+51073 82570
+66264 23784
+39483 80913
+88565 61865
+96306 22783
+50883 26870
+26523 43996
+38219 33662
+19402 39005
+63482 23565
+97055 36795
+66216 30577
+79952 33662
+69328 21802
+41244 53694
+83424 56912
+10589 68163
+88514 93117
+53046 42667
+37352 95247
+34421 71866
+67039 43583
+37162 86480
+74312 35842
+38740 66946
+69471 49022
+32289 47530
+72562 42667
+37081 93898
+31329 30512
+31243 53516
+62461 56655
+96473 60873
+25279 50991
+10072 70572
+47497 33662
+49427 19750
+10605 23381
+91095 47797
+58414 27795
+82370 21060
+57378 81767
+24485 35040
+13809 35448
+76442 30512
+64387 35842
+57400 65563
+29253 42667
+63306 66369
+23098 11025
+62865 65563
+87758 19402
+32587 21767
+45399 86480
+41893 76095
+56666 71866
+35264 42667
+52577 39871
+51123 65501
+62388 33662
+66812 34357
+21600 10996
+74599 95653
+72802 30577
+84800 19402
+72787 73560
+53794 26040
+33247 32184
+52978 66672
+66156 26657
+91181 30914
+48551 84043
+95712 64949
+25556 58905
+84885 42667
+53327 78473
+33532 12343
+19286 12106
+89021 26657
+10498 19402
+61704 77261
+46537 86328
+36143 57061
+76654 30512
+57004 55014
+85959 10589
+77137 22783
+52952 51845
+51984 92715
+30028 25828
+84410 99687
+37142 98764
+77446 39871
+55877 34357
+67259 79994
+99289 76315
+85489 76095
+31363 70436
+96633 69042
+81214 76530
+87281 42667
+44440 74182
+63470 68163
+42955 27795
+94662 30577
+14746 30914
+20227 61537
+69042 13898
+13060 61908
+43581 99289
+65247 40213
+96862 77549
+39871 19402
+19865 30512
+13117 92528
+60881 39871
+85892 31427
+41497 95571
+16212 33092
+25806 75406
+98783 86480
+84964 34920
+64895 68163
+49132 55568
+64979 88017
+17208 84371
+77114 61301
+47287 26657
+67657 35842
+99439 36267
+41719 80913
+79716 15507
+60986 82042
+93689 77261
+41660 42512
+31113 88722
+15586 33662
+93371 35040
+97330 92715
+14879 95341
+20385 66672
+51055 88017
+76346 66058
+70253 21087
+63415 80394
+95865 99337
+86466 61965
+14242 58182
+54002 31706
+70433 62878
+91588 32216
+37217 30633
+71912 54182
+15879 87966
+42596 23041
+90613 99312
+69816 55585
+82985 30926
+13592 19402
+90849 26519
+33383 32459
+97097 95571
+29779 70436
+19760 25315
+93199 26562
+35188 46436
+38680 32337
+75459 86005
+19065 95571
+35183 70436
+92715 46976
+83060 66672
+77412 94697
+97799 22096
+32652 69042
+94958 91362
+72526 42667
+16026 19402
+80913 82873
+41578 92715
+58877 19402
+37030 22783
+68147 20144
+56044 27795
+23335 53093
+42998 86480
+80307 26625
+77512 33662
+54090 30411
+88343 61965
+15894 16084
+62706 63686
+35842 15310
+95072 21419
+52930 44144
+75602 14290
+78117 33467
+65532 33662
+75020 65563
+46455 14369
+62850 42667
+81095 47639
+31291 61965
+27407 87833
+94752 15102
+92700 36795
+84447 99289
+92801 34357
+29143 49061
+21884 74720
+62375 12941
+19197 68163
+54156 27680
+78873 80806
+38246 76095
+72027 27128
+91571 17354
+53847 40153
+81973 29225
+13732 68670
+38452 20197
+31228 18468
+71135 46834
+21688 57767
+30221 78848
+31781 89061
+31625 87715
+53131 33362
+50753 82036
+49089 71866
+49710 86480
+48564 19402
+29574 93246
+84072 74995
+90715 65563
+87964 39871
+73204 78226
+78502 52265
+87303 65563
+31906 27800
+74740 58905
+22098 43030
+53867 78190
+67350 85640
+91135 99289
+53468 10699
+30141 53709
+74308 16668
+69043 99289
+88017 36795
+17584 21883
+32718 22783
+12671 57068
+69879 39023
+59025 98514
+52386 35842
+61922 63179
+89685 19402
+95571 26657
+86480 86465
+78702 13752
+29611 35253
+92687 77295
+66461 39430
+18818 98611
+64227 14592
+56273 87458
+10266 92715
+85568 54714
+41702 97648
+52256 44144
+20344 18187
+15045 66672
+36323 64742
+86451 62476
+62028 69193
+72924 50345
+95405 79614
+83618 85533
+36923 57068
+74576 75901
+60074 56912
+58127 13632
+94366 68163
+79964 86480
+20371 36795
+57111 92715
+56351 35040
+53511 22783
+69850 78355
+48511 11820
+11488 53110
+23957 34145
+10798 83449
+78424 95208
+70436 30577
+82584 86506
+27795 99289
+25243 33662
+85087 36008
+20537 26713
+60038 58905
+26860 66672
+29565 42485
+11527 63340
+38566 56304
+33662 99376
+30355 37831
+98463 81666
+61272 92715
+11703 85639
+71287 63011
+47090 50356
+84127 71866
+26416 62286
+17988 23504
+84605 27795
+64060 66974
+17587 77092
+56912 56912
+47325 36795
+25425 42294
+77940 30512
+82115 26657
+18915 30926
+53122 81831
+92038 66693
+90088 93030
+40983 37896
+64234 27789
+39122 80530
+53727 36795
+75297 34357
+51556 84926
+71953 47530
+83078 97110
+65563 34357
+53145 32345
+36795 26935
+91362 30847
+47701 27795
+33374 40093
+15572 56912
+96537 70436
+69457 77328
+62097 50482
+62543 65563
+23906 61328
+57479 72207
+37900 90011
+25566 23322
+22377 46878
diff --git a/versionRules.xml b/version-rules.xml
similarity index 100%
rename from versionRules.xml
rename to version-rules.xml