{"id":42858,"student_id":1976,"content":"// 預設程式\nwhen(\"click\", function () {\n guess(prompt());\n});\n\nvar list = []\n\nfor (var i = 123; i \u003c= 9876; i++) {\n var t = i.toString()\n if (t.length \u003c= 3) {\n t = '0' + t\n }\n if (t[0] != t[1] \u0026\u0026\n t[0] != t[2] \u0026\u0026\n t[0] != t[3] \u0026\u0026\n t[1] != t[2] \u0026\u0026\n t[1] != t[3] \u0026\u0026\n t[2] != t[3]) {\n list.push(t)\n }\n}\n\nconsole.log(list.length)\n\n// 根據猜的結果移除不可能的選項\n\n// for (var i = 0; i \u003c list.length; i++) {\n// var g = list[i]\n// var result = guess(g)\n// console.log(result)\n// if (result.a == 4) {\n// break;\n// }\n// }\nwhile (list.length \u003e 0) {\n var g = list[0]\n var result = guess(g)\n\n if (result.a == 4) {\n break;\n }\n\n for (var i = 0; i \u003c list.length; i++) {\n var d = diff(list[i],g)\n if (d.a != result.a || d.b != result.b) {\n list.splice(i, 1)\n }\n }\n}\n\n// 判斷兩組相似,返回 a、b\nfunction diff(num1, num2) {\n var a = 0;\n var b = 0;\n\n for (var i = 0; i \u003c 4; i++) {\n var idx = num1.indexOf(num2[i])\n if (idx != -1) {\n if (idx == i) {\n a++\n } else {\n b++\n }\n }\n }\n\n return {\n a: a, b: b\n }\n}","created_at":"2018-09-18T22:41:07.213+08:00","updated_at":"2019-11-11T00:20:55.580+08:00","name":"1A2B 解題 副本","language":"javascript","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/42858/d7350531ceb2fe999d875cf174af0b78.jpg"},"parent_id":33939,"plugin":"setBackdrop('black');\n\nvar guess = (function () {\n\n var answer = ''; // 正確答案\n var logs = []; // 記錄玩家所猜的數字與結果\n\n // 產生答案\n var numbers = '0123456789';\n for (var i = 0; i \u003c 4; i++) {\n var rand = Math.floor(numbers.length * Math.random());\n answer += numbers[rand];\n numbers = numbers.slice(0, rand) + numbers.slice(rand + 1);\n }\n\n function guess(num) {\n var a = 0;\n var b = 0;\n for (var i = 0; i \u003c 4; i++) {\n var idx = answer.indexOf(num[i]);\n if (idx != -1) i == idx ? a++ : b++;\n }\n logs.unshift({num: num, a: a, b: b});\n return { a: a, b: b }\n }\n\n forever(function(){\n for (var i=0; i\u003clogs.length \u0026\u0026 i\u003c100; i++) {\n var l = logs[i];\n var s = `${logs.length - i}. ${l.num} ${l.a}A${l.b}B`;\n // 補上對齊用的空格\n while(s.length \u003c 15) s = ' ' + s;\n print(s, 30, 20 + 30*i, l.a == 4 ? 'gold' : 'white', 25, 'monospace');\n }\n });\n\n return guess;\n\n})();","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":334,"hashid":"npmswg4p","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":752226,"file_name":"1.wav","project_id":42858,"asset_id":74916,"created_at":"2018-09-18T22:41:07.224+08:00","updated_at":"2018-09-18T22:41:07.224+08:00"},{"id":752227,"file_name":"0.wav","project_id":42858,"asset_id":74915,"created_at":"2018-09-18T22:41:07.227+08:00","updated_at":"2018-09-18T22:41:07.227+08:00"},{"id":752228,"file_name":"2.png","project_id":42858,"asset_id":74914,"created_at":"2018-09-18T22:41:07.229+08:00","updated_at":"2018-09-18T22:41:07.229+08:00"},{"id":752229,"file_name":"1.svg","project_id":42858,"asset_id":74913,"created_at":"2018-09-18T22:41:07.231+08:00","updated_at":"2018-09-18T22:41:07.231+08:00"},{"id":752230,"file_name":"0.png","project_id":42858,"asset_id":74912,"created_at":"2018-09-18T22:41:07.233+08:00","updated_at":"2018-09-18T22:41:07.233+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦