Open InfernoIV opened 1 month ago
Types:
"Find Largest Prime Factor" "Subarray with Maximum Sum" "Total Ways to Sum" "Total Ways to Sum II" "Spiralize Matrix" "Array Jumping Game" "Array Jumping Game II" "Merge Overlapping Intervals" "Generate IP Addresses" "Algorithmic Stock Trader I" "Algorithmic Stock Trader II" "Algorithmic Stock Trader III" "Algorithmic Stock Trader IV" "Minimum Path Sum in a Triangle" "Unique Paths in a Grid I" "Unique Paths in a Grid II" "Shortest Path in a Grid" "Sanitize Parentheses in Expression" "Find All Valid Math Expressions" "HammingCodes: Integer to Encoded Binary" "HammingCodes: Encoded Binary to Integer" "Proper 2-Coloring of a Graph" "Compression I: RLE Compression" "Compression II: LZ Decompression" "Compression III: LZ Compression" "Encryption I: Caesar Cipher" "Encryption II: Vigenère Cipher"
Mandatory: 20 GB
Optional / not used: 11 GB
` export function main(ns) { //file extension to search for const extension = “.cct” //for each server for(let server of scanServers(ns)) { //for each coding contract for(let file of ns.ls(server,extension) { //attempt coding contract attemptCodingContract(ns,file,server) } } }
function attemptCodingContract(ns, filename, hostname) { //create variable to save answer into var answer //get the contract type let type = ns.codingcontract.getContractType() //depending on type, check which function to use switch(type) { case "": answer = a; break case "": answer = b; break default: log(ns,1,warning,"attemptCodingContract - Unhandled type: " + type); return } //attempt answer let reward = ns.codingcontract.attempt(answer, filename, hostname) //if we are successful if(reward != "") { log(ns,1,success,"Contract solved successfully! Reward: " + reward) } else { log(ns,1,error,"Failed contract: " + type) } }
//actual code solving functions function a (data) { } //TODO function b (data) { } //TODO `