• Mar 22, 2022 •LeifMessinger
0 likes • 1 view
//QM Helper by Leif Messinger //Groups numbers by number of bits and shows their binary representations. //To be used on x.com const minterms = prompt("Enter your minterms separated by commas").split(",").map(x => parseInt(x.trim())); const maxNumBits = minterms.reduce(function(a, b) { return Math.max(a, Math.log2(b)); }); const bitGroups = []; for(let i = 0; i < maxNumBits; ++i){ bitGroups.push([]); } for(const minterm of minterms){ let outputString = (minterm+" "); //Count the bits let count = 0; for (var i = maxNumBits; i >= 0; --i) { if((minterm >> i) & 1){ ++count; outputString += "1"; }else{ outputString += "0"; } } bitGroups[count].push(outputString); } document.body.textContent = ""; document.body.style.setProperty("white-space", "pre"); for(const group of bitGroups){ for(const outputString of group){ document.body.textContent += outputString + "\r\n"; } }
• Nov 16, 2023 •LeifMessinger
0 likes • 7 views
function filePath(file){ let folders = file.getParents(); const parents = []; function makePathString(folderArray){ let path = ""; folderArray.forEach((folder)=>{ path += "/" + folder.getName(); }); return path; } while (folders.hasNext()) { const folder = folders.next(); //This should hopefully remove that folder from the iterator parents.unshift(folder); } return makePathString(parents); } function myFunction() { const myEmail = Session.getEffectiveUser().getEmail(); Logger.log("My email is " + myEmail); // Log the name of every file in the user's Drive. var fileIterator = DriveApp.getFiles(); const files = []; //List of [File, size] entries const filesMaxSize = 10; while (fileIterator.hasNext()) { var file = fileIterator.next(); const owner = file.getOwner(); //Only files I own if((!(owner)) || (!(owner.getEmail)) || owner.getEmail() != myEmail){ continue; } const entry = [file, file.getSize()]; function slideUp(arr, index){ //Let's keep sliding it up so we don't have to sort it at the end. for(let i = index; i > 0; --i){ //Stops at 1 const nextFile = arr[i-1]; if(nextFile[1] > entry[1]){ break; }else{ //Swap with the next file to slide the file up const temp = arr[i]; arr[i] = arr[i - 1]; arr[i - 1] = temp; } } } if(files.length < filesMaxSize){ files.push(entry); slideUp(files, files.length - 1); }else{ if(entry[1] > files[files.length - 1][1]){ //If it's bigger than the smallest file in the list. files[files.length - 1] = entry; //Replace the smallest file slideUp(files, files.length - 1); //Slide it up } } } for(let i = 0; i < filesMaxSize; ++i){ const file = files[i][0]; const size = files[i][1]; Logger.log(size + "\t" + filePath(file) + "/" + file.getName() + "\t" + file.getOwner().getName()); } }
• Nov 18, 2022 •AustinLeath
0 likes • 2 views
var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
• Nov 19, 2022 •CodeCatch
class LinkedList { constructor() { this.nodes = []; } get size() { return this.nodes.length; } get head() { return this.size ? this.nodes[0] : null; } get tail() { return this.size ? this.nodes[this.size - 1] : null; } insertAt(index, value) { const previousNode = this.nodes[index - 1] || null; const nextNode = this.nodes[index] || null; const node = { value, next: nextNode }; if (previousNode) previousNode.next = node; this.nodes.splice(index, 0, node); } insertFirst(value) { this.insertAt(0, value); } insertLast(value) { this.insertAt(this.size, value); } getAt(index) { return this.nodes[index]; } removeAt(index) { const previousNode = this.nodes[index - 1]; const nextNode = this.nodes[index + 1] || null; if (previousNode) previousNode.next = nextNode; return this.nodes.splice(index, 1); } clear() { this.nodes = []; } reverse() { this.nodes = this.nodes.reduce( (acc, { value }) => [{ value, next: acc[0] || null }, ...acc], [] ); } *[Symbol.iterator]() { yield* this.nodes; } } const list = new LinkedList(); list.insertFirst(1); list.insertFirst(2); list.insertFirst(3); list.insertLast(4); list.insertAt(3, 5); list.size; // 5 list.head.value; // 3 list.head.next.value; // 2 list.tail.value; // 4 [...list.map(e => e.value)]; // [3, 2, 1, 5, 4] list.removeAt(1); // 2 list.getAt(1).value; // 1 list.head.next.value; // 1 [...list.map(e => e.value)]; // [3, 1, 5, 4] list.reverse(); [...list.map(e => e.value)]; // [4, 5, 1, 3] list.clear(); list.size; // 0
• Jan 26, 2023 •AustinLeath
0 likes • 5 views
function printHeap(heap, index, level) { if (index >= heap.length) { return; } console.log(" ".repeat(level) + heap[index]); printHeap(heap, 2 * index + 1, level + 1); printHeap(heap, 2 * index + 2, level + 1); } //You can call this function by passing in the heap array and the index of the root node, which is typically 0, and level = 0. let heap = [3, 8, 7, 15, 17, 30, 35, 2, 4, 5, 9]; printHeap(heap,0,0)
• Mar 9, 2021 •LeifMessinger
alert("bruh")