{"ScriptPreparationCode":"function gaussian(mean, variance) {\r\n return Math.sqrt(-2 * variance * Math.log(Math.random())) *\r\n Math.cos(2 * Math.PI * Math.random()) \u002B mean;\r\n}","TestCases":[{"Name":"Algorithm 1","Code":"const n = 20;\r\nconst columns = 4*n;\r\nconst rows = 3*n;\r\nconst cellWidth = 640/columns;\r\nconst matrix = {};\r\n\r\nlet population = rows*columns;\r\nconst numParents = Math.ceil(0.2*rows*columns);\r\n\r\nfor (let i = 0; i \u003C rows; i\u002B\u002B) {\r\n matrix[i] = {};\r\n for (let j = 0; j \u003C columns; j\u002B\u002B) {\r\n matrix[i][j] = 0;\r\n }\r\n}\r\n\r\nlet p = 0;\r\nwhile (p \u003C numParents) {\r\n try {\r\n for (let i = 0; i \u003C rows; i\u002B\u002B) {\r\n for (let j = 0; j \u003C columns; j\u002B\u002B) {\r\n if (p \u003C numParents) {\r\n if (matrix[i][j] === 1) {\r\n continue;\r\n }\r\n if (Math.abs(gaussian(0,columns) \u003E j)) {\r\n matrix[i][j] = 1;\r\n \u002B\u002Bp;\r\n }\r\n } else {\r\n throw \u0022\u0022;\r\n }\r\n }\r\n }\r\n } catch (e) {}\r\n}","IsDeferred":false},{"Name":"Algorithm 2","Code":"const n = 20;\r\nconst columns = 4*n;\r\nconst rows = 3*n;\r\nconst cellWidth = 640/columns;\r\nconst matrix = {};\r\n\r\nfor (let i = 0; i \u003C rows; i\u002B\u002B) {\r\n matrix[i] = {}\r\n for (let j = 0; j \u003C columns; j\u002B\u002B) {\r\n matrix[i][j] = 0\r\n }\r\n}\r\n\r\nlet population = rows*columns;\r\nlet numParents = Math.ceil(0.2*rows*columns);\r\n\r\nfor (let i = 0; i \u003C numParents; i\u002B\u002B) {\r\n let success = false;\r\n while (!success) {\r\n let columnIndex = null;\r\n while (columnIndex === null) {\r\n const rand = Math.floor(Math.abs(gaussian(0, columns)));\r\n console.log(rand);\r\n if (rand \u003C columns) {\r\n columnIndex = rand\r\n }\r\n }\r\n const rowIndex = Math.floor(Math.random()*rows);\r\n if (matrix[rowIndex][columnIndex] === 0) {\r\n matrix[rowIndex][columnIndex] = 1;\r\n success = true;\r\n }\r\n }\r\n}","IsDeferred":false}]}