TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Cheat at Rock-Paper-Scissors-Lizard-Spock

85 点作者 HeinZawHtet超过 5 年前

4 条评论

geocar超过 5 年前
<p><pre><code> &amp;&#x2F;&quot;ki&quot;? </code></pre> It&#x27;s incredible how seven little characters can pack so much power, but this level of cuteness also demands some explanation as to why it&#x27;s correct (given the input domain).<p>The first thing we might observe is that every input has two possible outputs, and the output domain is the same as the input domain. That means that if we select our outputs carefully, we may be able to find a property of the input that differentiates them.<p><pre><code> q){x!x in&#x2F;:\:k}distinct raze k:string`Rock`Spock`Paper`Lizard`Scissors R| 10000b o| 11001b c| 11001b k| 11000b S| 01001b p| 01100b P| 00100b a| 00110b e| 00100b r| 00111b L| 00010b i| 00011b z| 00010b d| 00010b s| 00001b </code></pre> We can see several options: &quot;k&quot; gets us Paper, &quot;i&quot; gets us Rock, &quot;a&quot; gets us Scissors, &quot;p&quot; gets us &quot;Lizard&quot;. There are a few red herrings though: &quot;S&quot; doesn&#x27;t get us any single output (Scissors and Spock don&#x27;t have a shared winning response). The pairs I can see that differentiate all states are &quot;ki&quot;, &quot;ka&quot;, &quot;ip&quot;. Let us use &quot;ki&quot;:<p><pre><code> Roc&lt;k&gt; | Spock &lt;Paper&gt; Spoc&lt;k&gt; |&lt;Paper&gt; Lizard Paper | Lizard Scissors L&lt;i&gt;zard | Scissors&lt;Rock&gt; Sc&lt;i&gt;ssors|&lt;Rock&gt; Spock </code></pre> The only remaining item we can choose (Lizard or Scissors), and if we choose the latter then our game can play traditional Rock-Paper-Scissors as well!<p><pre><code> `Paper`Rock`Scissors@&amp;&#x2F;&quot;ki&quot;? </code></pre> Of course if you&#x27;re not using q, you could use a different mapping function. Many of the responses looked at the lengths or a critical bit of a hash (like md5), all with the aims of producing this kind of compression function, and this isn&#x27;t uncommon in high performance systems, but if you&#x27;re going to depend on such a function, you should explain carefully how you came up with these magic characters so if someone wants to extend the game in the future they know how to reconstruct your function.
reaperducer超过 5 年前
If nothing else, that was a very satisfying read because it shows the incredible diversity of programming languages available today.
giancarlostoro超过 5 年前
I am still wondering how the two Perl ones work with two missing words in the code.
评论 #21798276 未加载
评论 #21800677 未加载
评论 #21798556 未加载
tedunangst超过 5 年前
Apparently you don&#x27;t actually need to print &quot;Rock or Spock&quot; although it sounded like that&#x27;s a requirement.