diff --git a/Array/LongStrWithoutRepeat.js b/Array/LongStrWithoutRepeat.js similarity index 100% rename from Array/LongStrWithoutRepeat.js rename to Array/LongStrWithoutRepeat.js diff --git a/DailyCode/basic todos with localstorage/index.js b/DailyCode/basic todos with localstorage/index.js index 0cd7f58..8f48da2 100644 --- a/DailyCode/basic todos with localstorage/index.js +++ b/DailyCode/basic todos with localstorage/index.js @@ -1,90 +1,90 @@ - -// console.log("Welcome to notes app. This is app.js"); -showNotes(); - -// If user adds a note, add it to the localStorage -let addBtn = document.getElementById("addBtn"); -addBtn.addEventListener("click", function(e) { - let addTitle = document.getElementById('addTitle'); - let addTxt = document.getElementById("addTxt"); - let notes = localStorage.getItem("notes"); - if (notes == null) { - notesObj = []; - } else { - notesObj = JSON.parse(notes); - } - let myObj = { - title: addTitle.value, - text: addTxt.value - } - notesObj.push(myObj); - localStorage.setItem("notes", JSON.stringify(notesObj)); - addTxt.value = ""; - addTitle.value = ""; - showNotes(); -}); - - - - - - -// Function to show elements from localStorage -function showNotes() { - let notes = localStorage.getItem("notes"); - if (notes == null) { - notesObj = []; - } else { - notesObj = JSON.parse(notes); - } - let html = ""; - notesObj.forEach(function(element, index) { - html += ` -
-
-
${element.title.toUpperCase()}
-

${element.text}

- -
-
`; - }); - let notesElm = document.getElementById("notes"); - if (notesObj.length != 0) { - notesElm.innerHTML = html; - } else { - notesElm.innerHTML = `Nothing to show! Use "Add a Note" section above to add notes.`; - } -} - -// Function to delete a note -function deleteNote(index) { - - let notes = localStorage.getItem("notes"); - if (notes == null) { - notesObj = []; - } else { - notesObj = JSON.parse(notes); - } - - notesObj.splice(index, 1); - localStorage.setItem("notes", JSON.stringify(notesObj)); - showNotes(); -} - - -let search = document.getElementById('searchTxt'); -search.addEventListener("input", function(){ - - let inputVal = search.value.toLowerCase(); - let noteCards = document.getElementsByClassName('noteCard'); - Array.from(noteCards).forEach(function(element){ - let cardTxt = element.getElementsByTagName("p")[0].innerText; - if(cardTxt.includes(inputVal)){ - element.style.display = "block"; - } - else{ - element.style.display = "none"; - } - - }) -}) + +// console.log("Welcome to notes app. This is app.js"); +showNotes(); + +// If user adds a note, add it to the localStorage +let addBtn = document.getElementById("addBtn"); +addBtn.addEventListener("click", function(e) { + let addTitle = document.getElementById('addTitle'); + let addTxt = document.getElementById("addTxt"); + let notes = localStorage.getItem("notes"); + if (notes == null) { + notesObj = []; + } else { + notesObj = JSON.parse(notes); + } + let myObj = { + title: addTitle.value, + text: addTxt.value + } + notesObj.push(myObj); + localStorage.setItem("notes", JSON.stringify(notesObj)); + addTxt.value = ""; + addTitle.value = ""; + showNotes(); +}); + + + + + + +// Function to show elements from localStorage +function showNotes() { + let notes = localStorage.getItem("notes"); + if (notes == null) { + notesObj = []; + } else { + notesObj = JSON.parse(notes); + } + let html = ""; + notesObj.forEach(function(element, index) { + html += ` +
+
+
${element.title.toUpperCase()}
+

${element.text}

+ +
+
`; + }); + let notesElm = document.getElementById("notes"); + if (notesObj.length != 0) { + notesElm.innerHTML = html; + } else { + notesElm.innerHTML = `Nothing to show! Use "Add a Note" section above to add notes.`; + } +} + +// Function to delete a note +function deleteNote(index) { + + let notes = localStorage.getItem("notes"); + if (notes == null) { + notesObj = []; + } else { + notesObj = JSON.parse(notes); + } + + notesObj.splice(index, 1); + localStorage.setItem("notes", JSON.stringify(notesObj)); + showNotes(); +} + + +let search = document.getElementById('searchTxt'); +search.addEventListener("input", function(){ + + let inputVal = search.value.toLowerCase(); + let noteCards = document.getElementsByClassName('noteCard'); + Array.from(noteCards).forEach(function(element){ + let cardTxt = element.getElementsByTagName("p")[0].innerText; + if(cardTxt.includes(inputVal)){ + element.style.display = "block"; + } + else{ + element.style.display = "none"; + } + + }) +}) diff --git a/DailyCode/basic todos with localstorage/notes.html b/DailyCode/basic todos with localstorage/notes.html index 82faa54..bc0b7f4 100644 --- a/DailyCode/basic todos with localstorage/notes.html +++ b/DailyCode/basic todos with localstorage/notes.html @@ -1,70 +1,70 @@ - - - - - - - - Notes App - - - - - - - - -
-

Welcome To Magic Notes

-
-
-
Title
-
- -
-
Add a note
-
- -
- -
-
-
-

Your Notes

-
-
-
- - - - - - - - + + + + + + + + Notes App + + + + + + + + +
+

Welcome To Magic Notes

+
+
+
Title
+
+ +
+
Add a note
+
+ +
+ +
+
+
+

Your Notes

+
+
+
+ + + + + + + + diff --git a/DynamicProgramming/Minimum path sum in Triangular Grid.cpp b/DynamicProgramming/Minimum path sum in Triangular Grid.cpp index c0a5451..709ce59 100644 --- a/DynamicProgramming/Minimum path sum in Triangular Grid.cpp +++ b/DynamicProgramming/Minimum path sum in Triangular Grid.cpp @@ -1,19 +1,19 @@ -int f(int i, int j, int &n, vector> &t, vector> &dp){ - if(i >= n) - return 0; - if(dp[i][j] != -1) - return dp[i][j]; - return dp[i][j] = t[i][j] + min(f(i+1, j, n, t, dp), f(i+1, j+1, n, t, dp)); -} -int minimumPathSum(vector>& triangle, int n){ - vector dp(n, 0); - for(int i=0; i=0; --i){ - for(int j=0; j<=i; ++j){ - dp[j] = triangle[i][j] + min(dp[j], dp[j+1]); - } - } - return dp[0]; +int f(int i, int j, int &n, vector> &t, vector> &dp){ + if(i >= n) + return 0; + if(dp[i][j] != -1) + return dp[i][j]; + return dp[i][j] = t[i][j] + min(f(i+1, j, n, t, dp), f(i+1, j+1, n, t, dp)); +} +int minimumPathSum(vector>& triangle, int n){ + vector dp(n, 0); + for(int i=0; i=0; --i){ + for(int j=0; j<=i; ++j){ + dp[j] = triangle[i][j] + min(dp[j], dp[j+1]); + } + } + return dp[0]; } \ No newline at end of file diff --git a/GAMES/Memory Block Game/ReadMe.md b/GAMES/Memory Block Game/ReadMe.md new file mode 100644 index 0000000..1e704ec --- /dev/null +++ b/GAMES/Memory Block Game/ReadMe.md @@ -0,0 +1,7 @@ +# Memory Block Game + +A simple web based memory block game. You will be briefly showed all the blocks. Every block has its copy. Block will be activated if you choose two same blocks in consecutive turns otherwise blocks will disappear. Your task is to activate all blocks with minimum turns. + +# Controls + +Only Left Mouse Button \ No newline at end of file diff --git a/GAMES/Memory Block Game/app.js b/GAMES/Memory Block Game/app.js new file mode 100644 index 0000000..d4f5aea --- /dev/null +++ b/GAMES/Memory Block Game/app.js @@ -0,0 +1,74 @@ +const game = document.querySelector(".game-container") +const newGameButton = document.querySelector(".new") +const block = document.querySelector(".game-block") +const movesText = document.querySelector(".moves") + +const picArray = ["alien", "control", "planet", "robot", "satellite", "shuttle", "ufo", "weapon", "alien", "control", "planet", "robot", "satellite", "shuttle", "ufo", "weapon"] +var selected = [] +var moves = 0 + +function shuffle(array) { + for (var i = array.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + return array +} + +function newGame() { + moves = 0 + movesText.textContent = `Total Moves : ${moves}` + + game.innerHTML = `` + const arr = shuffle(picArray) + for (let i = 0; i < 16; i++) { + game.innerHTML += `
+ +
` + } +} + +function select(object) { + var f1 = 0 + var f2 = 0 + for (let i = 0; i < object.classList.length; i++) { + if (object.classList[i] == "not") { + f1 = 1 + break + } + } + for (let i = 0; i < object.classList.length; i++) { + if (object.classList[i] == "off") { + f2 = 1 + break + } + } + if (f1 == 0 || f2 == 0) { + return + } + else { + moves++; + movesText.textContent = `Total Moves : ${moves}` + object.classList.remove("off") + object.classList.add("on") + selected.push(object) + if (selected.length == 2) { + if (selected[0].getAttribute("data-object") == selected[1].getAttribute("data-object")) { + selected[0].classList.remove("not") + selected[1].classList.remove("not") + } + else { + selected[0].classList.remove("on") + selected[0].classList.add("off") + selected[1].classList.remove("on") + selected[1].classList.add("off") + } + selected = [] + } + } +} + +newGame() +newGameButton.addEventListener("click", newGame) diff --git a/GAMES/Memory Block Game/assets/alien.png b/GAMES/Memory Block Game/assets/alien.png new file mode 100644 index 0000000..63ed9b8 Binary files /dev/null and b/GAMES/Memory Block Game/assets/alien.png differ diff --git a/GAMES/Memory Block Game/assets/control.png b/GAMES/Memory Block Game/assets/control.png new file mode 100644 index 0000000..dd4efa7 Binary files /dev/null and b/GAMES/Memory Block Game/assets/control.png differ diff --git a/GAMES/Memory Block Game/assets/planet.png b/GAMES/Memory Block Game/assets/planet.png new file mode 100644 index 0000000..642a058 Binary files /dev/null and b/GAMES/Memory Block Game/assets/planet.png differ diff --git a/GAMES/Memory Block Game/assets/robot.png b/GAMES/Memory Block Game/assets/robot.png new file mode 100644 index 0000000..2f8e2a8 Binary files /dev/null and b/GAMES/Memory Block Game/assets/robot.png differ diff --git a/GAMES/Memory Block Game/assets/satellite.png b/GAMES/Memory Block Game/assets/satellite.png new file mode 100644 index 0000000..3b0f354 Binary files /dev/null and b/GAMES/Memory Block Game/assets/satellite.png differ diff --git a/GAMES/Memory Block Game/assets/shuttle.png b/GAMES/Memory Block Game/assets/shuttle.png new file mode 100644 index 0000000..1f35f4d Binary files /dev/null and b/GAMES/Memory Block Game/assets/shuttle.png differ diff --git a/GAMES/Memory Block Game/assets/ufo.png b/GAMES/Memory Block Game/assets/ufo.png new file mode 100644 index 0000000..b0c2437 Binary files /dev/null and b/GAMES/Memory Block Game/assets/ufo.png differ diff --git a/GAMES/Memory Block Game/assets/weapon.png b/GAMES/Memory Block Game/assets/weapon.png new file mode 100644 index 0000000..c96ffd8 Binary files /dev/null and b/GAMES/Memory Block Game/assets/weapon.png differ diff --git a/GAMES/Memory Block Game/index.html b/GAMES/Memory Block Game/index.html new file mode 100644 index 0000000..ee2eef7 --- /dev/null +++ b/GAMES/Memory Block Game/index.html @@ -0,0 +1,25 @@ + + + + + + + + + Memory Block Game + + + +
+
+ +

Memory Block Game

+

Total Moves : 0

+
+
+ +
+
+ - - + + + + + + + Calculator + + + +
+ + +

+ + + + + +
+
+ Result: +
+ + + diff --git a/simple_calci/index.js b/simple_calci/index.js index 08203ce..b23d709 100644 --- a/simple_calci/index.js +++ b/simple_calci/index.js @@ -1,27 +1,27 @@ - -let result= document.getElementById("result") - -function add() -{ - let num1 = document.getElementById("num1").value - let num2 = document.getElementById("num2").value -result.textContent = parseInt(num1) + parseInt(num2) -} -function subtract() -{ - let num1 = document.getElementById("num1").value - let num2 = document.getElementById("num2").value -result.textContent = parseInt(num1) - parseInt(num2) -} -function divide() -{ - let num1 = document.getElementById("num1").value - let num2 = document.getElementById("num2").value -result.textContent = parseInt(num1) / parseInt(num2) -} -function multiply() -{ - let num1 = document.getElementById("num1").value - let num2 = document.getElementById("num2").value -result.textContent = parseInt(num1) * parseInt(num2) -} + +let result= document.getElementById("result") + +function add() +{ + let num1 = document.getElementById("num1").value + let num2 = document.getElementById("num2").value +result.textContent = parseInt(num1) + parseInt(num2) +} +function subtract() +{ + let num1 = document.getElementById("num1").value + let num2 = document.getElementById("num2").value +result.textContent = parseInt(num1) - parseInt(num2) +} +function divide() +{ + let num1 = document.getElementById("num1").value + let num2 = document.getElementById("num2").value +result.textContent = parseInt(num1) / parseInt(num2) +} +function multiply() +{ + let num1 = document.getElementById("num1").value + let num2 = document.getElementById("num2").value +result.textContent = parseInt(num1) * parseInt(num2) +} diff --git a/simple_calci/s.css b/simple_calci/s.css index 918e3e1..cf65098 100644 --- a/simple_calci/s.css +++ b/simple_calci/s.css @@ -1,31 +1,31 @@ -*{ margin: 0; -padding: 0;} - -div{ - background-color: rgba(140, 187, 225, 0.604); - border: 5px solid rgba(1, 1, 46, 0.866); - width: 500px; - height: 250px; - - - text-align: center; - margin: auto; - margin-top: 100px; - - padding-top: 100px; - -} -button{ - padding: 3px; - border-radius: 5px; -} -input{ - border-radius: 5px; - width: 70px; - height: 30px; - padding: 5px; - font-size: 20px; -} -span{ - font-size: 30px; +*{ margin: 0; +padding: 0;} + +div{ + background-color: rgba(140, 187, 225, 0.604); + border: 5px solid rgba(1, 1, 46, 0.866); + width: 500px; + height: 250px; + + + text-align: center; + margin: auto; + margin-top: 100px; + + padding-top: 100px; + +} +button{ + padding: 3px; + border-radius: 5px; +} +input{ + border-radius: 5px; + width: 70px; + height: 30px; + padding: 5px; + font-size: 20px; +} +span{ + font-size: 30px; } \ No newline at end of file