Proud of myself.

Never played a game like this or programmed. I am 32 hours in, so I am just proud of myself for making this script and it worked! I'd say it could be done better but I have not idea lol. The top part is thanks to u/Reasonable_Law3275 and u/HiEv.

export async function main(ns) {
let servers = new Set(["home"]);
for (const server of servers) {
  ns.scan(server).forEach(x => servers.add(x));
}
var File = 'iron-gym.js'
var Mem = ns.getScriptRam(File)
const target_list = Array.from(servers)
for (var i = 1; i < target_list.length; i++) {
if (ns.getHackingLevel()>ns.getServerRequiredHackingLevel(target_list[i])) {
      ns.scp(File, target_list[i])
        ns.tprint(File + " installed on " + target_list[i]);
        var SPort = ns.getServerNumPortsRequired(target_list[i])
        var Sram = ns.getServerMaxRam(target_list[i])
        var MaxScript = Math.floor(Sram/Mem)
        if (SPort >= 1) {
          if (ns.fileExists("BruteSSH.exe", "home")) {
              ns.brutessh(target_list[i]);
              ns.tprint(target_list[i] + " has SSH port opened.")
            if (SPort >= 2) { 
              if (ns.fileExists("FTPCrack.exe", "home")) {
                  ns.ftpcrack(target_list[i]);
                  ns.tprint(target_list[i] + " has FTP port opened.")
                if (SPort >= 3) { 
                  if (ns.fileExists("relaySMTP.exe", "home")) {
                      ns.relaysmtp(target_list[i]);
                      ns.tprint(target_list[i] + " has SMTP port opened.")
                    if (SPort >= 4) { 
                      if (ns.fileExists("HTTPWorm.exe", "home")) {
                        ns.httpworm(target_list[i]);
                        ns.tprint(target_list[i] + " has HTTP port opened.")
                        if (SPort == 5) { 
                          if (ns.fileExists("SQLInject.exe", "home")) {
                              ns.sqlinject(target_list[i]);
                              ns.tprint(target_list[i] + " has SQL port opened.")
                          }
                        }      
                      }
                    }
                  }
                }    
              }
            }          
          }  
        }  
        if (ns.hasRootAccess(target_list[i]) == false) {
          try {ns.nuke(target_list[i])} catch { ns.tprint("Nuke Failed") }
          ns.tprint(target_list[i] + " was Nuked.")
        }
        if (ns.hasRootAccess(target_list[i])) {
          ns.tprint("Has Root Access to " + target_list[i] + ".")
          if (MaxScript>0){
            ns.exec(File, target_list[i], MaxScript)
            ns.tprint(File + " is running " + MaxScript + " time.")
            await ns.sleep(1000);
          }
        }
    }    
}
}