Generalized topn variable.

This commit is contained in:
2022-12-02 14:42:15 +01:00
parent 7419970f41
commit f5cac113d2
2 changed files with 8 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
# Advent of Code 2022 - assignment 1
This is the first assignment for Advent of Code 2022. The provided solution uses 3 variables: currentScore, highestCalorieScore, currentElf, highestElf.
It is complexity O(n²) since it loops through every line exactly once and the iterates for recalculating highscore.
It is complexity O(n+m) since it loops through every line exactly once (n) and the iterates for recalculating highscore (m).
## Solution description
Every iteration the score is added to the currentScore. If an empty line is detected we check if currentscore exceeds one of our highestCalorieScore, if yes we assign currentElf to highestElf.
@@ -12,4 +12,5 @@ Every iteration the score is added to the currentScore. If an empty line is dete
- https://stackoverflow.com/questions/154059/how-do-i-check-for-an-empty-undefined-null-string-in-javascript
- https://www.geeksforgeeks.org/convert-a-string-to-an-integer-in-javascript/#:~:text=In%20JavaScript%20parseInt()%20function,argument%20of%20parseInt()%20function.
- https://stackoverflow.com/questions/1230233/how-to-find-the-sum-of-an-array-of-numbers
- https://www.w3schools.com/js/js_break.asp
- https://www.w3schools.com/js/js_break.asp
- https://2ality.com/2018/12/creating-arrays.html