This file contains hidden or 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
| #!/usr/bin/env python3 | |
| """ | |
| Conway's Game of Life (revisited) on an 8x8 toroidal board. | |
| - Toroidal wrap-around: top↔bottom and left↔right edges are connected. | |
| - Uses the corrected initial configuration provided by you. | |
| - Prints the initial board + next 3 generations (4 total). | |
| """ | |
| SIZE = 8 # 8x8 board |
This file contains hidden or 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
| function countLetter(str){ | |
| let transStr=str.split(''); | |
| let count=0; | |
| let r=''; | |
| let currChar=transStr[0]; | |
| for(let i=0;i<=transStr.length;i++){ | |
| let c=transStr[i]; | |
| if(c!=currChar){ | |
| r+=`${currChar}${count}`; |
This file contains hidden or 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
| class Node { | |
| constructor(data) { | |
| this.data = data; | |
| this.link = null; | |
| } | |
| } | |
| class SingleLinkedList { | |
| constructor() { | |
| this.head = null; | |
| this.tail = null; |
This file contains hidden or 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
| class Node { | |
| constructor(data) { | |
| this.prev = null; | |
| this.data = data; | |
| this.next = null; | |
| } | |
| } | |
| class linkedList { | |
| constructor() { |
This file contains hidden or 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
| const pattern = "010"; | |
| const source = "amazing"; | |
| function patternSourceMatch(pattern, source) { | |
| let resp = ""; | |
| const vowels = new Set(["a", "e", "i", "o", "u", "y"]); | |
| // Convert source to binary string based on vowels/consonants | |
| for (let char of source) { | |
| resp += vowels.has(char) ? "0" : "1"; |
This file contains hidden or 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
| function transformArray(a) { | |
| const b = []; | |
| for (let i = 0; i < a.length; i++) { | |
| const left = a[i - 1] ?? 0; | |
| const current = a[i] ?? 0; | |
| const right = a[i + 1] ?? 0; | |
| b.push(left + current + right); | |
| } |
This file contains hidden or 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
| // your code goes here | |
| for(let i=5;i>=0;i--){ | |
| let row=''; | |
| for(let j=0;j<i;j++){ | |
| row+=j | |
| } | |
| console.log(row); | |
| } |
This file contains hidden or 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
| function countPairs(ar) { | |
| var obj = {}; | |
| ar.forEach(item => { | |
| obj[item] = obj[item] ? obj[item] + 1 : 1; | |
| }); | |
| return Object.values(obj).reduce((acc, curr) => { | |
| acc += Math.floor(curr / 2) | |
| return acc; |
This file contains hidden or 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
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf8'); | |
| // Your code here! | |
| function multiply(a, b) { | |
| return a / (1 / b); | |
| } | |
| console.log(multiply(2,3)); |
This file contains hidden or 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
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf8'); | |
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf8'); | |
| // Function to reverse string | |
| // function ReverseString(str) { | |
| // return str.split('').reverse().join('') | |
| // } | |