{"id":28917,"student_id":10,"content":"// 人、狼、羊、菜\nvar statuss = [[false, false, false, false]];\nvar logs = [];\n\nfunction checkSafe (statuss) {\n if (statuss[0] != statuss[1] \u0026\u0026 statuss[1] == statuss[2]) return false;\n if (statuss[0] != statuss[2] \u0026\u0026 statuss[2] == statuss[3]) return false;\n return true;\n}\n\nfunction checkRepeat (logs, clone) {\n for (var i=0; i\u003clogs.length; i++) {\n var l = logs[0];\n if (l[0] == clone[0] \u0026\u0026 l[1] == clone[1] \u0026\u0026\n l[2] == clone[2] \u0026\u0026 l[3] == clone[3]) {\n return true;\n }\n }\n return false;\n}\n\nfunction showSteps (s) {\n while(s != undefined) {\n console.log(s.toString());\n s = s.from;\n }\n}\n\nforever(function(){\n if (statuss.length \u003c= 0) return;\n \n var s = statuss.shift();\n logs.push(s);\n \n for (var i=1; i\u003c3; i++) {\n if (s[i] == s[i]) {\n var clone = s.slice();\n clone[0] = !clone[0];\n clone[i] = !clone[i];\n if (checkSafe(clone) \u0026\u0026 !checkRepeat(logs, clone)) {\n clone.form = s;\n statuss.push(clone);\n }\n if (clone[0] \u0026\u0026 clone[1] \u0026\u0026 clone[2] \u0026\u0026 clone[3]) {\n showSteps(clone);\n }\n }\n }\n var clone = s.slice();\n clone[0] = !clone[0];\n if (checkSafe(clone) \u0026\u0026 !checkRepeat(logs, clone)) {\n clone.form = s;\n statuss.push(clone);\n }\n if (clone[0] \u0026\u0026 clone[1] \u0026\u0026 clone[2] \u0026\u0026 clone[3]) {\n showSteps(clone);\n }\n});","created_at":"2018-05-16T11:28:53.813+08:00","updated_at":"2019-10-21T09:36:32.264+08:00","name":"River crossing problem","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/28917/fd1ac05835b665cf0d7e3c5532c7c2d7.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":308,"hashid":"9ygs5neq","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦