TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Obfuscated Game of Life in 9 lines of C

66 pointsby jackhammer2022over 11 years ago

8 comments

Aardwolfover 11 years ago
And to run this program in a <i>single line of bash</i> on Unix systems (does create a .&#x2F;a.out file):<p><pre><code> echo &#x27;int main(){int _[2048],O=(int)&amp;O,__=~__+__;while((__=-~__)^2048)__[_]=(O=(O*0x41C64E6D+12345)&amp;0x7fffffff)&amp;1024?1&lt;&lt;5:0;while(usleep(&#x27;&quot;&#x27;&quot;&#x27;d&#x27;&quot;&#x27;&quot;&#x27;&lt;&lt;&#x27;&quot;&#x27;&quot;&#x27;\n&#x27;&quot;&#x27;&quot;&#x27;),__+=~__){while((__=-~__)^8192){if(_[((__&gt;&gt;2)+2048+&quot;\x01?@A&quot;[__%4])%04000]&amp;1&lt;&lt;5)*(_+(__&gt;&gt;2))=-~_[__&gt;&gt;2];if(_[((__&gt;&gt;2)+04000-&quot;\x01?@A&quot;[__%4])%2048]&amp;1&lt;&lt;5)*(_+(__&gt;&gt;2))=-~_[__&gt;&gt;2];if(__%4==3)_[__&gt;&gt;2]|=_[__&gt;&gt;2]^&#x27;&quot;&#x27;&quot;&#x27;\&quot;&#x27;&quot;&#x27;&quot;&#x27;&amp;&amp;_[__&gt;&gt;2]^&#x27;&quot;&#x27;&quot;&#x27;#&#x27;&quot;&#x27;&quot;&#x27;?((_[__&gt;&gt;2]^3)?0:1&lt;&lt;4):1&lt;&lt;4;};while((__=-~__)^10240)if(putchar((_[__%2048]=_[__%2048]&lt;&lt;1&amp;1&lt;&lt;5)?&#x27;&quot;&#x27;&quot;&#x27;X&#x27;&quot;&#x27;&quot;&#x27;:&#x27;&quot;&#x27;&quot;&#x27; &#x27;&quot;&#x27;&quot;&#x27;),!(63^__%0100))putchar(10);}};&#x27; | gcc -xc - &amp;&amp; .&#x2F;a.out .</code></pre>
babuskovover 11 years ago
Nice explanation of each line is here:<p><a href="https://github.com/duckythescientist/obfuscatedLife/blob/master/remarks.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;duckythescientist&#x2F;obfuscatedLife&#x2F;blob&#x2F;mas...</a><p>Code is obfuscated more than needed to run. It starts with something simple like this:<p>&quot;I abuse 2&#x27;s complement math to initialize it as -1&quot;<p>Instead of: __ = -1 The code reads: __=~__+__<p>... and then gets more and more bizarre.
评论 #6821805 未加载
评论 #6822066 未加载
cgcardonaover 11 years ago
I&#x27;m sure many would complain about the obfuscated nature of the code. I however find it strangly beautiful. It has the appearance of a strand of DNA and then one marvels at all of the complexity hidden in these cryptic lines.<p>To see it:<p>`git clone <a href="https://github.com/duckythescientist/obfuscatedLife.git" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;duckythescientist&#x2F;obfuscatedLife.git</a><p>cd obfuscatedLife<p>gcc life.c<p>.&#x2F;a.out`<p>Here is a screenshot[1] for anyone who didn&#x27;t run the code. However a screenshot hardly does the dynamic nature of it justice.<p>[1] <a href="http://imgur.com/hWzEWAe" rel="nofollow">http:&#x2F;&#x2F;imgur.com&#x2F;hWzEWAe</a>
评论 #6821712 未加载
lelandbateyover 11 years ago
Youtube link for those who are unwilling or unable to download and compile yourself:<p><a href="http://www.youtube.com/watch?v=LFx46bAq-_E" rel="nofollow">http:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=LFx46bAq-_E</a><p>As well, for those that don&#x27;t want to use youtube, you can view&#x2F;stream the raw video here:<p><a href="http://lelandbatey.com/files/Obfuscated%20C%20-%20Game%20Of%20Life-LFx46bAq-_E.mp4" rel="nofollow">http:&#x2F;&#x2F;lelandbatey.com&#x2F;files&#x2F;Obfuscated%20C%20-%20Game%20Of%...</a>
iamstefover 11 years ago
Fun obfuscated version in ruby.<p><a href="https://github.com/stefanpenner/obfcuscatedLife.rb/blob/master/game_of_life.rb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stefanpenner&#x2F;obfcuscatedLife.rb&#x2F;blob&#x2F;mast...</a><p>and for those crazy people who ever far to trusting:<p><pre><code> curl https:&#x2F;&#x2F;raw.github.com&#x2F;stefanpenner&#x2F;obfcuscatedLife.rb&#x2F;master&#x2F;game_of_life.rb | ruby</code></pre>
carlosdpover 11 years ago
On a cool side note, I don&#x27;t know if this is old, but if you Google &quot;Conway&#x27;s Game of Life&quot;, an actual game of life is run on the page: <a href="https://www.google.com/#q=conway&#x27;s+game+of+life" rel="nofollow">https:&#x2F;&#x2F;www.google.com&#x2F;#q=conway&#x27;s+game+of+life</a>
评论 #6822682 未加载
deletesover 11 years ago
So much effort is ruined with the usage of usleep. Obfuscated C should be portable!
评论 #6822767 未加载
评论 #6821811 未加载
julienchastangover 11 years ago
In APL, it is one line of code <a href="http://catpad.net/michael/apl/" rel="nofollow">http:&#x2F;&#x2F;catpad.net&#x2F;michael&#x2F;apl&#x2F;</a>. Whether it is obfuscated or not is a matter of interpretation.