diff --git a/README.md b/README.md
index da57339..3bbe820 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,5 @@
+# Advent of Code 2022 - Assignment6_javascript
This repository contains answers to the assignments of Advent of Coding 2022
+
+## References
+- https://stackoverflow.com/questions/28207610/checking-if-the-characters-in-a-string-are-all-unique
\ No newline at end of file
diff --git a/index.html b/index.html
index 5cf1ba4..794716f 100644
--- a/index.html
+++ b/index.html
@@ -8,7 +8,9 @@
Assignment:
-
+
+
+
Answer:
Provide input first
diff --git a/script.js b/script.js
index a6e2848..d89ce30 100644
--- a/script.js
+++ b/script.js
@@ -1,12 +1,16 @@
const ASSIGNMENT = 'assignment';
const ANSWER = 'answer';
+const ALGORITHM_CHECKBOX = 'algorithm';
+const MARKER_DISTINCT_CHARACTERS = 4;
+const MESSAGE_DISTINCT_CHARACTERS = 14;
const NEWLINE_CHARACTER = '\n';
/**
* Main function
*/
window.onload = function() {
- document.getElementById(ASSIGNMENT).addEventListener("input", calculateAnswer);
+ document.getElementById(ASSIGNMENT).addEventListener("input", calculateAnswer);
+ document.getElementById(ALGORITHM_CHECKBOX).addEventListener("click", calculateAnswer);
}
/**
@@ -15,7 +19,9 @@ window.onload = function() {
*/
function calculateAnswer(event) {
console.info("Calculating answer for input...");
- let answer = algorithm(event.target.value);
+ let assignment = document.getElementById(ASSIGNMENT).value;
+ let distinctCharacters = (document.getElementById(ALGORITHM_CHECKBOX).checked)? MESSAGE_DISTINCT_CHARACTERS: MARKER_DISTINCT_CHARACTERS;
+ let answer = algorithm(assignment, distinctCharacters);
document.getElementById(ANSWER).innerText = answer;
}
@@ -25,9 +31,28 @@ function calculateAnswer(event) {
* @param assignment the input from the assignment.
* @return string the answer
*/
-function algorithm(assignment) {
- let lines = assignment.trim().split(NEWLINE_CHARACTER);
- console.info("Linecount:" + lines.length);
+function algorithm(assignment, distinctCharacters) {
+ let signal = assignment.trim();
+ let marker = assignment.substring(0,distinctCharacters);
- // TODO: implement assignment
+ for(let i=distinctCharacters; i