An algorithm that "solves" battleship in JavaScript