<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>42 | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/42/feed" rel="self" type="application/rss+xml" />
	<link>https://coolshell.cn</link>
	<description>享受编程和技术所带来的快乐 - Coding Your Ambition</description>
	<lastBuildDate>Fri, 07 Mar 2014 01:48:47 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>如何用最有创造力的方式输出42</title>
		<link>https://coolshell.cn/articles/11170.html</link>
					<comments>https://coolshell.cn/articles/11170.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Thu, 06 Mar 2014 14:42:42 +0000</pubDate>
				<category><![CDATA[趣味问题]]></category>
		<category><![CDATA[轶事趣闻]]></category>
		<category><![CDATA[42]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[程序员]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=11170</guid>

					<description><![CDATA[<p>酷壳似乎好长时间没有像《编程真难啊》或是《老手是这样教新手编程的》或是像《如何写出无法维护的代码》这样“严肃正经”的文章了，所以，赶在大家还没有向我扔臭鸡蛋前奉...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/11170.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/11170.html">如何用最有创造力的方式输出42</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></description>
										<content:encoded><![CDATA[<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415450859608158"
     crossorigin="anonymous"></script><img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2014/03/42-300x240.jpg" alt="" width="300" height="240" class="alignright size-medium wp-image-11216" srcset="https://coolshell.cn/wp-content/uploads/2014/03/42-300x240.jpg 300w, https://coolshell.cn/wp-content/uploads/2014/03/42-338x270.jpg 338w, https://coolshell.cn/wp-content/uploads/2014/03/42.jpg 750w" sizes="(max-width: 300px) 100vw, 300px" />酷壳似乎好长时间没有像《<a title="编程真难啊 - 80,069 人阅读" href="https://coolshell.cn/articles/1391.html">编程真难啊</a>》或是《<a title="老手是这样教新手编程的" href="https://coolshell.cn/articles/2420.html" target="_blank">老手是这样教新手编程的</a>》或是像《<a title="如何写出无法维护的代码" href="https://coolshell.cn/articles/4758.html" target="_blank">如何写出无法维护的代码</a>》这样“严肃正经”的文章了，所以，赶在大家还没有向我扔臭鸡蛋前奉献一篇。这篇文章来自CodeGolf.StackExchange上的《<a href="http://codegolf.stackexchange.com/questions/21835/most-creative-way-to-display-42">Most creative way to display 42</a>》—— 请以最有创造力的方式输出42。于是出现了下面的这些答案（注：精彩的总是留在最后面）</p>
<h4>人生和宇宙终级问题的答案：42</h4>
<p>这里，需要介绍一下为什么要输出42。这时因为42是我们人生，世界乃至整个宇宙的终级答案。这要从《银河系漫游指南》（英文名：The Hitchhiker&#8217;s Guide to the Galaxy）说起。这本书是著名英国科幻小说作家Douglas  Adams所著5本银河系漫游指南系列科幻喜剧系列小说中的第一本，改编自他本人为英国广播公司第四电台（BBC Radio 4）所写的广播剧剧本。该书1979年10月12日首次由麦克米伦出版公司（Pan Books）出版，次周成为英国图书销量榜冠军，前3个月内销售超过25万本。截至2005年，这本小说已被翻译成超过30种语言在全世界发行，并且被改编为电视剧、电影、舞台剧等多种艺术形式的作品。</p>
<p>这本小说中小说中充满尖锐的讽刺和隐喻，被西方科幻爱好者奉为“科幻圣经”。其中有两个关键词，一个是Don&#8217;t Panic，一个是42影响力很大，而其中关于42的故事简介是这样的：</p>
<p style="padding-left: 30px;">百万年前，老鼠其实是一种超智慧生物，它们建造了一部超级电脑深思Deep Thought，它们问超级电脑，生命、宇宙以及任何事情的终极答案（<i>Answer to Life, the Universe, and Everything</i>）什么，经过了750万年的计算，深思告诉老鼠的后人答案是<b>42</b>，深思解释它只能计算出答案是什么，但答案的原因必须由另一部更高智能的电脑才能解释，而该部电脑就是地球。经过了800万年，就在结果要出来的五分钟前，地球却因为挡在预定兴建的星际间高速公路的路线，被Vogons给毁灭，电脑没有给出最后的结果。</p>
<p><span id="more-11170"></span></p>
<p style="padding-left: 30px;">故事里面还说了这个42是6 乘于 9得来。当然，6乘9应该是54，但是因为地球上的电脑被搞坏了，导致主人翁答错了。至于后来有人说6 x 9 = 42是基于13进制，原作者说，完全没有这回事，他就是瞎搞的。</p>
<p>网上有很多人在猜测42的含义，比如<a href="http://www.douban.com/note/232036705/" target="_blank">douban的这篇文章</a>，但是原作者出来说这他就是随机想了一个，完全没有任何意义。</p>
<p>对于42来说，数字42和短语，“生命，宇宙以及一切的答案”（<i>Answer to Life, the Universe, and Everything</i>） 已达到在互联网上邪教的地位。在各种技术宅，极客，科学圈有着非同凡响的地位。</p>
<ul>
<li>您若在Google输入<a href="http://www.google.com/search?q=the+answer+to+life%2C+the+universe%2C+and+everything" target="_blank" rel="nofollow">the answer to life, the universe, and everything</a>，Google会直接回答42——而且还是用Google计算器算出来的。</li>
<li>若在<a title="Wolfram Alpha" href="http://zh.wikipedia.org/wiki/Wolfram_Alpha" target="_blank">Wolfram Alpha</a>中输入<a href="http://www.wolframalpha.com/input/?i=Answer+to+the+Ultimate+Question+of+Life%2C+the+Universe%2C+and+Everything" target="_blank" rel="nofollow">Answer to the Ultimate Question of Life, the Universe, and Everything</a>，Wolfram Alpha也会回答42</li>
<li>若在iPhone/iPad的Siri中问[What&#8217;s the meaning of life?]，Siri也会回答42</li>
<li><span><span>在</span></span><a title="OpenOffice.org" href="http://en.wikipedia.org/wiki/OpenOffice.org"><span>OpenOffice.org</span></a><span><span>软件，如果您在任何单元格输入spreadsheet=ANTWORT(&#8220;Das Leben, das Universum und der ganze Rest&#8221;) (注：德语的ANSWER(&#8220;life, the universe and everything&#8221;))，结果也会是42。</span></span></li>
</ul>
<p>另外，在美剧《Lost》里那个经典的数字序列： 4, 8, 15, 16, 23,42。经Lost的导演确认，最后那个42也是源自《银河系漫游指南》</p>
<p>好了，言归正传，下面让我们来看一下如何输出42的。</p>
<h4>Ruby</h4>
<p><code data-enlighter-language="ruby" class="EnlighterJSRAW"></code>puts (6 * 9).to_s(13)[/h4]</p>
<p>解释：6 x 9 = 42的表达式（基于13进制）</p>
<h4>Javascript</h4>
<p>[javascript]String.prototype.answer = function() {<br />
    alert(this.charCodeAt(+!&quot;The End of the Universe&quot;));<br />
};<br />
&#8216;*&#8217;.answer();[/javascript]</p>
<p>解释：+!&#8221;The End of the Universe&#8221;的值是0，&#8217;*&#8217;的ASCII码是42</p>
<p>[javascript]console.log(&quot;Douglas Adams&quot;.length + &quot;born on&quot;.length +<br />
    [1,1,0,3,1,9,5,2].reduce(<br />
        function(previousValue, currentValue, index, array){<br />
            return previousValue + currentValue;<br />
        }<br />
    )<br />
);</p>
<p> /* [1,1,0,3,1,9,5,2] =&gt; March 11, 1952 */[/javascript]</p>
<p>解释：Douglas Adams 是一位英国广播剧作家、和音乐家，尤其以《银河系漫游指南》系列作品出名。这部作品以广播剧起家，后来发展成包括五本书的“三部曲”，拍成电视连续剧。亚当斯逝世后还拍成电影。 除《银河系漫游指南》系列外亚当斯还参加了科幻电视连续剧《神秘博士》的拍摄工作，他写了其中的一些剧本。也的生日是 1952 年 3 月 11 日。</p>
<p>[javascript]alert((!![]+ -~[])*(!![]+ -~[])+&quot;&quot;+(!![]+ -~[]))[/javascript]</p>
<p>解释：[]是个空，![]就是true，~[]是-1, 于是，表达式就这样出来了。变态！</p>
<p>[javascript]var ________ = 0.023809523809523808, ____ = 1, ___ = 0, __ = 0, _ = 1;</p>
<p>       __ &#8211;           ___<br />
     /_  |0        //     \\<br />
    /_/   0     //          \\<br />
   /_/_  |0                //<br />
  /_/_   |0              //<br />
 /_/____ |_           //<br />
/________|0        //<br />
         |0     //______________[/javascript]</p>
<p>解释：这个其实是代码混乱的技巧之一，用下划线当变量。你可以参考《<a href="https://coolshell.cn/articles/933.html" target="_blank">如何加密/混乱C源代码</a>》和《<a href="https://coolshell.cn/articles/914.html" target="_blank">6个变态的C语言Hello World程序</a>》</p>
<h4>Shell</h4>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">echo &quot;what is the universe&quot;|tr &quot;a-z &quot; 0-7-0-729|sed &#039;s/9.//g;s/-/+/&#039;|bc</code></p>
<p>解释：其中，bc是一个计算器。tr是一个字符转换的命令，比如：<code>echo "good" | tr "good" "test"</code>输出 <code>tsst</code>。也就是说，g-t, o-e, o-s, d-t的映射，o被映了两次，所以，第二次会覆盖第一次。对于上面的<code>tr "a-z " 0-7-0-7-729</code>的意思是：abcdefg分别对应01234567，h对应-，ijklmno对应01234567，p对于2，剩下的包括空格都是9。如果你对tr和sed和bc不熟悉的话，可以man一下，关于sed你可以看一下我的《<a href="https://coolshell.cn/articles/9104.html" target="_blank">sed简明教程</a>》</p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">#!/bin/bash

#Vertical Version
echo $((2#100))
echo $((2#10))

#Horizontal Version
echo $((2#000100))$((2#00010))</pre>
<p>解释：2#100的意思就是说，#左边的数说明是“2进制”，右边的数是二进制数“100”，如16#ff就是16进制的ff，也就是十进制的255</p>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">echo &quot;obase=13;6*9&quot;|bc|figlet</code></p>
<p>上面的命令输出：</p>
<pre style="font-family: 'Consolas','Courier New', Courier, monospace;">
 _  _  ____
| || ||___ \
| || |_ __) |
|__   _/ __/
   |_||_____|</pre>
<p>解释：为了使用figlet命令，你还要去安装一个figlet（<a href="http://www.figlet.org/" target="_blank">http://www.figlet.org/</a>）这是一个让你画ASCII图的命令。</p>
<h4>Python</h4>
<p>Windows下，给你画个图：</p>
<div style="height: 300px; overflow: auto;">
<pre data-enlighter-language="python" class="EnlighterJSRAW">import win32api, win32con, win32gui
from time import time, sleep
import os

w = { 1:[(358, 263), (358, 262), (358, 261), (359, 261), (359, 262), (359, 264), (359, 266), (359, 270), (359, 282),
     (358, 289), (357, 308), (356, 319), (355, 341), (355, 351), (355, 360), (355, 378), (355, 388), (354, 397),
     (354, 406), (354, 422), (354, 428), (354, 436), (354, 438), (354, 439), (354, 440), (355, 440), (356, 439),
     (357, 439), (358, 438), (360, 438), (362, 437), (369, 437), (372, 437), (381, 437), (386, 437), (391, 437),
     (397, 436), (411, 436), (419, 435), (434, 435), (442, 435), (449, 434), (456, 434), (468, 434), (473, 435),
     (480, 436), (483, 436), (485, 436), (487, 437), (488, 437), (488, 438), (488, 439), (487, 440), (486, 440),
     (485, 440), (484, 440), (483, 439), (483, 437), (481, 431), (481, 427), (481, 420), (481, 413), (483, 396),
     (485, 387), (488, 367), (491, 356), (493, 345), (500, 321), (503, 310), (507, 299), (514, 280), (517, 272),
     (520, 266), (523, 260), (524, 258), (524, 259), (524, 261), (524, 265), (524, 269), (523, 275), (522, 289),
     (521, 297), (518, 315), (516, 324), (515, 334), (513, 345), (509, 368), (507, 382), (502, 411), (500, 426),
     (498, 440), (495, 453), (491, 478), (489, 491), (485, 517), (483, 530), (481, 542), (479, 552), (476, 570),
     (475, 577), (474, 588), (473, 592), (473, 595), (473, 597), (473, 600), (473, 601), (473, 602), (473, 601),
     (474, 599), (475, 597), (476, 594), (478, 587)],
  2:[(632, 305), (634, 306), (636, 309), (639, 314), (641, 319), (645, 330), (647, 337), (649, 353), (649, 362),
     (649, 372), (649, 384), (645, 409), (639, 436), (636, 448), (632, 459), (627, 470), (623, 479), (613, 497),
     (608, 503), (599, 512), (595, 514), (591, 514), (587, 513), (581, 504), (578, 498), (576, 483), (575, 476),
     (575, 469), (579, 454), (582, 447), (591, 436), (595, 432), (600, 430), (605, 429), (617, 432), (624, 437),
     (639, 448), (646, 455), (654, 461), (662, 469), (679, 484), (686, 491), (702, 504), (710, 509), (718, 512),
     (727, 514), (744, 515), (752, 515), (767, 512), (774, 510), (779, 508), (783, 505), (788, 499), (789, 495),
     (789, 486)] }

def d( x1, y1, x2, y2 ):
    win32api.SetCursorPos((x1, y1))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.SetCursorPos((x2, y2))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    sleep(0.01)

def p( l1 ):
    l2 = [&quot;&quot;]
    l2.extend(l1)
    l1.append(&quot;&quot;)
    l3 = zip(l2, l1)
    l3.pop(0)
    l3.pop(-1)
    for n in l3:
        d(n[0][0], n[0][1], n[1][0], n[1][2])

os.startfile(&quot;C:\Windows\system32\mspaint.exe&quot;)
sleep(0.5)
win32gui.ShowWindow(win32gui.GetForegroundWindow(), win32con.SW_MAXIMIZE)
sleep(0.5)

for n in w:
    p(w[n])</pre>
</div>
<p>输出：<img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2014/03/1j0va.png" alt="" width="300" height="240" class="aligncenter size-full wp-image-11172" srcset="https://coolshell.cn/wp-content/uploads/2014/03/1j0va.png 499w, https://coolshell.cn/wp-content/uploads/2014/03/1j0va-300x240.png 300w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>lambda表达式 </p>
<p><code data-enlighter-language="python" class="EnlighterJSRAW">&gt;&gt;&gt; p = lambda x: x%2!=0 and True&lt;&gt;&gt; sum(p(i) for i in range(0,6))</code></p>
<p>解释：对python的lambda表达式或函数式编程不是很清楚的同学可以看一下《<a href="https://coolshell.cn/articles/10822.html" target="_blank">函数式编程</a>》</p>
<h4>Java</h4>
<pre data-enlighter-language="java" class="EnlighterJSRAW">import java.lang.*;
class answer_to_everything 
{
    void static main() 
    {
        String s = &quot;Hitchhiker&#039;s Guide to the Galaxy&quot;;
        String s2 = &quot;Don&#039;tPanic&quot;;
        String s3 = &quot;The Restaurant at the End of the Universe.&quot;;

        int arthur_dent = s.length();
        int ford_prefect = s2.length();
        int zooey_deschanel = s3.length();
        int vogon_poetry = arthur_dent + ford_prefect;

        System.out.println(&quot;         &quot; + vogon_poetry + &quot;       &quot; + zooey_deschanel + &quot; &quot; + zooey_deschanel); //in case you&#039;re confused, I&#039;m using Zooey to print the big &#039;2&#039;, and Vogons to print the big &#039;4&#039;.
        System.out.println(&quot;       &quot; + vogon_poetry + vogon_poetry + &quot;     &quot; + zooey_deschanel + &quot;     &quot; + zooey_deschanel);
        System.out.println(&quot;     &quot; + vogon_poetry + &quot;  &quot; + vogon_poetry + &quot;    &quot; + zooey_deschanel + &quot;       &quot; + zooey_deschanel);
        System.out.println(&quot;   &quot; + vogon_poetry + &quot;    &quot; + vogon_poetry + &quot;            &quot; + zooey_deschanel);
        System.out.println(&quot; &quot; + vogon_poetry + &quot;      &quot; + vogon_poetry + &quot;          &quot; + zooey_deschanel);
        System.out.println(vogon_poetry + &quot; &quot; + vogon_poetry + &quot; &quot; + vogon_poetry + &quot; DA &quot; + vogon_poetry + &quot;     &quot; + zooey_deschanel);
        System.out.println(&quot;         &quot; + vogon_poetry + &quot;     &quot; + zooey_deschanel);
        System.out.println(&quot;         &quot; + vogon_poetry + &quot;    &quot; + zooey_deschanel + &quot; &quot; + zooey_deschanel + &quot; &quot; + zooey_deschanel + &quot; &quot; + zooey_deschanel);
    }
}</pre>
<p>上面这段看上去平淡无奇，但其亮点是那三个string，这段代码输出：</p>
<pre style="font-family: 'Consolas','Courier New', Courier, monospace;">
         42       42 42
       4242     42     42
     42  42    42       42
   42    42            42
 42      42          42
42 42 42 DA 42     42
         42     42
         42    42 42 42 42</pre>
<p>别忘了Java也可以混乱代码：</p>
<pre data-enlighter-language="java" class="EnlighterJSRAW">
public        class         FourtyTwo{ public
static         void         main(String[]args)
{  new        javax                    .swing.
JFrame        () {{                    setSize
(42 /(        42/42                    +42/42)
*42/ (        42/42                    +42/42)
,42/(42/ 42+42/42)*         42/(42/42+42/42));
}public void paint(         java.awt .Graphics
  g){g.drawPolygon(         new int[]{42,42,42
              + 42+         42,42+
              42+42         ,42+42
              +42 +         42,42+
              42+42         +42,42
              + 42+         42,42+42+42,42+42,
              42+42         },new int[]{42,42+
              42+42         +42,42+42+42+42,42

+42+42+42+42+42,                  42+42+
42+42+42+42,42,42,               42+42+42
,42 +        42+42              ,42}, (42/
42+42        /42)*              (42/  42 +
42/42        + 42/             42 +    42 /
42+42        /42))            ;g.drawPolygon
( new        int[]           {42+42+42+42+42,
42+42        +42 +           42+42      , 42+
42+42        + 42+          42+42        + 42,
42+42        +42 +          42+42        +42 +
42,42+42+42+42+42,         42+42          + 42+
42+42,42+ 42+42+           42+42          +42 +

42+42,42+42+42+42+42+42+42+42,42+42+42+42+42+42,
42+42+42+42+42+42,42+42+42+42+42+42+42+42,42+42+
42+42+42+42+42+42},new int[]{42,42 +42,42+42,42+
42+42,42+42+42,42+42+42+42+42+42,42+42+42+42+42+
42,42+42+42+42+42,42+42+42+42+42,42+42+42+42,42+
42+42+42,42},(42/42+42/42+42/42)*((42/42+42/42)*
(42/42+42/ 42)));};}.setVisible(42*42*42!=42);}}</pre>
<h4>C/C++</h4>
<pre data-enlighter-language="c" class="EnlighterJSRAW">#include
int main()
{
    printf(&quot;%d&quot;, fprintf( fopen(&quot;/dev/null&quot;,&quot;w&quot;),
       &quot;so-popularity-contest\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b&quot;) );
}
</pre>
<p>解释：\b是backspace，fprintf的返回值是写成功数据的长度。</p>
<div style="height: 200px; overflow: auto;">
<pre data-enlighter-language="c" class="EnlighterJSRAW">#include&lt;iostream&gt;
using namespace std;
int main()
{
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)66&lt;&lt;(char)73&lt;&lt;(char)82;
    cout&lt;&lt;(char)84&lt;&lt;(char)72&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)68&lt;&lt;(char)69;
    cout&lt;&lt;(char)65&lt;&lt;(char)84&lt;&lt;(char)72;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)47&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)124&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)124&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)95&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)124&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)32&lt;&lt;(char)47&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)49&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)50&lt;&lt;(char)124&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)47&lt;&lt;(char)32;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)57&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)84&lt;&lt;(char)79&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)47&lt;&lt;(char)48;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)124&lt;&lt;(char)53&lt;&lt;(char)124;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)47&lt;&lt;(char)48&lt;&lt;(char)47;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)124&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)124&lt;&lt;(char)50&lt;&lt;(char)124;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)49&lt;&lt;(char)47&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)47&lt;&lt;(char)32;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)47&lt;&lt;(char)32&lt;&lt;(char)47;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)32&lt;&lt;&#039;\n&#039;;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)32;
    cout&lt;&lt;(char)124&lt;&lt;(char)95&lt;&lt;(char)124;
    cout&lt;&lt;(char)32&lt;&lt;(char)32&lt;&lt;(char)124;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)95&lt;&lt;(char)95;
    cout&lt;&lt;(char)95&lt;&lt;(char)124&lt;&lt;&#039;\n&#039;;
    return 0;
}  </pre>
</div>
<p>输出：</p>
<p><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-11171" alt="" src="https://coolshell.cn/wp-content/uploads/2014/03/42.png" width="182" height="151" /></p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">#include &lt;stdio.h&gt;

#define six  1+5
#define nine 8+1

int main()
{
    printf(&quot;what do you get when you multiply six by nine?\n&quot;);
    printf(&quot;%i x %i = %i\n&quot;, six, nine, six*nine);
}</pre>
<p>解释：6 x 9 = 42 ???，如果你知道宏只是做简单的字符串替换的话，你就知道six*nine被替换成了1+5*8+1这个表达式了。呵呵。</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">
        main(c     ,z,_){c==01?
       main(c+     1,0,c^c):c==2
      ?z=_[&quot;#&quot;     &quot;#$#%&amp;#%#x&#039;%%&quot;
     &quot;()&amp;(%%x&quot;             &quot;$%$(&quot;
    &quot;(&amp;(&quot;&quot;*%x&quot;             &quot;&#039;%%(&quot;
   &quot;(&amp;(&quot; &quot;+%x&quot;             &quot;&#039;#%(&quot;
  &quot;(&amp;(&quot;  &quot;%#x&quot;             ],z ?z
 ==&#039;x&#039;?main(4,_     ,c*5):main(c
 +1,z,0),main(c    ,z,_+1):00:c
 ==3?(_+-2)==3?    main(_-1,_,
         32):(     main(
         c+1,c     ,((2+
         c)*(z     -35)+
         _)[&quot;&quot;     &quot;six&quot;
         &quot;*ni&quot;     &quot;ne= {   }   &quot;
         &quot;  ;&quot;     &quot;      _   ( &quot;
         &quot;) [&quot;     &quot; 3 ]do {;&quot;]==
         32?32     :043),main(c,z
         ,_+1)     ):putchar(_);}</pre>
<p>解释：参看<a href="http://codegolf.stackexchange.com/questions/21835/most-creative-way-to-display-42/21950#21950" target="_blank">原文的这个答案</a>里的How-To一节。</p>
<h4>Brainfuck</h4>
<p>代码混乱自然少不了brainfuck语言：（更多的奇葩的编程语言请参考《<a href="https://coolshell.cn/articles/4458.html" target="_blank">那些BT雷人的编程语言</a>》）</p>
<pre style="font-family: 'Consolas','Courier New', Courier, monospace;"> 
         +++++          +++[>+>++>
        +++>++        ++>+++++>+++++
       +>+++++       ++>+        ++++
      +++ >+++       ++++        ++>+
     +++  ++++                   ++>+
    +++   ++++                  +++>
   +++    ++++                 ++++
  +>+     ++++               ++++
 +++      +>++             ++++
++++++++>+++++++++       ++++
++>+++++++++++++++     +<<<
          <<<<        <<<<
          <<<<       <-]>
          >>>>       >>----.++++<<<<<
          <<>>       >>>>++.--<<<<<<.</pre>
<p>不过，下面这个BrainFuck更无聊，所以顶在了最佳答案上：</p>
<pre style="font-family: 'Consolas','Courier New', Courier, monospace;">
           +++++[>++[>+>+        ++>++++>++++>++++>++++++
          >++++++>+++++++        ++>+++++++++<<<<<<<<<-]>>
         >+>+>+> >>>+[<]<        -]>>       >++>-->>+>>++>+
        >--<<<<  <<<.....         .>            ....<......
       ...>...   <<.>....                       >.>>>>>.<.
       <<<<..     ..<....                      >..>>>>>.<
      .<<<<.      >>>.<<.                     >>>>>.<.<
      <<<<<       <.>...>                    >>>.>>>.
     <<<.<        <<<..>>                  .>>>>>.<
    <.<<<         <<...>>                 >>>.<<<
   <..<.          ...>...               <<.>..>.
   >>.<.<<...>>...<<...>>...<         <....>>..
  .<<<.>.>>..>.<<.......<....        .....>...
                 <<.>...            .....>...
                 <......           .>>>.<<..
                 <<.>...          .....>...<......>.>>.<.<<<
                 .>......        ..>>...<<....>>.....>.<..>.
</pre>
<p>执行上面的代码，你会得到下面的输出：</p>
<pre style="font-family: 'Consolas','Courier New', Courier, monospace;">
      ++++         +++
    +[>++++    ++[>+<-][
   <]<  -]>   >++    +++
  +.-   ---   ---    ---
 --.+++++++         +++
        +++       .++
        +++      +.-
        ---    -----.--.</pre>
<p>再执行上面的代码，会输出：</p>
<pre>6*7=42</pre>
<p>如果6*9=42就完美了，就差一步啊……</p>
<p>(全文完)<!--



<p align="center"><a href= target=_blank><img decoding="async" src=""></a></p>





<p align="center"><img decoding="async" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.weixin.jpg"> <img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.mini_.jpg" width="300" height="300"> <br />关注CoolShell微信公众账号和微信小程序</p>

 

--></p>
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;">
<p align="center"><strong>（转载本站文章请注明作者和出处 <a href="https://coolshell.cn/">酷 壳 - CoolShell</a> ，请勿用于任何商业用途）</strong></p>
</div>

<div class="wp_rp_wrap  wp_rp_vertical_m" id="wp_rp_first"><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/19612.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2019/07/1920px-Margaret_Hamilton_-_restoration-e1563697198766-1-150x150.jpg" alt="50年前的登月程序和程序员有多硬核" width="150" height="150" /></a><a href="https://coolshell.cn/articles/19612.html" class="wp_rp_title">50年前的登月程序和程序员有多硬核</a></li><li ><a href="https://coolshell.cn/articles/12052.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/29.jpg" alt="Leetcode 编程训练" width="150" height="150" /></a><a href="https://coolshell.cn/articles/12052.html" class="wp_rp_title">Leetcode 编程训练</a></li><li ><a href="https://coolshell.cn/articles/11656.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2014/06/software_development-150x150.png" alt="开发团队的效率" width="150" height="150" /></a><a href="https://coolshell.cn/articles/11656.html" class="wp_rp_title">开发团队的效率</a></li><li ><a href="https://coolshell.cn/articles/8387.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2012/10/Learnable_Programming-150x150.jpg" alt="Bret Victor &#8211; Learnable Programming" width="150" height="150" /></a><a href="https://coolshell.cn/articles/8387.html" class="wp_rp_title">Bret Victor &#8211; Learnable Programming</a></li><li ><a href="https://coolshell.cn/articles/22298.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2022/10/communication-150x150.png" alt="聊聊团队协同和协同工具" width="150" height="150" /></a><a href="https://coolshell.cn/articles/22298.html" class="wp_rp_title">聊聊团队协同和协同工具</a></li><li ><a href="https://coolshell.cn/articles/22173.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2022/02/http_method-150x150.png" alt="“一把梭：REST API 全用 POST”" width="150" height="150" /></a><a href="https://coolshell.cn/articles/22173.html" class="wp_rp_title">“一把梭：REST API 全用 POST”</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/11170.html">如何用最有创造力的方式输出42</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/11170.html/feed</wfw:commentRss>
			<slash:comments>29</slash:comments>
		
		
			</item>
	</channel>
</rss>
