380
votes
\$\begingroup\$

Douglas Adams was born on March 11, 1952, and died when he was just 49. In honor of this wonderful writer, I challenge you to display 42 in the most creative way possible.

You could print it in the log, via some convoluted method, or display it as ASCII art, or anything! Just come up with a creative method of displaying 42.

Because this a popularity-contest, whichever answer has the most upvotes by March 11, will be declared the winner.

Note: this is not a duplicate. The question it was marked as duplicating was a code-trolling question whose goal was to write code to output 42, not find the most creative way to display it.

Winner: grovesNL! With an astounding 813 votes! Congrats!

Honorable Mentions:

Mr Lister C 228 For the clever use of #define

David Carraher Mathematica 45 For the complicated and convoluted math function to achieve 42

Aschratt Windows Calculator 20 Because, well, it's windows calculator And definitely 1337.

f.rodrigues Python 17 Because of the clever use of using external programs. And MSPaint

Jason C LMGTFY 14 For the use of LMGTFY (Let Me Google That For You)

Trimsty Python 12 For the clever use of an error message to output 42.

Mukul Kumar C++ 7 For the nice ASCII output.

If you think that there is another answer worth putting on the list, please comment it!

\$\endgroup\$
22
  • 6
    \$\begingroup\$ The old closed question was a code-trolling, i.e, anything that does not shows 42 beside appearing to do so or do it in a really horrible way. This one is not code-trolling, i.e. the output should really be 42 in a nice way. Hence it is not duplicate. \$\endgroup\$ Commented Feb 23, 2014 at 22:59
  • 2
    \$\begingroup\$ @DanDascalescu This SE site has many questions without strict requirements, which allows users to exercise creative freedom in their answers. Sometimes too many restrictions can impede the expression of creativity \$\endgroup\$
    – grovesNL
    Commented Feb 24, 2014 at 0:45
  • 9
    \$\begingroup\$ The question should remain at 42 votes. \$\endgroup\$
    – Zero Fiber
    Commented Feb 24, 2014 at 3:47
  • 28
    \$\begingroup\$ Marvin The Robot "I would post my brilliant answer, but you would probably down vote it. Being right all the time is so depressing." \$\endgroup\$
    – Reactgular
    Commented Feb 24, 2014 at 16:43
  • 3
    \$\begingroup\$ Can we get 42 favorites? \$\endgroup\$
    – Milo
    Commented Feb 24, 2014 at 22:48

110 Answers 110

10
votes
\$\begingroup\$

Bash – 42 bytes

  1. Vertical Version

    #!/bin/bash
    echo $((2#100))
    echo $((2#10))
    

    Yep, that's exactly 42 bytes of sourcecode to output:

    4
    2
    
  2. Horizontal Version

    After I posted the “Vertical Version”, Glenn correctly noted in a comment that you could write both numbers on a single line too by writing echo $((2#00100))$((2#00010)). Yet, the prepended zeros wouldn't depict full bytes (which would expect 8 binary characters per byte), which was the main reason why I initially opted-out of posting that solution. Also, Glenn's suggestion merely uses 41 bytes, which is not what I intended.

    Nevertheless, to add a horizontal alternative which – again – uses 42 bytes of sourcecode:

    #!/bin/bash
    echo $((2#000100))$((2#00010))
    

    Note that this is almost the same as what Glenn suggested, but with an added 0 in the first binary representation, which make the sourcecode exactly fit 42 bytes. It's output will be:

    42
    
\$\endgroup\$
9
  • \$\begingroup\$ I count 44 bytes. \$\endgroup\$
    – Doorknob
    Commented Feb 23, 2014 at 22:15
  • \$\begingroup\$ @Doorknob Then you should count again... 11 + \n + 15 + \n + 14 = 42 bytes including the two newlines. \$\endgroup\$
    – e-sushi
    Commented Feb 23, 2014 at 23:26
  • \$\begingroup\$ Turns out your code had trailing spaces at the end of the lines, which threw off my automatic length counter. I edited them out \$\endgroup\$
    – Doorknob
    Commented Feb 23, 2014 at 23:29
  • \$\begingroup\$ Hmmm, must have been SE modding my copy-and-paste. Thanks for killing two invisible chars then. ;) \$\endgroup\$
    – e-sushi
    Commented Feb 23, 2014 at 23:33
  • 3
    \$\begingroup\$ Still 42 bytes of source code, but writes 42 on one line. Replace the two echo statements with one: echo $((2#00100))$((2#00010)) \$\endgroup\$ Commented Feb 24, 2014 at 3:58
10
votes
\$\begingroup\$

CSS

Here's one I made myself, hand drawn in CSS.

html, body {padding:0; margin:0;}
:before, :after {display:block; content:''; position:absolute;}
html:before {
    border-top:20px solid transparent;
    border-right:14px solid transparent;
    border-bottom:20px solid;
    border-left:24px solid;
    padding:25px; width:35px; height:20px;
    -webkit-transform:skewX(-35deg);
    -ms-transform:skewX(-35deg);
    transform:skewX(-35deg);
    top:10px; left:50px;
}
html:after {
    border-right:20px solid;
    left:88px; top:10px;
    width:0; height:170px;
}
body {
    border:20px solid;
    border-radius:100px;
    padding:42px; width:0; height:0;
    border-bottom-color: transparent;
    border-left-color: transparent;
    position:relative; left:120px; top:9px;
}

body:after {
    border-top:20px solid transparent;
    border-right:20px solid transparent;
    border-bottom:20px solid;
    border-left:28px solid;
    padding:25px; width:15px;
    -webkit-transform:skewX(-45deg);
    -ms-transform:skewX(-45deg);
    transform:skewX(-45deg);
    top:62px; left:37px;
}

Markupless fiddle: http://jsfiddle.net/MrLister/A3f85/1/

Output:

42

\$\endgroup\$
10
votes
\$\begingroup\$

Piet

42 Piet

After the "Hello World", this is the first thing I tried in Piet, it start in the top left, push 42 ten times to the stack(maybe I'll make a 42 times), add them(the colored part), divides by 10, and outputs(the light blue part at the top of '2').

42 Piet Simple

And this is a very simple 42.

\$\endgroup\$
1
  • \$\begingroup\$ This is art in multiple point of views! \$\endgroup\$
    – bobbel
    Commented Sep 14, 2015 at 7:19
8
votes
\$\begingroup\$

C#

TimeSpan thoughtTime = new TimeSpan(65221821, 18, 13, 20, 0);
for (int i = 0; i < 42; i++)
{
    Thread.Sleep(thoughtTime);
}
Console.WriteLine("42");

...aaaand seven and a half million years later... voila!

\$\endgroup\$
7
votes
\$\begingroup\$

C++, Windows (TTS)

Turn your volume up.

#include <sapi.h>

int main () {

    // compute 6 * 9
    int value = 6 * 9;
    wchar_t str[3];
    wsprintf(str, L"%i%i", value/13, value%13);

    // display result
    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ISpVoice *v;
    CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&v);
    for (int n = 0; n < _wtoi(str); ++ n)
        v->Speak(str, 0, NULL);
    v->Release();
    CoUninitialize();

}

Result is presented 6*9 times. Compile with MSVC. As far as I can see this is the only audio version here.

\$\endgroup\$
7
votes
\$\begingroup\$

Ruby

I didn't see a Ruby entry (except the 6*9 one), so here's a stab:

<<z.scan(/\S/).each_slice(8){|b|i=0;(?0+b.map{|h|'%04b'.% '0x'+h}.join).scan(/.../).each{|m|$><<' #'[i%2]*m&&i+=1 if 0!=(m=m.to_i 2)};puts}

    0A   692D
  0C91  4D  74
 D1 03     71
74D191   4D
    74  D1
    0A  69730C
z

(Yes, the big "42" above is part of the program, not the output.)

Output

 ##   ##  ##      #### ####
  ## ##   ##       ##   ## 
   ###    ##       ##   ## 
  ## ##   ##       ##   ## 
 ##   ##  ####### #### ####

(That's 42 in Roman numerals.)

Notes

I could have golfed this some more but since this wasn't actually a golfing challenge I quit pretty quick. If anyone is interested in an ungolfing I'd be happy to write it up, but there's no particularly interesting magic going on here.

\$\endgroup\$
1
  • \$\begingroup\$ XLII doesn't sound like the answer to the meaning of life to me. It sounds like the answer to "What size T-shirt is that?" Double extra large. \$\endgroup\$ Commented Feb 27, 2014 at 22:28
6
votes
\$\begingroup\$

Perl

extrapolation in base 13

#!/usr/bin/perl
BEGIN
{
    eval "use Deep::Thought" or warn "DON'T PANIC\n";

    package Ultimate;

    our $Answer = "Share and Enjoy";

    sub Question
    {
        my ($min, $t, $s, %t) = (2, 13);

        my @cake = map {/[a-z]/i ? -97 + ord lc : ($t{$_} ||= --$t)} split //, shift;

        $s += $_ for @cake;

        $s = ($s * $min) % 13;

        my $v = $cake[0];

        for (my $more = 12; $more--;)
        {
            $v = ($v + 1) % 13;

            $v = $min if $v < $min;

            my @tpv = @cake;

            for (@cake)
            {
                my (@t, @u, @lie);

                @u = @t = @tpv;

                for my $brownian (@t)
                {
                    $brownian *= $s * 13 - $v;
                }

                $t[0] += $min;

                for (my $i = 0; $i < @cake; $i++)
                {
                    print((" " x ($t[$i] % (6 * 9))), ".");

                    $t[$i + 1] += int $t[$i] / 13 if $i + 1 < @cake;

                    $t[$i] %= 13;
                }

                my $zero;

                for (my $i = 0; $i < @cake; $i++)
                {
                    for (my $j = 0; $i + $j < @cake; $j++)
                    {
                        my $ij = $i + $j;

                        $lie[$ij] += $t[$i] * $u[$j];

                        $lie[$ij + 1] += int $lie[$ij] / 13 if $ij + 1 < @cake;

                        $lie[$ij] %= 13;
                    }

                    $zero = 0 if $lie[$i] != $tpv[$i];

                    $tpv[$i] = $lie[$i];
                }

                next if $zero ~~ 0;

                print "\n";

                my @d;

                for (my $i = @tpv; $i--;)
                {
                    $_ *= 13 for @d;

                    $d[0] += $tpv[$i];

                    for (my $j = 0; $j < @d; $j++)
                    {
                        next if $d[$j] < 1000000;

                        $d[$j + 1] += int $d[$j] / 1000000;

                        $d[$j] %= 1000000;
                    }
                }

                our $Answer = "";

                $Answer = sprintf "%06d%s", $_, $Answer for @d;

                return;
            }

            warn sprintf "%s%s\n", ($more ? "DON'T " : ""), "PANIC";
        }

        die "Total Existence Failure\n";
    }
}  

"Life, the Universe, and Everything"->Ultimate::Question;

END
{
    my ($false, $truth);

    while ($Ultimate::Answer =~ /(\d{4}(\d\d))/g)
    {
        ($false, $truth) = ($1, $2);

        $false =~ s/(?<=..)(..)/ $1 /;

        print "$false\n";
    }

    print "\n";

    exit $truth;
}

126 lines. The output?

DON'T PANIC

The Total Perspective Vortex, extrapolated from the array @cake. After some false starts, it eventually produces on a 160-column terminal:

. .                                                 .                                     .                         .                                           
.                         .                         ..                    .                                     .                                               
.                    .                   .  .     .                       .                          .                                    .                     
                                .              .       .                                                  .          .                                          
    .                                         .        .   . .                                                 . .                   .  .                       
         . . .                                                 .                                     .                         .                                
           .                         .                                                 .                                           .                            
   .       .       .             .                   .                                     .                                                 ..                .

...

               .                                                   .     .                   .                                . . .                             
                    .                                     .                         .                                           .                         .     
                                            .                                           .                               .       .       .             .         
          .                                     .                   .                               .       .             .                               . . . 
                                                .                                     .                         .                                           .   
                      .                                                 .                                           .                               .       .   
                                  .                                                .                                . . .                                       
          .                                     .                         .                                           .                         .               
                                  .                                           .                               .       .       .             .                   
.                                     .                   .                               .       .             .                               . . .           
                                      .                                     .                         .                                           .             
            .                                                 .                                           .                               .       .       .     
        .
00 00 54
37 62 45
45 35 54
55 00 23
09 16 88
75 04 85
15 77 42

with an exit status of that last number. Most of the work is done by $brownian motion in @t before line 42.

\$\endgroup\$
6
votes
\$\begingroup\$

Befunge

Now, I know I'm fairly late to the show, but I wanted to try something using befunge:

42*2+42+::*\->" "\1-:v>$82+>"2"\1-:v>$" 444"42+:*>" "\1-:v>$442++v              
v  42*42+4242^  $*42 _^4242^$*2*42 _^42 42 42 42 ^  $%42 _^42*42%>
>42+:*>" "\1-:v>$"222  444"42+:*>" "\1-:v>$42*2+42+:*1-v>424<
vchuck^norris _^the question of ^$$life _^the universe >
>>" "\1-:v>$"222 4"42*2+>"4"\1-:v>$42*4*2->" "\1-:v>$442++42*4*v_and everything
v^$!%42  _^    6*9=?    ^     DA_^knows   ^$the   _^answer: 42 >
>" ">" "\1-:v>$"222 "::"  444  444"42*4*>" "\1-:v>$$42+4+v forty-two
  v ^ $$ 42 _^42% 42+ \!:+* 42*- 42\$   ^ $*42  _^       >42      $$
  >42*4*1->" "\1-:v>$"222"42*>" "\1-:v>$$"444 444"424**>" "\1-:v>$42*2+v
  v       ^       _^         ^       _^                ^       _^      >
  >42+:4*+>" "\1-:v>$"222    222 ":::"444"44*2*1+>" "\1-:v>$24:++v
  v       ^       _^                             ^       _^      >
  >" "442**2->" "\1-:v>$42*>"2"\1-:v>$4>" "\1-:v>$"444"244**2+>" "\1-:v>$v
v            ^       _^    ^       _^  ^       _^             ^       _^ >
>004:*p   v>04:*g14:*gp:42*2+-#v_$004:*p144*g1+144*pv                  v
  v p*:410<^              <    >04:*g1+044*p                           v
  >       >^              |       -7g*:41           <                  <
v                         <
>42*42*2+*>" "\1-:v>$>:#v_v
          ^       _^ ^> >  04:*g14:*gp04:*g1+04:*pv
^                    ^         _v#-**44*44g*:40   <>14:*g1+14:*p2044*p
@theonlygusti        >^   >                        ^>
                                >                   ^

Now, this program is special in that it produces no output! None whatsoever! Instead, it modifies its own source to display 42, ASCII-art style.

                                444    22222222
                               444    222    222
                              444 444       222
                             444  444     222
                            44444444444 222
                                  444  222
                                  444 2222222222

Therefore, I recommend Alexios' interpreter to visualize it.

To make it slightly more challenging, I've tried to only use the digits 4 and 2 wherever possible, but have often used a 1 instead of (my alternative) 42%!.

I thought this would be a pretty cool concept, and I love how the program uses its own destruction to end!The program, as its overwritten, reaches some of the code which keeps the loop going, and therefore ends. I'd love to explore this idea further in the future!

One of my other ideas was to have a befunge program generate some brainfuck as its output, and the brainfuck, when run, would generate the befunge which generated it! I might try that later, post as another answer here.

\$\endgroup\$
5
votes
\$\begingroup\$

HTML 5 + Javascript

<!DOCTYPE html>
<html>
<body>

<canvas id="monalisa" width="200" height="200" style="border:1px solid #000000;">
Your browser is non-artistic !! 
</canvas>

</body>
<script>
    var question = "Answer to life the universe and everything";
    var c = document.getElementById("monalisa");
    var context = c.getContext("2d");
    context.fillStyle = "rgb(255, 0, 0)";
    var text = question.length;
    context.font = "180px Arial";
    context.strokeText(text, 1, 160);
</script>
</html>

Output:

Canvas

Demo:

http://jsfiddle.net/NmHty/1/

\$\endgroup\$
5
votes
\$\begingroup\$

Binary:

00000000011000000011111000
00000001111000001100000110
00000110011000011000000011
00011000011000000000000110
01100000011000000000011000
11111111111111000001100000
00000000011000001100000000
00000000011000011111111111
\$\endgroup\$
4
  • 5
    \$\begingroup\$ This is a programming contest, not an arranging-the-characters contest. \$\endgroup\$
    – user12205
    Commented Feb 24, 2014 at 21:40
  • 4
    \$\begingroup\$ @ace And binary is a programming language. :) \$\endgroup\$
    – Dozer789
    Commented Feb 24, 2014 at 22:12
  • 1
    \$\begingroup\$ Technically it's the ONLY programming language ;) \$\endgroup\$ Commented Feb 26, 2014 at 20:56
  • \$\begingroup\$ @MatthewWilcoxson How? \$\endgroup\$
    – user36219
    Commented Jul 31, 2015 at 17:41
5
votes
\$\begingroup\$

Bash

#!/bin/bash
if [ "$1" == "the Ultimate Question of Life, the Universe, and Everything" ]; then
echo 42
fi

produces:

~$ ./Answer "the Ultimate Question of Life, the Universe, and Everything"
42
\$\endgroup\$
1
  • 3
    \$\begingroup\$ But where is ./Question? \$\endgroup\$
    – Cole Tobin
    Commented Mar 1, 2014 at 5:42
4
votes
\$\begingroup\$

Java

This one's another one using Strings. :)
Here, I use the letters inside the title of the book to create it, while using variable names related to the book, itself.
Don't forget to include/import your library classes before executing!

String towel = "The Hitchhiker's Guide to the Galaxy";
char babel = towel.charAt(32);
char heart_of_gold = towel.charAt(34);
char harmless = towel.charAt(5);

babel = Character.toUpperCase(babel);
heart_of_gold = Character.toUpperCase(heart_of_gold);
harmless = Character.toUpperCase(harmless);

System.out.println(heart_of_gold + babel + harmless + harmless);

Output should be:

XLII

...which is Roman-Numeral for 42. :)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Can you please add the public class ClassName { public static void main(String[] args) { { ... } }? This way this answer would be complete. \$\endgroup\$ Commented Feb 24, 2014 at 3:24
  • \$\begingroup\$ @Victor This is a popularity-contest, not code-golf. The class declaration should be obvious to anyone who knows Java. \$\endgroup\$
    – IQAndreas
    Commented Mar 2, 2014 at 7:36
  • \$\begingroup\$ @IQAndreas But not everybody knows java, and without these, the program is untstable. \$\endgroup\$ Commented Mar 2, 2014 at 15:38
  • 1
    \$\begingroup\$ @Victor Someone who doesn't know Java isn't going to test the code anyway. ;) (they likely won't even have the compiler installed on their computer). \$\endgroup\$
    – IQAndreas
    Commented Mar 2, 2014 at 17:51
4
votes
\$\begingroup\$

Javascript

var x = console.log;

x('    ' +4 + '    ' + 2,2,2);
x('  ' + 4 + ' ' + 4 + '   ' + 2 + '   ' + 2);
x(' ' + 4 + '  ' + 4 + '      ' + 2);
x(4+' '+ 4+' '+ 4+  '     ' +2);
x('    ' + 4 + '   ' + 2);
x('    ' + 4 + '  ' + 2,2,2,2);

Output

    4    2 2 2
  4 4   2   2
 4  4      2
4 4 4     2
    4   2
    4  2 2 2 2
\$\endgroup\$
2
  • \$\begingroup\$ People not like my answer? I'm new, please let me know why I get no upvotes? \$\endgroup\$
    – user12183
    Commented Feb 23, 2014 at 21:38
  • 1
    \$\begingroup\$ Sorry. I didn't see it earlier. \$\endgroup\$
    – Toothbrush
    Commented Feb 24, 2014 at 0:01
4
votes
\$\begingroup\$

C one-liner

c(x,y){return(y<x?0:x?c(x-1,y)+c(x,y-1):1);}main(){printf("%d\n",c(5,5));}

The appearance of the magic number 5 is, of course, a reference to the number of books in the Hitchhiker's Trilogy.

Spoiler:

Computes the 5th Catalan number.

\$\endgroup\$
4
votes
\$\begingroup\$

PHP – 134 bytes

Description:

On 3 November 1993, he gave an answer at alt.fan.douglas-adams about the origin of “42”:

I sat at my desk, stared into the garden and thought “42 will do”. I typed it out. End of story.

Based on that answer, this should be the way Douglas Adams would have commented his PHP code…

Source:

<?php 
/* The Ultimate Answer to Life, The Universe and Everything is… */ echo(42);
/* So Long, and Thanks for All the Fish. */ exit();

The comments represent quotes by Douglas Adams, but they also fit/describe the PHP functionalities.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ +1 nice one! Even though Adams wouldn't forget a ?> at the end ;) \$\endgroup\$
    – bobbel
    Commented Feb 24, 2014 at 13:24
  • 3
    \$\begingroup\$ @bobbel [+1] on your comment. While I would like to note that the trailing ?> isn't needed in PHP, I guess you're right in the sense that Adams died before the closing ?> was deprecated. \$\endgroup\$
    – e-sushi
    Commented Feb 24, 2014 at 14:29
4
votes
\$\begingroup\$

Bash, coreutils

It seems appropriate that the manpage for random has the number 42 built in:

$ man random | head -n 1 | tr -d " " | wc -c
42
$ 

As does the above command itself:

$ s='man random | head -n 1 | tr -d " " | wc -c'
$ echo ${#s}
42
$
\$\endgroup\$
4
votes
\$\begingroup\$

Rebol

letters: charset [#"a" - #"z"]
nothing: 0
words: []

parse "the meaning of life" [
    any [
        copy word some letters (append words word) |
        space (++ nothing)
    ] (
        deep-thought: sort map-each n words [length? n]
        print (first deep-thought) * nothing * (last deep-thought)
      )
]


Output:

42

\$\endgroup\$
1
  • \$\begingroup\$ What the...:-) nice one. \$\endgroup\$ Commented Feb 26, 2014 at 22:29
4
votes
\$\begingroup\$

PowerShell

Write '42' to a bitmap, then use the pixel data to write ASCII art '42'

$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$bmp = New-Object System.Drawing.Bitmap(24, 20)
$font = New-Object Drawing.Font 'Courier Regular',20,0,2
$graphic = [drawing.graphics]::FromImage($bmp)
$graphic.DrawString(42, $font,[drawing.brushes]::White, 0, 0)

$rect = new-object drawing.Rectangle (0, 0, $bmp.Width, $bmp.Height)
[Drawing.Imaging.BitmapData]$bd = $bmp.LockBits($rect,
        [Drawing.Imaging.ImageLockMode]::ReadOnly, 
        [Drawing.Imaging.PixelFormat]::Format1bppIndexed)

$bp = New-Object Drawing.Bitmap (24, 20, $bd.Stride, 
        [Drawing.Imaging.PixelFormat]::Format1bppIndexed, 
        $bd.Scan0)

foreach($y in 0..19) {
    foreach($x in 0..23) {
        if($bp.GetPixel($x, $y).r) { $p = '42' }
        else { $p = '  ' }
        Write-Host $p -NoNewline
    }
    Write-Host
}

The output:

              4242            4242424242    
              4242          42424242424242  
            424242        424242      424242
          42424242        4242          4242
        4242  4242                      4242
        4242  4242                      4242
      4242    4242                      4242
    4242      4242                    4242  
    42        4242                  4242    
  42424242424242424242            4242      
  42424242424242424242        424242        
              4242          4242            
              4242        424242            
              4242        424242424242424242
              4242        424242424242424242
\$\endgroup\$
0
4
votes
\$\begingroup\$

JavaScript and string theory

Refactored from my other answer: Write a mathematical function whose result is "hello world"

function stringTheory(theory) {
  var proof = 0;
  var principles = theory.split(/[ ,.'-]/);
  for (var i = 0; i < principles.length; i++) {
      var formula = '';
      for (var j = 0; j < principles[i].length; j++) {
        formula += principles[i].charCodeAt(j).toString(10);
      }
      proof += +formula;
  }
  return proof;
}

console.log(
     stringTheory("Hello world")
-
     stringTheory('\2 Yo it\'s 4327 - Go to space, look back, and see the dot of a small blue rock you once sat on amid the vast empty void - KA-BOOM - you are in awe of it. "Ah" - so tiny in this vast space yet you are even more so. A mere atom in an ocean of stars, the earth a speck of dust to the sun\'s ping-pong ball. One day you shall go back and as your toes touch the soft soil once more, the cool wind in your hair as you cast your gaze upon the moon, a mere rock just like this one, and bask in it\'s warm glow - Ah. Only then can you know the scale of it all, what luck you have to call this place home.  And with this new ken, a love you\'ve kept for all of time but had not seen - for it is clear to you now. You lay open your arms and fill the air with your song - (aah) ~o Good-bye space and ... o? \3')
);

What is going on?

Using stringTheory() we subtract Hello world from '\2 Yo it\'s 4327 - Go to space, look back, and see the dot of a small blue rock you once sat on amid the vast empty void - KA-BOOM - you are in awe of it. "Ah" - so tiny in this vast space yet you are even more so. A mere atom in an ocean of stars, the earth a speck of dust to the sun\'s ping-pong ball. One day you shall go back and as your toes touch the soft soil once more, the cool wind in your hair as you cast your gaze upon the moon, a mere rock just like this one, and bask in it\'s warm glow - Ah. Only then can you know the scale of it all, what luck you have to call this place home. And with this new ken, a love you\'ve kept for all of time but had not seen - for it is clear to you now. You lay open your arms and fill the air with your song - (aah) ~o Good-bye space and ... o? \3'

and we get 42.

This is equivalent to:

191212222216211 - (2 + 89111 + 105116 + 115 + 52515055 + 71111 + 116111 + 1151129799101 + 108111111107 + 989799107 + 97110100 + 115101101 + 116104101 + 100111116 + 111102 + 97 + 11510997108108 + 98108117101 + 11411199107 + 121111117 + 11111099101 + 11597116 + 111110 + 97109105100 + 116104101 + 11897115116 + 101109112116121 + 118111105100 + 7565 + 66797977 + 121111117 + 97114101 + 105110 + 97119101 + 111102 + 105116 + 346510434 + 115111 + 116105110121 + 105110 + 116104105115 + 11897115116 + 1151129799101 + 121101116 + 121111117 + 97114101 + 101118101110 + 109111114101 + 115111 + 65 + 109101114101 + 97116111109 + 105110 + 97110 + 1119910197110 + 111102 + 11511697114115 + 116104101 + 10197114116104 + 97 + 11511210199107 + 111102 + 100117115116 + 116111 + 116104101 + 115117110 + 115 + 112105110103 + 112111110103 + 9897108108 + 79110101 + 10097121 + 121111117 + 11510497108108 + 103111 + 989799107 + 97110100 + 97115 + 121111117114 + 116111101115 + 11611111799104 + 116104101 + 115111102116 + 115111105108 + 11111099101 + 109111114101 + 116104101 + 99111111108 + 119105110100 + 105110 + 121111117114 + 10497105114 + 97115 + 121111117 + 9997115116 + 121111117114 + 10397122101 + 117112111110 + 116104101 + 109111111110 + 97 + 109101114101 + 11411199107 + 106117115116 + 108105107101 + 116104105115 + 111110101 + 97110100 + 9897115107 + 105110 + 105116 + 115 + 11997114109 + 103108111119 + 65104 + 79110108121 + 116104101110 + 9997110 + 121111117 + 107110111119 + 116104101 + 1159997108101 + 111102 + 105116 + 97108108 + 11910497116 + 10811799107 + 121111117 + 10497118101 + 116111 + 9997108108 + 116104105115 + 1121089799101 + 104111109101 + 65110100 + 119105116104 + 116104105115 + 110101119 + 107101110 + 97 + 108111118101 + 121111117 + 118101 + 107101112116 + 102111114 + 97108108 + 111102 + 116105109101 + 98117116 + 10497100 + 110111116 + 115101101110 + 102111114 + 105116 + 105115 + 9910810197114 + 116111 + 121111117 + 110111119 + 89111117 + 10897121 + 111112101110 + 121111117114 + 97114109115 + 97110100 + 102105108108 + 116104101 + 97105114 + 119105116104 + 121111117114 + 115111110103 + 40979710441 + 126111 + 71111111100 + 98121101 + 1151129799101 + 97110100 + 11163 + 3)

\$\endgroup\$
4
votes
\$\begingroup\$

C

#include <stdio.h>
const int YEAR_OF_PRODUCTION = 1979;

int main(int argc, char** argv) {
        char* name = argv[0];
        char c;
        int i = 0;
        while((c = *(name++)) != 0) {
                i += c*2;
        }
        printf("%d\n",2*(i-(YEAR_OF_PRODUCTION + 6)));

        return 0;
}

Compile as an executable named "fortytwo" and run in the same directory on a linux system as in:

./fortytwo

Result:

42

\$\endgroup\$
4
votes
\$\begingroup\$

Java

42 happens to be the number of full binary trees with six leaves.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FortyTwo {

    private static class TreeNode {
        TreeNode left;
        TreeNode right;
    }

    private static List<TreeNode> fullTreesWithNLeaves(int n) {
        if (n == 1) {
            return Arrays.asList(new TreeNode());
        } else {
            List<TreeNode> result = new ArrayList<TreeNode>();
            for (int leftLeaves = 1; leftLeaves < n; leftLeaves++) {
                int rightLeaves = n - leftLeaves;
                List<TreeNode> leftTrees = fullTreesWithNLeaves(leftLeaves);
                List<TreeNode> rightTrees = fullTreesWithNLeaves(rightLeaves);
                for (TreeNode left : leftTrees) {
                    for (TreeNode right : rightTrees) {
                        TreeNode root = new TreeNode();
                        root.left = left;
                        root.right = right;
                        result.add(root);
                    }
                }
            }
            return result;
        }
    }


    public static void main(String[] args) {
        System.out.println(fullTreesWithNLeaves(6).size());
    }

}
\$\endgroup\$
4
votes
\$\begingroup\$

Perl

am I creative enough?

print eval join ~ P & k, map length of x length, Just, another, Perl, hacker

Edit: Explanation

length of x length is a creative way to write 2 * length as it evaluates to length('of' x length($_)).

~ P & k is not a probability calculation but just a way to get a plus sign (ab)using barewords.

So in clean code, this is more or less:

print eval join '+', map 2 * length, qw/Just another Perl hacker/
\$\endgroup\$
1
  • 2
    \$\begingroup\$ I don't know, but +1 because your username is awesome. \$\endgroup\$
    – Jason C
    Commented Feb 25, 2014 at 13:14
4
votes
\$\begingroup\$

CharPlot

Plotting with Chars. You can do it with 42 and with your girl friend, too.

public class CharPlotUtil {

    private static int xStep = 2;
    private static int yStep = 2;

    public static void main(String[] args) throws IOException {

        initChars(" .:0123456789oO*+-,;dc3öÖ%qQG´");

        BufferedImage bufferedImage = ImageIO.read(new File("D:\\Temp\\Chars\\img.png"));
        // http://www.stupidedia.org/images/8/80/The_Answer_to_Life,_the_Universe,_and_Everything.png

        int normalizationFactor = 3 * xStep * yStep * 255;

        for (int y = 0; y < bufferedImage.getHeight() - yStep; y += yStep) {
            for (int x = 0; x < bufferedImage.getWidth() - xStep; x += xStep) {

                int sum = 0;
                for (int xx = x; xx < x + xStep; xx++) {
                    for (int yy = y; yy < y + yStep; yy++) {
                        int value = bufferedImage.getRGB(xx, yy);
                        int byte1 = value & 0xFF;
                        int byte2 = (value >> 8) & 0xFF;
                        int byte3 = (value >> 16) & 0xFF;
                        sum += byte1 + byte2 + byte3;
                    }
                }
                float f = ((float) sum) / normalizationFactor;
                System.out.print(CharWithGrayValue.getCharByGrayValue(f).getChar());
            }
            System.out.println();
        }
    }

    private static void initChars(String charsAsString) {

        for (int i = 0; i < charsAsString.length(); i++) {
            char c = charsAsString.charAt(i);
            CharWithGrayValue.add(new CharWithGrayValue(c));
        }
    }
}

public class CharWithGrayValue {

    private static int width = 16;
    private static int height = 24;
    private static int fontSize = 23;
    private static Font font = new Font("Courier New", Font.PLAIN, fontSize);

    private static Map<Integer, CharWithGrayValue> charsWithGrayValue = new TreeMap<>();
    private static int minGrayValue = -1;
    private static int maxGrayValue = 0;

    private char c;
    private int grayValue;

    public CharWithGrayValue(char c) {
        this.c = c;
        grayValue = getGrayValue(c);
    }

    public char getChar() {
        return c;
    }

    public int getGrayValue() {
        return grayValue;
    }

    private static int getGrayValue(char c) {

        BufferedImage charImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
        Graphics graphics = charImage.createGraphics();
        graphics.setFont(font);
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, width, height);
        graphics.setColor(Color.BLACK);
        graphics.drawString("" + c, 0, height - 4);
        return getGrayValue(charImage);
    }

    private static int getGrayValue(BufferedImage charImage) {
        int result = 0;
        for (int i = 0; i < charImage.getHeight(); i++) {
            for (int j = 0; j < charImage.getWidth(); j++) {
                if (charImage.getRGB(j, i) != -1) {
                    result++;
                }
            }
        }
        return result;
    }

    public static void add(CharWithGrayValue cg) {
        charsWithGrayValue.put(cg.getGrayValue(), cg);
        if (cg.getGrayValue() > maxGrayValue) {
            maxGrayValue = cg.getGrayValue();
        }
        if (cg.getGrayValue() < minGrayValue || minGrayValue == -1) {
            minGrayValue = cg.getGrayValue();
        }
    }

    public static CharWithGrayValue getCharByGrayValue(float normalizedGrayValue) {

        // normalizedGrayValue: 0, ..., 1
        // intGrayValue: minGrayValue, ..., maxGrayValue

        int intGrayValue = (int) (minGrayValue + (maxGrayValue - minGrayValue) * normalizedGrayValue);
        for (int gv : charsWithGrayValue.keySet()) {
            if (gv >= intGrayValue) {
                return charsWithGrayValue.get(gv);
            }
        }
        return new CharWithGrayValue(' '); // Should not happen
    }
}



                                                                                                                     ´´´´´                                      
                                              ,c7co333oc777cooooooo,                                       ´.,:*7c7;;:::::::::::,-..                            
                                             .3occo3223occccooo3ooo,                                   ´,*o3o3333o7;:::::::::*;;;;;;;:,.´                       
                                            .223occo3223oooooo33333,                                 .;555233322o7;*:::::::*;;;;;;77;;;;:,.                     
                                           ´o55233oo32523ooooo33333,                               .o55455232223c7;*::::::*;;;77777;;;;*::::.                   
                                           72555523o325523oooo33222:                             ´;255445222252o7;**::::*;;77777777;;;*:::::::´                 
                                          :325554523o32552333332222:                            ,o2554ö45225523c;;**::*;;777777777;***:::::::::-                
                                         .7o32554452332555233332222:                          ´:o2554öö5555553o7;;***;;7777cccc77;;;**:******:;;:´              
                                        .*;7o3554öö4523254522222222:                         ´73325ö664555552o7;;;**;;7cccccoc77;;;****;;;;;;;77;*´             
                                       ´;;;;7o254öö6452254452222255:                        ´73325ö68ö4554453c7;;;;;7cooooooo77;;;;;;;;**;;;;77777;´            
                                      ´;77;;;7o254ö6645225ö45222255:                        72325ö688ö554ö53o77;;;77ooooooooc7;;;;;;;;;;;;777777c77;´           
                                      *oc777;;7o24ö688ö525464522255:                       :522546886444ö42oc77;77co333333oc77;;;;;;;;777777ccoccccc:           
                                     :33ooc7777c3246888ö555ö6455555:                      .5522468G8ö4ö6ö53c7777co3333333oc77;;;;;;;7777cccooooocc777-          
                                    ,22233oooc77c35ö688865548845555:                      2552568GG8öö6653oc777o33222223oo7777777777cccooooooooccccc7;´         
                                   .322552233ooc7o35ö88GG6456884555:                     :4555ö8GG86688423occoo32222223oo77777777ccoooo333ooooooccc7;7:         
                                  ´7o3225552233oooo3568GGG84ö8G8454:                    ´5ö5548GGG8888ö23oooo322555523oocccccccoooo33333333ooooocc77;;;´        
                                 ´;cco325544552233oo256GG%G8ö6GG844:                    :6ö558G%%G88G6533oo32255555233ooooooooo333222223333ooooc777;*;;,        
                                 :77coo3255öö45522333258G%%G8ö8GG6ö:                    28ö56G%%G8GG8523333255544553:.´´´´.:o32225522223333oooc77;;*;;**        
                                ,777ccoo3255ö664552223258G%q%86GGG6:                   .88öö8Gq%GGGGö2333255444452:´        ´:555555222333ooc77;;;;;;*;;.       
                               .;;77ccoo332254686ö45223248%%q%G8G%G:                   *88ö8GqqGGGG65233254öööö52.            -5455522233occ777;;;;*::::,       
                              ´*;;777cooo3322546886ö452224G%qq%GG%%*                   5886Gqq%G%%8522254ö666ö52.              .5555223ooc77;;;;;***:::;:       
                             ´:*;;;777coo332225468G88ö45224GqqqqGG%;                  ´G888%qq%%%G45225ö6888ö55:                :55233oo777;;;;;**::::*::´      
                            ´::**;;;777coo332255468GGG8ö455öGqqQqG%;                  :G88%qQq%qG65254888G8ö453                 ´323ooc77;;;;;;*****:;*::.      
                            ,:::**;;;77cco33222554ö8G%GG8ö45öGqQQqG;                  7G8GqQqqq%845568GGG86455,                  :ooc777;;;;;****::::*:::.      
                           .:::::*;;;;77coo33225554ö8G%%GG864öGqQQq*                  4G8qQQqqq8ö548GGGG8644ö4´                  .oc777;;;;;****:::::::::.      
                          .::::::**;;;777coo33225554ö8G%qqGG866GQQQ;                  GG%QQQqqG6ö68GG%G86ö668o                   ´c777;;;;;****::::::::::.      
                         ´:::::::**;;;;777coo3322554ö68GGqqqGG88GQQ7                 .%GQQQQQG868G%%%G88888GG:                    777;;;;;;****::::::::::.      
                        ´:::::::***;;;;777ccoo.322554ö68GG%qqqG88GQ7                 :GqQQQQ%868Gqq%G88GGG%qq.                   ´777;;;;;;***::*::::::::.      
                        :;;********;;;;7777co, 3322554ö88GG%qQq%G8G;                 ;%QQQQq88G%qq%GGGGGqqQQq                    .77;;;;;****:**::::;**::.      
                       :777;;;;;;;;;;;;7777c:  33322554ö88GG%qQQq%G*                 ´´´´´´´´´´´´´´´´´´´´´´´´                    ,77;;;;;;*****::::::::::´      
                      ,7777ccccccc77777777c*   333222554ö88GGGqQQQq;                                                             ;77;;;;;;***::::::::::::       
                     .7777ccoooooooooooooo7´   3333222554ö88GG%qQQQ7                                                            .77;;;;**::::::::::::::::       
                    ´;7777ccoooo3333222223.    33332222554ö88GG%qqQ7                                                            ;7;;;;**::::::::::::::::.       
                   ´*77777ccoooo333322255.     555222225554ö888G%qq7                                                           ,;;;;**::::::::::::::::::.       
                   :;;;;7777cooo33332255:      6666öö445544ö6888GGq;                                                          .;;;;**:::::::::::::::::::        
                  ,***;;;;7777cooo33322*       6888GGGGG8888888888G*                                                         ´;;;;;;***::::::::::::::::-        
                 .:::****;;;;777ccooo3;        6688GGGGG%%%%%GG8888*                                                        ´*77;;;;;;***::::::::::::::´        
                .::::::::***;;;;777co7´        44ö688GGG%%qqqqQQQqq;                                                       ´;77777;;;;;;;;*****;*:*:::,         
               ´:::::::::::::**;;;;77´         25554ö688GGG%qqqQQQQ7                                                      ´73ooooocccc7777777;7;;77;;;´         
              ´,:::::::::::::::::**;.          332225554ö6888GGG%qQ7                                                     .2555522223333ooooooccc7c777:          
              ,::::::::::::::::::::.           ooo33332225554ö66688:                                                    ,688866ööö4455522223333ooooo7´          
             -:::::::::::::::::***,            2222554ö6888GG%qqqQQ7                                                   :44445555522223333ooooocccc77.           
            .:::::::::::**;;;;777:             688GGGG%%qqqqqqqqqQQ7                                                  :333ooooooccc77777777;;;;;;;;,            
           .::::*;;;;;;7777cooo37´             888888GGGGGG%qqQQQQQ7                                                ´;cc777;;;;;*****::::::::::::::             
          ´:;;;77777cccoooooo33o´              444ö688G%qQQQQQQQq%G*                                               .3233ooc777;;;**:::::::::::::::´             
         ´:;7777777777777ccccoo.               68GG%qQQQQQQqGG88GGG*                                              :445552233ooc777;;;**::::::::::´              
         :;77;;;;;;;;;;;777777-                %qqqQqq%G8666888GG8G*                                            ´c4455555222233oocc77;;;;***::::´               
        ,:********;;;;;;;;;77,                 %GG86ö5555ö68888888G;                                           .3555555522223333ooooc7777;;;;*:.                
       .:**:::::*****;;;777c*                  552222554ö6666688GqQ7                                          ,o333332222223333oooocc777777;;;.                 
      ´:::::::***;;;;77coo37´                  333225554444ö688qQQq;                                         *233oocccoooooooooooocc777777;;*´                  
     ´:::::*;;;;;777coo3323´                   322255555554ö8%QQq%q7                                       ´3455233oc77777777777777777777;;:´                   
    ´:****;77777cooo332255.                    222222225556GqQqGGqq;                                      .ö86ö455233oc7;;;*;;;;;;;;;;;;;;:´                    
    ,;;;;7777cooo3333333o-                     333332225öGqQqGG%q%G;                                     ,qq%86ö4552233oc7;;*::::::::****,                      
    ,;;777ccoooooooocc77*--.......---,,,,,,,,,,333322248%qqG8G%qGGQö7**77;;77;                          :8qQQqG8ö4552223oo77;;*:::::::::.                       
    :77ccccc777777;;;;**:::::::**;;;7777ccccoooo333256GqqG88G%%8GQQQq8QQQqQQQq                         *5548%qqqG8ö552233ooc77;;*:::::,´                        
    :77777;;;;;;**::::::::::::**;;;;77777777cooo33248%%G8ö8G%G8GQQQq6qQQ%qQQ%q                        cö552256Gqq%G8452233oooc77;;*::-                          
    ,;;;;***:::::::::::::::::**;;;;;;;;77777coo3258G%G8öö8GG86GQQQq6GQQqGQQQGq                      ´3G8ö552225ö8%qG8645233oocc77;;:.                           
    ,:::::::::::::::::::::::****;;;;;;;;7777co25ö8GG645ö8GG6öGQQQqö8QQQG%QQqGq                     ´2GG884522333248G%G8ö4523oocc77:´                            
    ,::::::::::::::::::::::::::*****;;;;777c3248G86455ö8G844GQQQ%ööqQQ%GqQQGGq                    ´6qG8886452233o3256GGG8ö523ooc7-                              
    -:::::::::::::::::::::::::::::**;;;;77o25ö88ö5525ö88ö54GqQQ%ö5GQQqGGQQqGGq                   ´2%qqG8666452233ooo25ö8G864523;´                               
    -:::::::::::::::::::::::::::::**;;;7o32466ö55225ö8ö554GqQq%628qQqG8GQQ%8G%                  ´4G8GqqG6ööö45223ooc7o324688ö4*´                                
    -:::::::::::::::::::::::::::::**;;7o25ö64522225öö4524Gqqq%ö2ö%qQG8GqQqG8GG                 ´2q%86GqqG644445233oc777c325öö,                                  
    -:::::::::::::::::::::::::::::*;7o324ö45233325445224GqqqGö25Gqqq88GqQ%88GG                 3GGqG6öGq%Gö4555523ooc77;;7oc.                                   
    -::::::::::::::::::::::::::::;;co3545523oo3254522248qqqGö228qqqG68GQqG68G8                7qG8G%Gö48%%8ö5555523oc777;;:´                                    
    -::::::::::::::::::::::::::*;7o3255233oco3255523258qq%Gö23ö%qqG668qQ%8ö8G8               :G%G88G%8448G%8ö5555223oc77;,                                      
    -::::::::::::::::::::::::*;77o32223oo7co325523o358%%%Gö235G%q%846GqqG648G8              .ö8G%G68GG8556GG845222223oc7,                                       
    -:::::::::::::::::::::::*;7c32233oc77co32523oo358%%GG42o28%%%8448%q%8ö4886             ´24ö8GG8ö8GGö55öGG84522223oo,                                        
    -:::::::::::::::::::::*;77o333ooc777co3223ooc358GGG842o3öG%%Gö5ö8qqG65488ö             ;454ö8GG6ö8G8425ö8G64233333,                                         
    -:::::::::::::::::::*;;7co3ooc77;;7co333oocc358GG8842o358G%G655öGq%8ö5486ö            -45555ö8G8448G65224886523337,,,,,--.........--,,,,,,,,,,---.....      
    -:::::::::::::::::**;77ooooc77;;;7co33ooc7c356888842co26GGG85556GqG652ö8ö4           ´5455555688ö5468ö522568ö523oooooc77;;*::::::::*;77coooo7777;;***:      
    .::::::::::::::::*;;7coocc7;;*;;77ooooc777356888653c7348GG842548%%8ö52ö644           *645555556864546842325ö8ö52ooooooc7;;**:::::::::*;;77cooc77;;;;::      
    .:::::::::::::::;;77ccc77;;**;;77oooc77;735ö886653c7o588G8ö2254GqG6525öö55          ´86ö552255468ö5546652o35ö6ö53oocccc77;;**::::::::::*;;777oc777;;;;      
                                               66öö537;c2ö888ö5225ö*                    7G8ö552222548645546ö53o3246453occc7777;;**::::::::::::*;;777777;;;      
                                               öö4537;7356886522258*                   ´8G8ö52222225ö6ö5254ö423o325ö423o7777777;;*::::::::::::::**;;7cc77;      
                                               44537;;o5ö6864232248;                   ;888ö522222225öö52255ö52oco354523o777777;;;**::::::::::::::*;;;7777      
                                               52o7;;c24ö66423325öG*                  ´4888ö5522333225ö452325453o7o32452oc7777;;;;;*:::::::::::::::::*;;;7      
                                               2o7**7354ö6ö53o3256G:                  ,ö688ö55233333355ö523325523c7o32553oc7;;;;;;;***:::::::::::::::::**;      
                                               o7*:;o244öö53oo3258G:                  34ö66ö552333o33254453o32553o77co3523o77;;;;;;;**::::::::::::::::::::      
                                               7*:;73544ö52ooo32488:                 .544ö6ö55233oooo3254523o32523o7;7o3223o77;;;;;*;;::::::::::::::::::::      
                                               *::7o254452ocoo35ö8ö:                 :554ö6ö5523oooooo325523oo3222oc;;7o3223o7;;;**;;;**::::::::::::::::::      
                                               ::;c3555423ccoo25684:                 o5554öö5523oooccoo32553oco3323o7;;7co33oc7;;**;;;;;***:::::::::::::::      
                                               :*73255553o7coo248ö5:                ´255554ö5223ooccccco32523oco3323c7;;7co33oc7;*;*;**:::::::::::::::::::      
                                               :;o222553o77co35ö642:                -25555445223occ777cco3223oc7oo33o7;;;;7oo3o77;;**::;;***::::::::::::::      
                                               ;7322253o777co35öö53,                :22225545233occ77777co323oc77co33o7;**;7coocc7;*:******:::::::::::::::      
                                               7o32222oc;77co25ö523,                ;32222555233oc7777777co323o777coooc7;**;77ooo77;;*::::::::::::::::::::      
                                               c33322oc7;77co24453o,                o32222555233oc77777777co33oc777co3oc7;**;7ccoc7;;**:::::::::::::::::::      
                                               o33323c7;;77c324523c,               ´oo333225523ooc777;;;;77co3oo7;;7cooc7;;:*;77coc7;;*:::::::::::::::::::      
                                               o3333o7;;;77o35423o7,               .co333322523ooc77;;;;;;77co3oc7;;77coc7;*:*;;7cc77;;**:::::::::::::::::      

This is the source image:

42

\$\endgroup\$
4
votes
\$\begingroup\$

XAML

I really love challenges like this one, as they give you a bit of freedom to experiment. In this case I discovered that Inkscape (a cool free vector graphic application on the PC) can be used to generate XAML. Which for me is awesome and something I never knew before this challenge!

First, I used Inkscape to create a nice colourful vector image or the number 42 (not very exciting as I'm no graphic designer). I then chose to "Save As" and selected "Microsoft XAML (*.xaml)" as the file type.

The vector image of 42 within Inkscape

The output from this is then easily copied into a XAML file within a WPF project.

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
        <Canvas Name="svg2" Width="346" Height="250">
            <Canvas.Resources>
                <LinearGradientBrush xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="linearGradient3762" MappingMode="RelativeToBoundingBox" StartPoint="0,0" EndPoint="1,1">
                    <LinearGradientBrush.GradientStops>
                        <GradientStopCollection>
                            <GradientStop Color="#FFFF0000" Offset="0"/>
                            <GradientStop Color="#FFFFFF00" Offset="0.18175817"/>
                            <GradientStop Color="#FF00FF00" Offset="0.42157799"/>
                            <GradientStop Color="#FF00FFFF" Offset="0.48468846"/>
                            <GradientStop Color="#FF0000FF" Offset="0.73672789"/>
                            <GradientStop Color="#FFFF00FF" Offset="0.8971166"/>
                            <GradientStop Color="#FFFF00FF" Offset="1"/>
                        </GradientStopCollection>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
                <LinearGradientBrush xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="linearGradient3768" MappingMode="Absolute" StartPoint="106,248" EndPoint="282,248">
                    <LinearGradientBrush.GradientStops>
                        <GradientStopCollection>
                            <GradientStop Color="#FFFF0000" Offset="0"/>
                            <GradientStop Color="#FFFFFF00" Offset="0.18175817"/>
                            <GradientStop Color="#FF00FF00" Offset="0.42157799"/>
                            <GradientStop Color="#FF00FFFF" Offset="0.48468846"/>
                            <GradientStop Color="#FF0000FF" Offset="0.73672789"/>
                            <GradientStop Color="#FFFF00FF" Offset="0.8971166"/>
                            <GradientStop Color="#FFFF00FF" Offset="1"/>
                        </GradientStopCollection>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
                <LinearGradientBrush xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="linearGradient3780" MappingMode="Absolute" StartPoint="106,248" EndPoint="282,248">
                    <LinearGradientBrush.GradientStops>
                        <GradientStopCollection>
                            <GradientStop Color="#FFFF0000" Offset="0"/>
                            <GradientStop Color="#FFFFFF00" Offset="0.18175817"/>
                            <GradientStop Color="#FF00FF00" Offset="0.42157799"/>
                            <GradientStop Color="#FF00FFFF" Offset="0.48468846"/>
                            <GradientStop Color="#FF0000FF" Offset="0.73672789"/>
                            <GradientStop Color="#FFFF00FF" Offset="0.8971166"/>
                            <GradientStop Color="#FFFF00FF" Offset="1"/>
                        </GradientStopCollection>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
                <LinearGradientBrush xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="linearGradient3782" MappingMode="Absolute" StartPoint="106,248" EndPoint="282,248">
                    <LinearGradientBrush.GradientStops>
                        <GradientStopCollection>
                            <GradientStop Color="#FFFF0000" Offset="0"/>
                            <GradientStop Color="#FFFFFF00" Offset="0.18175817"/>
                            <GradientStop Color="#FF00FF00" Offset="0.42157799"/>
                            <GradientStop Color="#FF00FFFF" Offset="0.48468846"/>
                            <GradientStop Color="#FF0000FF" Offset="0.73672789"/>
                            <GradientStop Color="#FFFF00FF" Offset="0.8971166"/>
                            <GradientStop Color="#FFFF00FF" Offset="1"/>
                        </GradientStopCollection>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </Canvas.Resources>
            <!--Unknown tag: sodipodi:namedview-->
            <!--Unknown tag: metadata-->
            <Canvas Name="layer1">
                <Canvas Name="text2985" Opacity="1">
                    <Canvas.RenderTransform>
                        <MatrixTransform Matrix="1.9031797 0 0 2.3496285 -195.43459 -460.36446"/>
                    </Canvas.RenderTransform>
                    <Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path2990" Fill="{StaticResource linearGradient3780}" StrokeThickness="4" Stroke="#FF000000" StrokeMiterLimit="4">
                        <Path.Data>
                            <PathGeometry Figures="m 144.81139 296.64789 c 0.42183 -4.17187 0.79683 -8.60156 1.125 -13.28906 0.32808 -4.68749 0.56245 -8.41405 0.70312 -11.17969 l -7.66406 0.0703 -5.76563 0 -26.4375 0.42188 0.21094 -2.17969 c 0.0469 -0.5156 0.11718 -2.03904 0.21094 -4.57031 l 0.5625 -13.35938 c 0.0469 -1.2187 0.0703 -2.50777 0.0703 -3.86719 4.78124 -5.76557 10.30077 -12.94915 16.55859 -21.55078 6.25779 -8.60148 12.22263 -17.42569 17.89454 -26.47265 7.2187 0.0938 13.71088 0.14072 19.47656 0.14062 5.43743 1e-4 11.01555 -0.0468 16.73437 -0.14062 -0.79695 9.93758 -1.41804 19.65242 -1.86328 29.14453 -0.44538 9.49224 -0.69148 16.67583 -0.73828 21.55078 2.24992 0.0938 4.89836 0.14067 7.94531 0.14062 2.39054 5e-5 3.77335 -0.0117 4.14844 -0.0352 0.37491 -0.0234 1.28898 -0.082 2.74219 -0.17578 -0.18759 5.62504 -0.28134 11.55472 -0.28125 17.78906 l 0 3.30469 c -2.81259 -0.18748 -6.96102 -0.28123 -12.44531 -0.28125 l -2.88282 0.0703 c -0.37507 4.54689 -0.56257 12.70313 -0.5625 24.46875 -4.64069 -0.0937 -9.44537 -0.14063 -14.41406 -0.14063 -4.64068 0 -9.75005 0.0469 -15.32812 0.14063 z m 5.83593 -44.22656 1.47657 -31.71094 c -3.0938 4.82819 -5.62505 8.67194 -7.59375 11.53125 -1.9688 2.85943 -3.39848 4.8985 -4.28907 6.11719 l -10.19531 14.0625 z" FillRule="NonZero"/>
                        </Path.Data>
                    </Path>
                    <Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path2992" Fill="{StaticResource linearGradient3782}" StrokeThickness="4" Stroke="#FF000000" StrokeMiterLimit="4">
                        <Path.Data>
                            <PathGeometry Figures="m 200.78014 296.64789 c 0.18749 -2.20312 0.33983 -5.12109 0.45703 -8.75391 0.11718 -3.6328 0.26952 -7.34764 0.45703 -11.14453 4.87499 -3.98435 9.35155 -7.85153 13.42969 -11.60156 6.60934 -6.09371 12.46871 -11.81246 17.57812 -17.15625 4.07808 -4.26557 7.49996 -8.17963 10.26563 -11.74219 1.5937 -2.10931 2.64838 -3.86712 3.16406 -5.27344 0.37495 -0.98431 0.56245 -1.99212 0.5625 -3.02343 -5e-5 -1.35931 -0.30474 -2.5429 -0.91406 -3.55079 -0.60943 -1.00773 -1.57037 -1.8632 -2.88282 -2.5664 -1.31254 -0.70305 -2.90629 -1.26555 -4.78125 -1.6875 -1.87504 -0.4218 -4.00785 -0.63274 -6.39843 -0.63281 -3.28129 7e-5 -6.73831 0.28132 -10.3711 0.84375 -3.63283 0.56257 -8.58986 1.6407 -14.87109 3.23437 l 1.82812 -10.05469 c 0.42187 -2.01554 1.03124 -5.88272 1.82813 -11.60156 12.3281 -2.0624 23.88277 -3.09365 34.66406 -3.09375 4.92182 1e-4 9.63275 0.44541 14.13281 1.33594 4.49994 0.89072 8.53118 2.40244 12.09375 4.53515 3.56242 2.13291 6.2343 4.61728 8.01563 7.45313 1.78116 2.83602 2.67179 5.89461 2.67187 9.17578 -8e-5 2.15632 -0.25789 4.28913 -0.77343 6.39844 -0.51571 2.01569 -1.47665 4.38288 -2.88282 7.10156 -1.78133 3.37506 -3.98445 6.70318 -6.60937 9.98438 -3.8907 4.92192 -8.39069 10.00785 -13.5 15.25781 -4.87506 4.96878 -10.73443 10.5469 -17.57813 16.73437 l 7.73438 0.0703 c 1.82807 2e-5 5.44916 -0.0469 10.86328 -0.14063 5.41399 -0.0937 9.17571 -0.18748 11.28516 -0.28125 2.10929 -0.0937 4.71085 -0.30467 7.80468 -0.63281 -0.1407 2.25002 -0.36336 5.06251 -0.66797 8.4375 -0.30476 3.37501 -0.62117 7.5 -0.94921 12.375 -11.67195 -0.0937 -23.88287 -0.14063 -36.63282 -0.14063 -15.37503 0 -28.38282 0.0469 -39.02343 0.14063 z" FillRule="NonZero"/>
                        </Path.Data>
                    </Path>
                </Canvas>
            </Canvas>
        </Canvas>
    </Viewbox>
</Grid>

Here, the entire Viewbox element is generated by Inkscape.

Running the project outputs the number 42 as follows:

Beware of the Leopard

\$\endgroup\$
1
  • \$\begingroup\$ +1 for boldly admitting you let an app generate the code for you. This 42 totally needs to drink a smart drink and rave all night. \$\endgroup\$ Commented Feb 28, 2014 at 21:20
4
votes
\$\begingroup\$

Infinite Brainfuck

Maybe not creative, but it sure was time-consuming as f*ck. Given a Brainfuck program as input, it outputs an equivalent Brainfuck program that's twice as large.

Here's the code:

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>>><<

<<     << <<<<<<
<<     << <<<<<<<<<
<<     <<        <,+
[-     --         --
--     --        --[
+++++++++      +--
---------    ---
       --  ---
       -- --
       -- --
       -- --->[-]+>[
       -] <<[+++++++

++     ++ ++++++
++     ++ +++++++++
++     >>        >>>
>>     >>         >+
++     ++        +++
+++++++++      +++
+++++++++    +++
       ++  +++
       >> >>
       >> >>
       >> ++++++++++
       ++ ++++++++++

++     ++ ++++++
++     ++ +<<<<<<<<
<<     <<        <<<
<<     <<         <[
->     >>        >>>
>>>>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>[
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>>>]<

<<     <+ <<<<<<
<<     << <<<<<<<<<
<<     <<        <<<
[<     <<         <<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<<<]<<    <<]
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>>[>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        >]+
[<     <<         <<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<<<]<<    <<+
       ++  +++
       ++ ++
       ++ ++
       ++ ++++++++++
       ++ ++++++++++

++     ++ ++++++
++     ++ [->>>>>>>
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>[>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >] <<<<+<<<<<
       << <<<<<<<<<<

<<     << <<<<<[
<<     << <<<<<<<<<
<<     <<        <<<
<<     <<         <<
<<     <<        ]<<
<<]>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       [> >>>>>>>>>>
       >> >>>>>>>>>>

>>     >> >>>]+[
<<     << <<<<<<<<<
<<     <<        <<<
<<     <<         <<
<<     <<        ]<<
<<+++++++      +++
+++++++++    +++
       ++  +++
       ++ ++
       ++ ++
       ++ ++++++++++
       ++ +[->>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        [>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>>]<<<<+    <<<
       <<  <<<
       << <<
       << <<
       << <<<<<<<<[<
       << <<<<<<<<<<

<<     << <<<<<<
<<     << <<<]<<<<]
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>[>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>]+[<
       << <<<<<<<<<<

<<     << <<<<<<
<<     << <<<]<<<<+
++     ++        +++
++     ++         ++
++     ++        +++
+++++++++      +++
+++++++++    [->
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>[>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        ]<<
<<     +<         <<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<[<<<<    <<<
       <<  <<<
       << <<
       << <<
       << <<<<<<<<]<
       << <]>>>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >[        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>]+[<<<<    <<<
       <<  <<<
       << <<
       << <<
       << <<<<<<<<]<
       << <>-]>[<+++

++     ++ ++++++
++     ++ +++++++++
++     ++        ++>
>>     >>         >>
>>     >+        +++
+++++++++      +++
+++++++++    +++
       ++  +++
       ++ +>
       >> >>
       >> >>>+++++++
       ++ ++++++++++

++     ++ ++++++
++     ++ +++<<<<<<
<<     <<        <<<
<<     <<         <<
<>     ->        ]<<
>>>>>>>>>      >[-
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>[>>
       >> >>>>>>>>>>

>>     >> >>>>>>
>>     >> >>]<<<<+<
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<[<<<      <<<
<<<<<<<<<    <<<
       <<  <<<
       << <<
       << <]
       << <<]>>>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>>
>>     >> >[>>>>>>>
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>]+[<<<      <<<
<<<<<<<<<    <<<
       <<  <<<
       << <<
       << <]
       << <<>>>>>>>>
       >> [->>>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >[        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>]<<<<+<    <<<
       <<  <<<
       << <<
       << <<
       << <<<<<<<[<<
       << <<<<<<<<<<

<<     << <<<<<<
<<     << <<]<<<<]>
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>[>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>]+[<<
       << <<<<<<<<<<

<<     << <<<<<<
<<     << <<]<<<<<<
<<     <<        <<<
<<     <<         <<
<<     <<        <,-
---------      ]>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>[>>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
]>     [<        <<<
[-     >>         >>
[<     <<        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <<<
       ]>  +<<
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>>>[>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        >>]
<<     <]         >>
>+     >[        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <<<
       <<  <]>
       -- --
       -- --
       -- ----------
       -- ----------

--     -- ->[-]+
>[     -] <<[++++++
++     ++        +++
++     ++         ++
++     ++        +++
+++++++++      ++>
>++++++++    +++
       ++  +++
       ++ ++
       ++ ++
       ++ ++++++..[-
       ]< <>-]>[<+++

++     ++ ++++++
++     ++ +++++++++
++     ++        +++
++     ++         <<
<<     <<        <<<
<<<<<<>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> [>>>>>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>]
<<     <[ ->>>>[<<<
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<<]>      +<<
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>[>>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>>
>>     ]< <<]>>>+>[
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<<<<      <]>
.[-]<<<<<    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>[>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>]     <<        <[-
>>     >>         [<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <]>
       +<  <>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>[>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        ]<<
<]     >>         >+
>[     <<        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <<<
       <]  >.[
       -] <<
       << <>
       >> >>>>>>>>>>
       >> >->]<<[-]<

<>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        >>>
>[     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>>>>>>]>    ]>+
       ++  +++
       ++ ++
       .[ -]
       << <<<<<<<<<<
       << <<<<<<<<<<

<<     << <<<[<<
<<     << <<<<<<<<<
<<     <<        <<<
<<     <<         <<
<<     ]<        <<<
>>>>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>[>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>>
>>     >] >[<<<<[->
>>     >[        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<<<<      <<<
<<]>+<<>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       [> >>>>>>>>>>

>>     >> >>>>>>
>>     >> >>>>>]<<<
]>     >>        +>[
<<     <<         <<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<<]>--    ---
       --  ---
       -- --
       -- --
       -- ----------
       -- ----->[-]+

>[     -] <<[+++
++     ++ +++++++++
++     ++        +++
++     ++         ++
++     ++        +++
+>>++++++      +++
+++++++++    +++
       ++  +++
       ++ ++
       ++ ..
       [- ]<<>-]>[<+
       ++ ++++++++++

++     ++ ++++++
++     ++ +++++++++
+<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> [>>>>>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>]
<<     <[ ->>>>[<<<
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<<]>      +<<
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>[>>>>>>
       >> >>>>>>>>>>

>>     >> >>>>>>
>>     ]< <<]>>>+>[
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<<<<<      <]>
.[-]<<<<<    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>[>>>>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>]     <<        <[-
>>     >>         [<
<<     <<        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <]>
       +<  <>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>[>>>

>>     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        ]<<
<]     >>         >+
>[     <<        <<<
<<<<<<<<<      <<<
<<<<<<<<<    <<<
       <]  >.[
       -] <<
       << <>
       >> >>>>>>>>>>
       >> >>>>>>>>>>

>-     >] <<[-]<
<>     >> >>>>>>>>>
>>     >>        >>>
>>     >>         >>
>>     >>        >[>
>>>>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       ]> ]>
       ++ ++
       ++ ++++.[-]<<
       << <<<<<<<<<<

<<     << <<<<<<
<<     << <<<[<<<<<
<<     <<        <<<
<<     <<         <<
<<     <<        <<<
<<<<<]<<<      <<<
<<<<<<<<<    <<<
       <<  <<<
       << <<
       << <<
       << <<<<<<<<<<
       << <<<<<<<<<,

+]     >> >>>>>>
>>     >> >>>>>>>>>
>>     >>        >>>
>>     >>         >>
>>     >>        >>>
>>>>>>>>>      >>>
>>>>>>>>>    >>>
       >>  >>>
       >> >>
       >> >>
       >> >>>>>>>>>>
       >> >>>>>>>>>>

And a snippet of the output that results when you run it with itself as input*.

>42*          >42*  >42*>42*>42*
>42*          >42*  >42*>42*>42*
>42*          >42*  >42*>42*>42*>42*>4
2*>4          2*>4  2*>42*>42*>42*>42*
>42*          >42*                >42*>4
2*>4          2*>4                2*>42*
>42*          >42*                  >42*
>42*          >42*                  >42*
>42*          >42*                >42*>4
2*>4          2*>4                2*>42*
>42*>42*>42*>42*>4            2*>42*
>42*>42*>42*>42*>4            2*>42*
>42*>42*>42*>42*>4        2*>42*
>42*>42*>42*>42*>4        2*>42*
              >42*    >42*>4
              2*>4    2*>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*<4
2*<4          2*<4  2*<42*<42*<42*<42*
<42*          <42*                <42*<4
2*<4          2*,4                2*+42*
[42*          -42*                  -42*
-42*          -42*                  -42*
-42*          -42*                -42*-4
2*-4          2*-4                2*[42*
+42*+42*+42*+42*+4            2*+42*
+42*+42*+42*+42*-4            2*-42*
-42*-42*-42*-42*-4        2*-42*
-42*-42*-42*-42*-4        2*-42*
              -42*    -42*-4
              2*-4    2*-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*

Note: EOL and EOF behavior varies by Brainfuck implementation and environment. This code expects a single 10 for EOL, and -1 for EOF.

* Theoretically. I couldn't actually get this to work -- it caused a segfault. But running it on smaller inputs worked.

\$\endgroup\$
1
  • \$\begingroup\$ I don't agree that it's an "infinite brainfuck" if it requires input to run. If it were a proper quine (no input, copies itself as output) then it would be infinite. \$\endgroup\$
    – grovesNL
    Commented Mar 10, 2014 at 2:32
4
votes
\$\begingroup\$

Python

Patterned from the Evolution of Text. Churns out random text, but keeps the parts that match your target.

Program:

import random,time

def joined(string):
    return ''.join(string)

print("The Evolution of the Question")
theQuestion = "The Answer to Life, the Universe and Everything is 42"
letters = [chr(i) for i in range(32,127)]
randomString = [random.choice(letters) for i in range(len(theQuestion))]
print("Our first guess:", joined(randomString))
nextGuess = list()

evol = 0
while joined(randomString) != theQuestion:
    nextGuess = list()
    evol += 1
    for i in range(len(randomString)):
        if randomString[i] == theQuestion[i]:
            nextGuess.append(theQuestion[i])
        else:
            nextGuess.append(random.choice(letters))
    print("Next:", joined(nextGuess))
    randomString = nextGuess
    time.sleep(0.5)

print("in {} generations.".format(evol))

Output:

The Evolution of the Question
Our first guess: :Z[_8v~(sH!F'^[8D*g4*vTa|gDa/ 6evII&]Ni{SIixV7jq=7u8e
Next: F9p\pS,IF5sBOA<J<QfYd}Fm!93r~LQeQ|aY60v%lNx!z!Dt8]@r\
Next: |(E\V5>:zJ"<:?1p}}Y`EjyY|X<v#jheSTt1*(v_! Io{N%')wpoh
Next: d@o6x4/*{: @PLXV`>aF9p53+f`v/-<e|,21_evFH>zqx$RBw(8YU
Next: y7ZT>cNqfr ;Od7]@w.~)yDVEdwv6IgeFWWJA.vbr!wr*Gy_3MJ(&
Next: ^A$Ea\L5Kr Vd-TnL;m5%nh32OkvZ4_eJGJuHsvsrSw<l`&AoK,HC
Next: (MRnA,.Myr gwqpj!+!Ow&li;?Fv0}fe0B5UeEv;r-nPw:P9hgupw
Next: Pba4Ak5"pr s|mHq<sFDAqQJTd]vSk0eS0yf$EvTr=&m+V)@T7O y
Next: HcmVA<qn\r qG2!|Aa\*c[ ghS4v;y e]<aB1Ev`rv?$c\QGy`GTq
Next: [cR/A$;r,r ziXe}%Rqli)6+=Sgvc\Le2BF!bEvFrc\1dP'Z.+^9I

and 300-400+ evolutions later...

Next: The Answer to Life, tRe Universe and Everything is 42
Next: The Answer to Life, tFe Universe and Everything is 42
Next: The Answer to Life, t%e Universe and Everything is 42
Next: The Answer to Life, t)e Universe and Everything is 42
Next: The Answer to Life, tke Universe and Everything is 42
Next: The Answer to Life, tke Universe and Everything is 42
Next: The Answer to Life, the Universe and Everything is 42
in 498 generations.
\$\endgroup\$
4
votes
\$\begingroup\$

ised

ised '[]'

It's an easter egg... an empty constructor returns 42!

This would probably win a code-golf entry (with only 2 characters), but for a popularity contest, it's just an interesting piece of information :)

\$\endgroup\$
4
votes
\$\begingroup\$

Bro... no...

This is how you output 42:

import Control.Monad                --               _                       _
                                    --              | |                     | |
bros :: (Integral n, Monad m)       --            =H| |=====mn=======nm=====| |H=
     => (n -> n) -> m n -> m n      --              |_|     ( \     / )     |_| 
bros = do                           --                       \ )(")( /
       you even                     --                       ( /\_/\ )
       liftM                        --                        \ 4 2 /
  where                             --                         )=O=(
    you = liftM                     --                        /  _  \
                                    --                       /__/ \__\
fact = sum . bros succ . tail       --                       | |   | |
                                    --                       |_|   |_|
main = print $ fact [1..8]          --                       (_)   (_)
\$\endgroup\$
4
votes
\$\begingroup\$

C++, It's Not Always Sunny Over There

Edit:

1) I don't need the average velocity anymore thanks to the 3rd Kepler's law (see how the period is computed; 92955807 because 1 AU = 92955807 miles). 2) Use of TAU instead of PI.

Version 1

#include <iostream>
#include <cmath>

#define TAU 6.283185307179586
#define D double

int north;

int main(){

    D theta = 0.000001;

    D farthest = 1868039489; // miles
    D closest = 1699449110; // miles
    D eccentricity = 0.04725744;
    
    D a = (closest + farthest) / 2;
    D b = (a * 2 * sqrt(1 - pow(eccentricity, 2))) / 2;
    D period = sqrt(pow(a / 92955807, 3));

    for (D t = 0; t < TAU; t += theta) if (b * sin(t) >= 0) north++;

    std::cout << (int)(north * period / (TAU / theta));

}

Output:

42

Indeed:

Summer on northern hemisphere of Uranus lasts 42 years per period.

Explanation:

Only using perihelion and aphelion [closest and farthest distance to the sun] and orbit eccentricity [data from NASA], my program simulates, at the highest level of abstraction and in an extremely simplified way, the rotation of Uranus around the sun. enter image description here


Version 2

#include <iostream>
#include <cmath>

#define TAU 6.283
#define D double

int north;

bool incidence(D t, D tilt) {
    int i = (int)(t * 57.295 + tilt) % 360;
    return i >= 90 && i <= 270;
}

int main(){

    D theta = 0.00001;

    const D orbit_size = 19.189165; // AU
    const D axial_tilt = 97.77; // degrees

    D period = sqrt(pow(orbit_size, 3));

    for (D t = 0; t < TAU; t += theta) if (incidence(t, axial_tilt)) north++;

    std::cout << (int)((north * period) / (TAU / theta));

}

In this version, only the size of the orbit (= semi major axis, in AU) and the axial tilt of Uranus are used. The program computes the orbit period with the third Kepler's law. The way sunlight reaches the planet is computed thanks to the t angle (radians) converted to degrees (* 57.295) plus the axial tilt. North is lighted up when this angle is between 90° and 90+180°. enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Just adding to the amounting proof that it is actually embedded in our universe. \$\endgroup\$ Commented Apr 14, 2015 at 1:56
3
votes
\$\begingroup\$

C

I guess you should know what the output is:

#include<stdio.h>
int main()
{
    printf("       :::::::::  ::::::::::::::::\n");
    printf("      ::::::::::  ::::::::::::::::::\n");
    printf("     :::::::::::  :::::::::::::::::::\n");
    printf("    ::::::::::::  :::::::     ::::::: \n");
    printf("   :::::: ::::::              :::::::\n");
    printf("  ::::::  ::::::              :::::::\n");
    printf(" ::::::   ::::::           ::::::::: \n");
    printf("::::::::::::::::::    :::::::::::::  \n");
    printf("::::::::::::::::::  :::::::::::::    \n");
    printf(":::::::::::::::::: :::::::::::       \n");
    printf("          ::::::   :::::::          \n");
    printf("          ::::::   :::::::          \n");
    printf("          ::::::   :::::::       ::::::\n");
    printf("        :::::::::: ::::::::::::::::::::\n");
    printf("        :::::::::: ::::::::::::::::::::\n");
    printf("        :::::::::: ::::::::::::::::::::\n");

    return 0;
}
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.