{"id":48593,"student_id":208,"content":"// 可以修改預設密碼來測試\n// setPassword('password');\n\n\n\n// var chars = ' qazwsxedcrfvtgbyhnujmiklopQAZWSXEDCRFVTGBYHNUJMIKOLP';\nvar chars = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n\nvar pops = [];\nconsole.log(chars.length)\n// 不斷嘗試密碼並將分數高的排在前面,產生下一代的密碼\n\nfor (var j = 0; j \u003c 20; j++) {\n var gens = '';\n for (var i = 0; i \u003c 23; i++) {\n var g = chars[Math.floor(Math.random()*53)];\n gens += g;\n }\n pops.push(gens);\n\n}\nconsole.log(pops);\n\npops.sort(function(a, b) {\n return password(b) - password(a);\n});\n\nforever(function() {\n var children = [];\n pops.sort(function(a, b) {\n return password(b)-password(a)\n })\n for (var i = 0; i \u003c 20; i++) {\n var child = crossover(pops[0], pops[1]);\n children.push(child);\n }\n pops = children;\n});\n\nconsole.log(pops[0]);\nconsole.log(pops[1]);\nconsole.log(crossover(pops[0], pops[1]));\n// 將兩組密碼進行組合\nfunction crossover (a, b) {\n var gens = '';\n for (var i = 0; i \u003c 23; i++) {\n var n = Math.random();\n var g;\n if (n \u003c 0.05) {\n g = chars[Math.floor(Math.random()*53)];\n } else if (n \u003c 0.5025) {\n g = a[i]\n } else {\n g = b[i]\n }\n\n gens += g;\n }\n return gens\n\n\n\n\n\n\n\n}","created_at":"2018-11-11T10:15:56.762+08:00","updated_at":"2019-11-09T01:20:04.955+08:00","name":"遺傳演算法 副本","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/48593/f2598c4f86e6af95d8e6d8a6ed84b34c.jpg"},"parent_id":33940,"plugin":"setBackdrop('hacker1.jpg', 0, 0, 640, 480);\n\nvar game = (function () {\n \n var log = [];\n var key = 'I love Koding very much';\n var gameOver = false;\n \n when('click', function () {\n if (prompt('請輸入密碼?') == key) {\n setBackdrop('hacker2.jpg', 0, 0, 640, 480);\n setTimeout(function() {\n setBackdrop('hacker3.jpg', 0, 0, 640, 480);\n stop();\n }, 1000);\n }\n });\n \n function password (passwd) {\n if (gameOver) return;\n if (passwd == key) gameOver = true;\n \n log.unshift(passwd);\n var count = 0;\n for (var i = 0; i \u003c key.length; i++) {\n if (key[i] == passwd[i]) count++;\n }\n return count;\n }\n \n function setPassword (passwd) {\n key = passwd;\n }\n \n forever(function(){\n for (var i=0; i\u003c14 \u0026\u0026 i\u003clog.length; i++) {\n print(log[i], 50, 35 + 20*i, log[i] == key ? 'gold' : 'white');\n }\n });\n\n return {\n password: password,\n setPassword: setPassword\n }\n})();\n\nvar password = game.password;\nvar setPassword = game.setPassword;\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":69,"hashid":"d5msqqnm","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":871448,"file_name":"hacker2.jpg","project_id":48593,"asset_id":74924,"created_at":"2018-11-11T10:15:56.773+08:00","updated_at":"2018-11-11T10:15:56.773+08:00"},{"id":871449,"file_name":"hacker3.jpg","project_id":48593,"asset_id":74923,"created_at":"2018-11-11T10:15:56.775+08:00","updated_at":"2018-11-11T10:15:56.775+08:00"},{"id":871450,"file_name":"hacker1.jpg","project_id":48593,"asset_id":74922,"created_at":"2018-11-11T10:15:56.778+08:00","updated_at":"2018-11-11T10:15:56.778+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦