{"id":237812,"student_id":3469,"content":"// 可以修改預設密碼來測試\n\nvar chars = ' abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; //密碼可能的字元\nvar pops = []; //存放要猜的密碼\n\nvar passweerd = '';\n\nfor (var n = 0; n \u003c 13; n++) {\n var randdd = Math.floor(Math.random() * 63);\n passweerd += chars[randdd];\n}\n\n\n\nsetPassword(passweerd);\n\n\n\nfor (var k = 0; k \u003c 20; k++) {\n var guess = '';// guest number\n for (var i = 0; i \u003c 13; i++) {\n var rand = Math.floor(Math.random() * 63);\n guess += chars[rand];\n }\n pops.push(guess);\n }\n\n\n// 按下空白按鍵來破解金庫\non('keydown', 'space', nextGeneration);\n\nfunction nextGeneration () {\n // 學生遊戲試玩,開始實作時註解或移除\n // var s = prompt('請輸入 13 個由英文字母大小寫、數字、空白所組成的密碼');\n // var r = password(s);\n // alert(`你輸入的密碼中只有 ${r} 個字是正確的!`);\n var arr = [];\n for (var j = 0; j \u003c 20; j++) {\n \n \n arr.push({score: password(pops[j]), gene: pops[j]});\n \n arr.sort(function(a, b){\n return b.score - a.score;\n });\n \n }\n // console.log(arr);\n \n var parentA = arr[0].gene;\n var parentB = arr[1].gene;\n \n for (var l = 0; l \u003c 20; l++) {\n pops[l] = crossover(parentA, parentB);\n }\n}\n\n// 將兩組密碼進行組合\nfunction crossover (a, b) {\n var child_gene = '';\n for (var m = 0; m \u003c 13; m++) {\n if (Math.random() \u003c 0.1) {\n var rand = Math.floor(Math.random() * 63);\n child_gene += chars[rand];\n } else {\n if (Math.random() \u003c 0.5) {\n child_gene += a[m];\n } else {\n child_gene += b[m];\n }\n }\n \n }\n return child_gene;\n}\n\n\n\n\n\n\n\n","created_at":"2021-03-21T13:32:54.306+08:00","updated_at":"2021-03-21T15:00:54.140+08:00","name":"遺傳演算法(預設版) 副本","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/237812/7dcf4818114883d56bda8acdf5af7a66.jpg"},"parent_id":150101,"plugin":"(function () {\n \n setBackdrop('hacker1.jpg', 0, 0, 640, 480);\n\n var logs = [];\n var key = '';\n var gameOver = false;\n\n function password (str) {\n\n var count = 0;\n for (var i = 0; i \u003c key.length; i++) {\n if (key[i] === str[i]) count++;\n }\n \n if (!gameOver) {\n logs.unshift([str, count]);\n }\n \n if (!gameOver \u0026\u0026 str.length == key.length \u0026\u0026 count === key.length) {\n gameOver = true;\n setBackdrop('hacker2.jpg', 0, 0, 640, 480);\n createSound('beep.wav');\n setTimeout(function () {\n setBackdrop('hacker3.jpg', 0, 0, 640, 480);\n createSound('unlock.wav');\n }, 1000);\n }\n \n return count;\n }\n \n function setPassword (str) {\n key = str;\n }\n \n forever(function(){\n for (var i=0; i\u003c14 \u0026\u0026 i\u003clogs.length; i++) {\n print(logs.length - i, 50, 35 + 20*i, '#aaa', 14);\n print(logs[i][1], 100, 35 + 20*i, logs[i] == key ? 'gold' : 'gold', 16);\n print(logs[i][0], 130, 35 + 20*i, logs[i] == key ? 'gold' : 'white', 16);\n }\n });\n \n window.password = password;\n window.setPassword = setPassword;\n\n})();\n\nsetPassword('I love Koding');\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":174,"hashid":"6rps9rwdn","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":4337243,"file_name":"beep.wav","project_id":237812,"asset_id":216286,"created_at":"2021-03-21T13:32:54.310+08:00","updated_at":"2021-03-21T13:32:54.310+08:00"},{"id":4337244,"file_name":"unlock.wav","project_id":237812,"asset_id":216287,"created_at":"2021-03-21T13:32:54.311+08:00","updated_at":"2021-03-21T13:32:54.311+08:00"},{"id":4337245,"file_name":"hacker1.jpg","project_id":237812,"asset_id":216288,"created_at":"2021-03-21T13:32:54.312+08:00","updated_at":"2021-03-21T13:32:54.312+08:00"},{"id":4337246,"file_name":"hacker3.jpg","project_id":237812,"asset_id":216289,"created_at":"2021-03-21T13:32:54.313+08:00","updated_at":"2021-03-21T13:32:54.313+08:00"},{"id":4337247,"file_name":"hacker2.jpg","project_id":237812,"asset_id":216290,"created_at":"2021-03-21T13:32:54.314+08:00","updated_at":"2021-03-21T13:32:54.314+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦