3f3daab72615fb220d3a1cd1bec879b652855852
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+m) since it loops through every line exactly once (n) and the iterates for recalculating highscore (m). The GUI also provides a checkbox to toggle top3 or top1.
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.
references
- https://adventofcode.com/2022/day/1
- https://stackoverflow.com/questions/17595361/how-to-read-text-line-by-line-in-a-html-text-area
- https://bobbyhadz.com/blog/javascript-get-value-of-textarea
- 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://2ality.com/2018/12/creating-arrays.html
Description
Languages
JavaScript
52.2%
HTML
26.4%
CSS
21.4%