更無聊的人做什么:檢查模仿游戲的答案

一個(gè)月前看到琉璃心仙人先生的《論無聊的人做什么:模仿游戲》,頓覺有趣。對(duì)于這種混雜纏繞在一起的問題,我立刻產(chǎn)生一個(gè)疑問:

答案是唯一的嗎?

如果我來設(shè)計(jì)這類題目,我的做法是先列一個(gè)答案,按照這個(gè)答案來設(shè)計(jì)題目。但是這樣做能保證它的唯一性嗎?


原作者利用學(xué)了一個(gè)月的JAVA暴力求解這個(gè)問題。我作為非專業(yè)人員,用了一個(gè)月時(shí)間來寫下面的一段非JAVA函數(shù),親手驗(yàn)證一下它的唯一性。結(jié)果發(fā)現(xiàn)它真的是只有一個(gè),不由得對(duì)設(shè)計(jì)題目的牛逼感到由衷的敬佩。

結(jié)果:

ansLst=Tuples[{1,2,3,4},10];

Table[testFun[ansLst[[i]]],{i,1,Length@ansLst}];

Union@%

結(jié)果除了False就是這個(gè){2, 3, 1, 3, 1, 3, 4, 1, 2, 1}(非程序員從1開始數(shù)數(shù)。)

即BCACACDABA。

附錄函數(shù):

testFun[x_,mode_:"noDebug"]:=Module[{rule},

rule=Thread[{"A","B","C","D"}->{1,2,3,4}];


option2={"C","D","A","B"};

option2A=option2/.rule;

test2=x[[5]]==option2A[[x[[2]]]];

If[mode=="Debug",Print[test2]];

If[test2==False,Return[test2]];


option3={x[[3]],x[[6]],x[[2]],x[[4]]};

test3=Module[

{lst1,lst2},

lst1=option3[[x[[3]]]];

lst2=Drop[option3,{x[[3]]}];

(Equal@@lst2)&&(lst1!=lst2[[1]])

];

If[mode=="Debug",Print["3->"test3]];

If[test3==False,Return[test3]];


option4={

{x[[1]],x[[5]]},

{x[[2]],x[[7]]},

{x[[1]],x[[9]]},

{x[[6]],x[[10]]}

};

test4=Module[{lst1,lst2},

lst1=option4[[x[[4]]]];

lst2=Drop[option4,{x[[4]]}];

(Equal@@lst1)&&And@@(Unequal@@@lst2)

];

If[mode=="Debug",Print["4->",test4]];

If[test4==False,Return[test4]];


option5={x[[8]],x[[4]],x[[9]],x[[7]]};

test5=Module[{lst1,lst2},

lst1=option5[[x[[5]]]];

lst2=Drop[option5,{x[[5]]}];

(x[[5]]==lst1)&&And@@(Unequal[x[[5]],#]&/@lst2)

];

If[mode=="Debug",Print["5->",test5]];

If[test5==False,Return[test5]];


option6={

{x[[2]],x[[4]]},

{x[[1]],x[[6]]},

{x[[3]],x[[10]]},

{x[[5]],x[[9]]}

};

test6=Module[{lst1,lst2},

option6A=Append[#,x[[8]]]&/@option6;

lst1=option6A[[x[[6]]]];

lst2=Drop[option6A,{x[[6]]}];

condition1=Equal@@lst1;

condition2=And@@(Not/@(Equal@@@lst2));

condition1&&condition2

];

If[mode=="Debug",Print["6->",test6]];

If[test6==False,Return[test6]];


option7={"C","B","A","D"};

test7=Module[{},

option7A=option7/.rule;

countLst=Count[x,#]&/@{1,2,3,4};

xNumMin=Min[countLst];

If[Count[countLst,xNumMin]==1,

Position[countLst,xNumMin][[1,1]]==option7A[[x[[7]]]],

False]

];

If[mode=="Debug",Print[test7]];

If[test7==False,Return[test7]];


option8={x[[7]],x[[5]],x[[2]],x[[10]]};

test8=Module[{lst1,lst2},

lst1=option8[[x[[8]]]];

lst2=Drop[option8,{x[[8]]}];

condition1=Abs[lst1-x[[1]]]!=1;

condition2=And@@(Abs[#-x[[1]]]==1&/@lst2);

condition1&&condition2

];

If[mode=="Debug",Print[test8]];

If[test8==False,Return[test8]];


option9={x[[6]],x[[10]],x[[2]],x[[9]]};

test9=Module[{lst1,lst2},

lst1=option9[[x[[9]]]];

lst2=Drop[option9,{x[[9]]}];

condition1=x[[1]]==x[[6]];

condition2=lst1==x[[5]];

condition3=((#==x[[5]])&/@lst2);

condition1!=condition2&&(Equal@@condition3)&&condition1==condition3[[1]]

];

If[mode=="Debug",Print[test9]];

If[test9==False,Return[test9]];


option10={3,2,4,1};

test10:=Module[{xMin,xMax,lst},

lst=Count[x,#]&/@{1,2,3,4};

{xMin,xMax}={Min@lst,Max@lst};

(xMax-xMin)==option10[[x[[10]]]]

];

If[mode=="Debug",Print[test10]];

If[test10==False,Return[test10]];

x

]

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • =========================================================...
    lavor閱讀 3,649評(píng)論 0 5
  • 不支持上傳文件,所以就復(fù)制過來了。作者信息什么的都沒刪。對(duì)前端基本屬于一竅不通,所以沒有任何修改,反正用著沒問題就...
    全棧在路上閱讀 2,068評(píng)論 0 2
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,568評(píng)論 19 139
  • 今天寫策略模式的Demo時(shí),發(fā)現(xiàn)子類的對(duì)象可以訪問到父類的protected對(duì)象,查了一下才反應(yīng)過來原來是獲得了包...
    xzt閱讀 196評(píng)論 0 0
  • 本書講述了創(chuàng)業(yè)過程中所會(huì)遇到的問題以及相應(yīng)的解決方法。作者一共從九個(gè)章節(jié)來講述從創(chuàng)立公司的最初動(dòng)力困難到最后的以1...
    等好風(fēng)吹來閱讀 1,312評(píng)論 1 1

友情鏈接更多精彩內(nèi)容