382
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\$ 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
    Feb 24, 2014 at 0:45
  • 9
    \$\begingroup\$ The question should remain at 42 votes. \$\endgroup\$
    – Zero Fiber
    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
    Feb 24, 2014 at 16:43
  • 3
    \$\begingroup\$ Can we get 42 favorites? \$\endgroup\$
    – Milo
    Feb 24, 2014 at 22:48

110 Answers 110

3
votes
\$\begingroup\$

C

#include<stdio.h>
int main()
{
   printf("101010\n");
   return 0
}
\$\endgroup\$
2
  • 3
    \$\begingroup\$ I don't get the trick is it about the missing semicolon at the end? \$\endgroup\$
    – Mohammad
    Feb 25, 2014 at 15:37
  • \$\begingroup\$ It outputs 42 in binary which is 101010 (32+8+2)... \$\endgroup\$
    – Axel
    Feb 25, 2014 at 16:33
3
votes
\$\begingroup\$

Ruby

six = '1 + 5'
times = 42.chr
nine = '8 + 1'

p eval [six,times,nine].join
\$\endgroup\$
2
3
votes
\$\begingroup\$

Befunge-93

I guess this is not very creative but since there are several brainf*ck answers, I feel like good old befunge-93 should get his moment too. I did try to use some of the cool features of the language such as self-modification and a trampoline.

                                                                               v
           What is the answer to life, the universe, and everything?           
                                   >   v
                 DON'T                             PANIC
v:                                "6 * 9"                                      <
_v#                                                                           :,
 >       1v        <     >         ^   >            *.@
v****22222< >79*2-,^
>,          |         
            >56+5*58*1-4p^

And the output is of course:

 6 * 9 = 42
\$\endgroup\$
3
votes
\$\begingroup\$

Haskell

h2g2          = fromIntegral
douglasAdams  = length
l x           = 1 / h2g2 (douglasAdams x)
the x         = h2g2 $ sum $ zipWith (*) (map douglasAdams x) [0,1,-1]
theanswerisfoundin theRestaurantAtTheEnd= print $ round theRestaurantAtTheEnd

main=theanswerisfoundin 
     (the ["Hitch" ,"Hikers" ,"Guide"] / (l "TO" - l "THE" - l "GALAXY!")) 

How it works

It outputs 1/ (1/2 - 1/3 - 1/7) :)

\$\endgroup\$
3
votes
\$\begingroup\$

C#

There's a clear dependency between the phrase and the hashes:

using System;
using System.Security.Cryptography;
using System.Text;

class C
{
    static void Main ()
    {
        byte[]b=Encoding.ASCII.GetBytes("Answer to the Ultimate Question of Life, the Universe, and Everything");
        Func<HashAlgorithm,int>q=a=>a.ComputeHash(b)[0];
        int[]i={ q(MD5.Create()), q(SHA1.Create()), q(SHA256.Create()), q(SHA384.Create()), q(SHA512.Create()) };
        Console.WriteLine((i[0]+i[1]+i[2]+i[3]+i[4])/(i[2]-i[1])+1);
    }
}

Is it a coincidence or a sign?

\$\endgroup\$
3
votes
\$\begingroup\$

Python

print reduce(lambda x, y: x ^ ord(y), 'Life, the universe and everything', 6 * 9)
\$\endgroup\$
3
votes
\$\begingroup\$

Python

import math
print ((math.floor(e)*math.floor(e))*(math.ceil(pi*pi)))+math.floor(e)

Actually, you can print every integer using this method. It's your job to find it . . . .

\$\endgroup\$
3
votes
\$\begingroup\$

In the language whose name is the first three letters of Douglas Adams' last name:

Ada

with Ada.Text_IO;
with Ada.Integer_Text_IO;
procedure Print_42 is
    S: String(1..6);
begin
    Ada.Integer_Text_IO.Put(To => S, Item => 6 * 9, Base => 13);
    Ada.Text_IO.Put_Line(S(4..5));
end Print_42;
\$\endgroup\$
3
votes
\$\begingroup\$

Javascript

var s = this.toString().split(" ")[1].replace("]","").toLowerCase() + Math.sqrt(123 ^ 0.5).toString().charAt(2) + atob("bG9jYXRpb24=") + String.fromCharCode((4 * 4 * 4).toString().charAt(1) + (Math.log(4 * 4 * 4) / Math.log(2)));
for (var i = 0; i < "roy eats pea lasagne and crunchy eggs!".split(" ").length; i++) {
    s += "roy eats pea lasagne and crunchy eggs".split(" ")[i].charAt();
}
s += String.fromCharCode(5 * Math.pow(2, 3)) + "\"data:text/text,";
var i = 21,
    o = 21;
while (i != Math.floor(i) || i == 21) {
    i += o;
    o /= 2;
}
s += i + s.charAt(24) + String.fromCharCode(s.charCodeAt(23) + 1);
window.location.replace("javascript:" + s);

Output:

window.location.replace("data:text/text",42);

Output's output:

42
\$\endgroup\$
3
votes
\$\begingroup\$

Perl

another try - reads as assembly, parses as perl, includes "DON'T PANIC" and displays 42 :)

use v5.10;

* DON::T = sub {
    s   mm
    pop me, y

    - Douglas N. Adams 
    - a short fanfare

    (-;

    s   0.0
    g   x 
    hex $&, 0eg
    and do
    say tr

    - Ford Prefect
    - Arthur Dent

    c-c
};

DON'T PANIC
\$\endgroup\$
3
votes
\$\begingroup\$

Simple but efficient python one-liner.

>>> sum([ord(x) for x in 'THE UNIVERSE FINAL ANSWER']) // 42
42
\$\endgroup\$
1
  • \$\begingroup\$ Nice. But better use // (integer division) to make it work in Python 3 too. (Otherwise the result would be 42.19047619047619.) \$\endgroup\$
    – manatwork
    Feb 28, 2014 at 12:56
3
votes
\$\begingroup\$

Python (But not specific to Python...)

print(((True<<((True<<((True<<True)+True))+True))/(True<<((True<<(True<<True))+(True<<True)))-True)*((True<<(True<<True))+(True<<True)))

EDIT:

Slightly nicer (and 42 non-whitespace characters...)
Only works in Python 2.x though.

print (1<<1<<(1<<1<<1))+(1<<1<<1<<1)+(1<<1)
\$\endgroup\$
3
votes
\$\begingroup\$

Wang B-machine

Of course the B-machine doesn't have a graphical output, but if you interpret the final tape as a 9x6 font...

{ (1, →), (2, →), (3, →), (4, *), (5, →), (6, →), (7, →), (8, *), (9, →), (10, *), (11, →),
(12, →), (13, →), (14, →), (15, *), (16, →), (17, *), (18, →), (19, →), (20, *), (21, →),
(22, →), (23, →), (24, *), (25, →), (26, →), (27, *), (28, →), (29, →), (30, *), (31, →),
(32, →), (33, →), (34, →), (35, →), (36, *), (37, →), (38, *), (39, →), (40, *), (41, →),
(42, *), (43, →), (44, *), (45, →), (46, *), (47, →), (48, →), (49, →), (50, *), (51, →),
(52, →), (53, →), (54, →), (55, →), (56, *), (57, →), (58, →), (59, →), (60, *), (61, →),
(62, →), (63, →), (64, →), (65, →), (66, →), (67, *), (68, →), (69, →), (70, *), (71, →),
(72, *), (73, →), (74, *), (75, →), (76, *) }
\$\endgroup\$
3
votes
\$\begingroup\$

Bash:

expr "`echo "The answer to Ultimate Question of Life, the Universe, and Everything" | wc -l`" \* "`echo "Here it goes" | wc -l`" \* "`echo "Life," | wc -c`" + "`echo "The Unviverse," | wc -c`" + "`echo "And Everything..." | wc -c`" + "`echo "The Answer is" | wc -w`"

Output:

42

\$\endgroup\$
1
  • \$\begingroup\$ Could you format this in a way that is readable on Stack Exchange? E.g. using four leading spaces (code formatting) and some line breaks? Maybe also use $(...) instead of the backticks ``? \$\endgroup\$ Mar 4, 2014 at 23:02
3
votes
\$\begingroup\$

Piet

This is my first attempt at a program in Piet.
It prints 42 indefinitely:

enter image description here

It simply multiplies 6 by 7 and outputs, so nothing really fancy, I just wanted to give Piet a try.
It is somewhat golfed though as it consists only of 18 codels.

\$\endgroup\$
3
votes
\$\begingroup\$

JavaScript

I probably could have done something more creative than this, but:

var ArrayToLifeTheUniverseAndEverything=[
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,0,0,1,0,0,1,1,1,1,1,0,0,0,1,0],
[0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0],
[0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0],
[0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0],
[0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0],
[0,0,0,0,1,0,0,0,1,1,1,1,0,0,0,1,0],
[0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0],
[0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0],
[0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0],
[0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];

var DouglasAdams =""

for(var DontPanic = 0; DontPanic<ArrayToLifeTheUniverseAndEverything.length; DontPanic++){
    for(var FriendlyLetters = 0; FriendlyLetters<ArrayToLifeTheUniverseAndEverything[DontPanic].length; FriendlyLetters++){
        if(ArrayToLifeTheUniverseAndEverything[DontPanic][FriendlyLetters]){
            DouglasAdams+="*";
        }else{
            DouglasAdams+=" ";
        }
    }
    DouglasAdams+="\n"
}
console.log(DouglasAdams);

But as a bonus, as I saw someone else say earlier, the ASCII code for * is 42.

\$\endgroup\$
3
votes
\$\begingroup\$

C

main(){printf((char[]){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>>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,(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+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/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)/(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/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/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>>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});return 42;}

This outputs "The answer to life, the universe and everything." using (almost) only the number 42. Additionally, it returns 42.

\$\endgroup\$
3
votes
\$\begingroup\$

Mathematica

Ceiling[E^(E + E^(E - E))]
\$\endgroup\$
3
  • \$\begingroup\$ Which language is this? \$\endgroup\$ Feb 24, 2014 at 19:20
  • \$\begingroup\$ @ Victor, Mathematica \$\endgroup\$
    – martin
    Feb 24, 2014 at 19:22
  • 1
    \$\begingroup\$ Ok, I recommend that you always put the used language in the title and ident source-code with four spaces (so the site identifies it as source-code). I did this for you here. \$\endgroup\$ Feb 24, 2014 at 19:24
2
votes
\$\begingroup\$

F#

let answer = 42
[|62; 74; 74; 70; 73; 16; 5; 5; 77; 77; 77; 4; 61; 69; 69; 61; 66; 59; 4; 57;
  69; 67; 5; -7; 71; 19; 74; 62; 59; 1; 55; 68; 73; 77; 59; 72; 1; 74; 69; 1;
  66; 63; 60; 59; 1; 74; 62; 59; 1; 75; 68; 63; 76; 59; 72; 73; 59; 1; 55;
  68; 58; 1; 59; 76; 59; 72; 79; 74; 62; 63; 68; 61|]
|> Array.map (((+) answer) >> char)
|> (fun c -> new string(c))
|> System.Diagnostics.Process.Start

It navigates to https://www.google.com/#q=the+answer+to+life+the+universe+and+everything

\$\endgroup\$
2
votes
\$\begingroup\$

Google

Enter "the answer to life the universe and everything" into the search bar of google:
https://www.google.ch/search?q=the+answer+to+life+the+universe+and+everything

I am aware that this is not actually source code that executes. However the OP did not state that is has to be written in a programming language or that it should result in a executable file.

\$\endgroup\$
2
votes
\$\begingroup\$

PHP + Google

header("Location: http://www.google.com/#q=the+answer+to+life+the+universe+and+everything");

If you really type The answer to life the universe and everything in Google, it will output 42.

\$\endgroup\$
1
  • \$\begingroup\$ Oh, did not see that someone else had the same idea, just a few minutes before I posted my version of this answer \$\endgroup\$
    – RononDex
    Feb 24, 2014 at 8:06
2
votes
\$\begingroup\$

Perl

#!/usr/bin/perl
package Six;
use overload '*' => sub { return "42\n" };
sub multiplied { return bless {}, shift };
sub by { shift };
sub nine { shift };
sub equals { $six=shift;  return $six*$nine };

package main;

print Six->multiplied->by->nine->equals
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Welcome to Code-Golf! Don't forget to add an explanation on why this answer is creative! \$\endgroup\$
    – Justin
    Feb 24, 2014 at 5:47
2
votes
\$\begingroup\$

Python 3

Example from real-life (translated to english). One of the python3 student tasks was writing a program that outputs string with user name to both screen and file. The student program was:

protocol_file = open("protocol.txt", "wt")
name = input("Enter your name: ")
print(protocol_file.write("Judge says:  Do you admit your guilt, " + name + "?\n"))
protocol_file.close()

For testing purposes student inputs some two-letter garbage as name - "mg". ... and, got 42 printed in console.

\$\endgroup\$
2
votes
\$\begingroup\$

bash 732

Where 7, 3 and 2 are the primes that compose 42!!

#!/bin/bash

export ResultString

export MaxToReach=${RANDOM}{0,}

for ((CurrentVal = MaxToReach ; CurrentVal-- ;-p))
do
   ((
     ( CurrentVal + CurrentVal ) == ( CurrentVal * CurrentVal ) &
     ( CurrentVal * CurrentVal ) == ( CurrentVal ** CurrentVal )
   )) &&
     printf -v ResultString "%01d%01d" $((
          CurrentVal ** CurrentVal
          )) $CurrentVal
done

AltCheck=$(stat -c %s $0)
for (( I = ${#AltCheck} ; I-- ;-p))
do
     AltResult=${AltCheck:I:1}*$AltResult
   done

cat <<EndOfFinalAnswer
DISCLAIMER: This tool would help you to compute the answer!
Unfortunely, this tool is unable to retrieve THE question.

The answer to the ultimate question is: '$ResultString' or '$((${AltResult}1))'!
EndOfFinalAnswer

Running this very usefull tool will print:

DISCLAIMER: This tool would help you to compute the answer!
Unfortunely, this tool is unable to retrieve THE question.

The answer to the ultimate question is: '42' or '42'!
\$\endgroup\$
2
votes
\$\begingroup\$

Binary

101010

is 42 in binary and the meaning of life...;-)

I owe, I owe, I owe. (it's off to work I go.)

\$\endgroup\$
4
  • 2
    \$\begingroup\$ This is a programming contest, not a poetry contest. \$\endgroup\$
    – user12205
    Feb 24, 2014 at 21:38
  • \$\begingroup\$ I edited your answer to change it to a more acceptable format. Next time, write your answers more like this. \$\endgroup\$
    – Justin
    Feb 24, 2014 at 23:17
  • \$\begingroup\$ Who you owe? What do you owe them? Maybe you should pay them back... \$\endgroup\$
    – DaveRandom
    Jun 21, 2014 at 10:24
  • \$\begingroup\$ @Kevin if you're trying to quote that song from Snow White, you should only say "I owe" twice. \$\endgroup\$
    – mbomb007
    Jan 14, 2015 at 15:15
2
votes
\$\begingroup\$

Perl evil answer (42)

( $E666 = 666 )=~s/.//;printf "%x\n",$E666

Running demo:

perl -e '( $E666 = 666 )=~s/.//;printf "%x\n",$E666'
42
\$\endgroup\$
2
votes
\$\begingroup\$

HTML & CSS

It's ugly and probably not compatible with all browsers, but here we go:

    <span style="display: inline-block; width: 3em; height: 3em">
    <span style="position: relative; display: inline-block; width: 3em; height: 3em">
        <i style="position: absolute;display:inline-block;width:0;height:0;line-height:0;border:1.5em solid #000000;border-bottom:none;border-top-right-radius:1.5em;border-top-left-radius:1.5em;left:4em;top:0em"></i>
        <i style="position: absolute;display:inline-block;width:0;height:0;line-height:0;border:1.3333333333333333em solid #ffffff;border-radius:1.3333333333333333em;left:4.166666666666666em;top:0.16666666666666666em"></i>
        <i style="position: absolute;display:inline-block;width:0;height:0;line-height:0;border:1.5em solid transparent;border-right:1.5em solid #000000;border-bottom:1.5em solid #000000;left:4em;top:1.3333333333333333em"></i>
        <i style="position: absolute;display:inline-block;width:0;height:0;line-height:0;border:1.3333333333333333em solid transparent;border-right:1.3333333333333333em solid #ffffff;border-bottom:1.3333333333333333em solid #ffffff;left:4.333333333333333em;top:1.6666666666666665em"></i>
        <i style="position: absolute;display:inline-block;width:3em;height:0.16666666666666666em;background-color:#000000;left:4em;top:4.333333333333333em"></i>
        <i style="position: absolute;display:inline-block;width:0.16666666666666666em;height:4.5em;background-color:#000000;left:1.8333333333333333em;top:0em"></i>
        <i style="position: absolute;display:inline-block;width:3em;height:0.16666666666666666em;background-color:#000000;left:0em;top:1.5em"></i>
        <i style="position: absolute;display:inline-block;width:0.16666666666666666em;height:1.6666666666666665em;background-color:#000000;left:0em;top:0em"></i>
    </span>
</span>

Which outputs

enter image description here

In Chrome at least... Here's the fiddle: http://jsfiddle.net/myJC4/

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Works fine in Opera ;3 \$\endgroup\$
    – cjfaure
    Feb 28, 2014 at 12:27
2
votes
\$\begingroup\$

Bash:

$ expr "`whatis "the answer to Ultimate Question of Life, the Universe, and Everything" 2>&1 | wc -c`" - "`echo "Really, what it is?" | wc -c`" - "`echo "For god sake, please tell me." | wc -c`"

Output is: 42

\$\endgroup\$
2
votes
\$\begingroup\$

JavaScript

String.prototype.repeat = function( num )
{
    return new Array( num + 1 ).join( this );
};
var four='4';
var two='2';

var firstLineFour=four+' '.repeat(5)+four;
var secondLineFour=' '.repeat(6)+four;
console.log(
    (firstLineFour+' '+two.repeat(7)+'\n'+firstLineFour+' '.repeat(7)+two+'\n'+four.repeat(7)+' '+two.repeat(7)+'\n')+((secondLineFour+' '+two)+'\n')+(secondLineFour+' '+two.repeat(7))+'\n'
);

Output:

4     4 2222222
4     4       2
4444444 2222222
      4 2
      4 2222222

The variable four is set to '4' and two set to '2', but you can change them to make it "draw" with different numbers.

\$\endgroup\$
2
votes
\$\begingroup\$

JavaScript (or ActionScript 3)

"What do you get if you multiply 6 times 9?".length

Result:

42
\$\endgroup\$

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