-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94feba0
commit 0ab8495
Showing
8 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
3 4 | ||
4 3 | ||
2 5 | ||
1 3 | ||
3 9 | ||
3 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'day_01_solver.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:h3x_devtools/solvers/advent_of_code/aoc_solver.dart'; | ||
|
||
export 'dart:math'; | ||
|
||
export '../../_solver_exports.dart'; | ||
|
||
abstract class AdventOfCode2024Solver extends AdventOfCodeSolver { | ||
|
||
@override | ||
final int yearNumber = 2024; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:h3x_devtools/solvers/advent_of_code/2024/aoc_2024_solver.dart'; | ||
|
||
class Day01Solver extends AdventOfCode2024Solver { | ||
|
||
@override | ||
final int dayNumber = 1; | ||
|
||
@override | ||
String getSolution(String input) { | ||
List<List<int>> locationIdGroups = input.splitLines().map((line) => line.split(' ').parsedAsInts.toList()).toList(); | ||
|
||
// Part 1 | ||
List<int> list1Sorted = locationIdGroups.map((group) => group[0]).toList()..sort(); | ||
List<int> list2Sorted = locationIdGroups.map((group) => group[1]).toList()..sort(); | ||
|
||
int totalDistance = list1Sorted.foldIndexed(0, (index, previous, element) => previous + (element - list2Sorted[index]).abs()); | ||
|
||
// Part 2 | ||
List<int> list1 = locationIdGroups.map((group) => group[0]).toList(); | ||
List<int> list2 = locationIdGroups.map((group) => group[1]).toList(); | ||
|
||
double totalSimilarity = list1.foldIndexed(0, (index, previous, element) => previous + element * list2.countValueOccurances(element)); | ||
|
||
return 'Total distance: $totalDistance, total similarity: $totalSimilarity'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters