91
votes
\$\begingroup\$

4, 8, 15, 16, 23, 42

Write a program that outputs this sequence of numbers infinitely. However, The Numbers must not appear in your source code anywhere.

The following is not a valid Java program to output The Numbers because The Numbers appear in its source code:

class TheNumbers {
    public static void main(String[] args) {
        for(int n = 0;;) System.out.println(
            n == 4 ? n = 8 :
            n == 8 ? n = 15 :
            n == 15 ? n = 16 :
            n == 16 ? n = 23 :
            n == 23 ? n = 42 : (n = 4)
        );
    }
}

The definition of "The Numbers must not appear in your source code" is as follows:

  • You must not use the numeral 4.
  • You must not use the numeral 8.
  • You must not use the numeral 1 followed by the numeral 5.
  • You must not use the numeral 1 followed by the numeral 6.
  • You must not use the numeral 2 followed by the numeral 3.

If your language ignores certain characters that can be placed between the numerals, it's not a valid substitution. So for example if your language interprets the literal 1_5 as 15, this would count as the numeral 1 followed by the numeral 5.

Alternative bases are included in the restriction, so for example:

  • Binary 100 can't be used as a substitute for 4.
  • Octal 10 can't be used as a substitute for 8.
  • Hexadecimal F can't be used as a substitute for 15.

Therefore, the following is a valid (but not very inspired) Java program to output The Numbers because The Numbers do not appear in its source code:

class TheNumbers {
    public static void main(String[] args) {
        for(int n = '*';;) {
            System.out.println(n -= '&');
            System.out.println(n *= 2);
            System.out.println(n += 7);
            System.out.println(++n);
            System.out.println(n += 7);
            System.out.println(n += 19);
        }
    }
}

Note that in that program, '*' and '&' are substituted for the integers 42 and 38, because otherwise the numerals 4 and 8 would appear in its source code.

The definition of "outputs the sequence infinitely" is open to interpretation. So, for example, a program that outputs glyphs getting smaller until they are "infinitely" small would be valid.

Kudos if you are able to generate the sequence in some way that's not basically hard-coding each number.

This is a popularity contest, so be creative. The answer with the most up votes on March 26th is the winner.

\$\endgroup\$
25
  • 8
    \$\begingroup\$ I can count 6 downvotes but no comments :/ \$\endgroup\$
    – Vereos
    Mar 12, 2014 at 13:52
  • 11
    \$\begingroup\$ @Vereos, "This is a stupid question" isn't very constructive, which might be why no-one posted it as a comment. \$\endgroup\$ Mar 12, 2014 at 15:26
  • 18
    \$\begingroup\$ There are 11 types of people in this world: those that watched Lost, those that didn't, and those that don't understand binary. \$\endgroup\$
    – r3mainer
    Mar 12, 2014 at 16:26
  • 7
    \$\begingroup\$ @PeterTaylor For sure, but newcomers mostly will not get that and leave the site instead of trying to improve their future questions. I guess that This isn't an interesting question, IMHO, since the solution is pretty trivial. Please post in the sandbox next time. would be way better than This is a stupid question., but that's just my personal opinion. \$\endgroup\$
    – Vereos
    Mar 12, 2014 at 16:57
  • 3
    \$\begingroup\$ I notice the question does not prohibit outputting other numbers. So at least according to infinite-monkey-theory an unadulterated pseudo-random number generator should do the trick. \$\endgroup\$
    – kojiro
    Mar 13, 2014 at 13:21

109 Answers 109

1 2 3
4
1
vote
\$\begingroup\$

Haskell

{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit (simpleHttp)
import Data.ByteString.Lazy.Char8 (ByteString, unpack)

import Data.List
import Data.Maybe

url="http://bit.ly/Oijgr0"

parseSequence::ByteString->[Int]
parseSequence i = parser $ text i
    where
        text = (drop 9) . head . catMaybes . (map $ stripPrefix "%S") . lines . unpack
        parser = (map read) . (split ',')
        split _ []=[[]]
        split n (x:xs) | n==x = []:(split n xs)
                       | otherwise = let (l:ls)=split n xs in (x:l):ls

main=print =<< (fmap (cycle . parseSequence) $ simpleHttp url)

Apparently it is oeis.org/A104101 (I have to use the shortened link because the sequence name has a 4 in it.)

\$\endgroup\$
1
vote
\$\begingroup\$

Forth (gforth)

So here's my solution. It pushes a 2 (on the stack) and then modifies the stack.

Short version:

: x
  begin
    2 2 * dup .
    2 * dup .
    dup 2 * 1 - .
    dup 2 * dup .
    + 1 - dup .
    2 * 2 2 * - .
    cr
  0 until
;

x

Minified short version (100 Chars):

: x begin 2 2 * dup . 2 * dup . dup 2 * 1 - . dup 2 * dup . + 1 - dup . 2 * 2 2 * - . cr 0 until ; x

Readable long version with comments:

: one 1 ;
: two 2 ;
: add + ;
: sub - ;
: mul * ;
: inc one add ;
: dec one sub ;
: dbl two mul ;

: out
    begin
        two dbl dup     . ( output:  4, stack:  4 )
        dbl dup         . ( output:  8, stack:  8 )
        dup dbl dec     . ( output: 15, stack:  8 )
        dup dbl dup     . ( output: 16, stack:  8 16 )
        add dec dup     . ( output: 23, stack: 23 )
        dbl two dbl sub . ( output: 42, stack: <empty> )
        cr
    0 until
;

out
\$\endgroup\$
1
vote
\$\begingroup\$

JAVASCRIPT

function printInt(){
var someJavaCode = "roll {Drums;} while(rollDrum) {Drums.plays();} if(Drums.playingNow()){ displayThisToDoc(aGuyPlayingDrumPicture);}"
var brokenPiece = someJavaCode.split(' ');
var returnVal = [];
for(var i=0;i< brokenPiece.length;++i){
returnVal.push(brokenPiece[i].length);
}
return returnVal;
}
printInt();
\$\endgroup\$
1
vote
\$\begingroup\$

Python 3

x=list(str(int(33706136394/7)))
while 1:print(x[0],x[1],x[2]+x[3],x[3+1]+x[5],x[6]+x[7],x[7+1]+x[9])
\$\endgroup\$
1
vote
\$\begingroup\$

Haskell, phoning it in.

main = putStrLn $ show $ cycle $ map (+3) [1, 5, 12, 13, 20, 39]
\$\endgroup\$
2
  • \$\begingroup\$ And the number 15. Both issues easily fixed if you used +3 instead of +1. \$\endgroup\$ Mar 18, 2014 at 15:12
  • \$\begingroup\$ Hehe, clearly not paying attention. \$\endgroup\$
    – mmachenry
    Mar 18, 2014 at 15:17
1
vote
\$\begingroup\$

C

NOTE: Not a single digit actually used in the code.

#include <stdio.h>

#define s (':')
#define m (s - ';')
#define l ('@' - s)
#define c (">BIJQd")

main()
{
    char a[l] = c;
    char i = m;
    while(l) printf("%d, ", a[i = (++ i) % l] - s);
}
\$\endgroup\$
1
vote
\$\begingroup\$

C#

void Main()
{
    while (true) 
        foreach (var c in "EIPQXk")
            Console.Write(c - 'A');
}

Edit: figured.. why not use linq too. Here you can optionally also have a newline at the end of every sequence without adding more than the work Line.

while (true)
    Console.Write(String.Concat("EIPQXk".Select(c => c - 'A')));
\$\endgroup\$
1
vote
\$\begingroup\$

Python

a = 1

while (a > 0):
    b = a + 3
    c = b * 2
    d = c + 7
    e = c * 2
    f = e + 7
    g = f + c + 11
    print b, c, d, e, f, g

It's not very "pythonic" but it has room for improvement

\$\endgroup\$
1
vote
\$\begingroup\$

COBOL

   ID DIVISION.
   PROGRAM-ID. LOST.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  LOST PIC XXXX.
   LINKAGE SECTION.
   01  TOTALLY-LOST PIC 9,9,99,99,99,99.
   PROCEDURE DIVISION USING TOTALLY-LOST.

       COMPUTE TOTALLY-LOST =  
                            ( 
                             ( 
                              FUNCTION LENGTH ( LOST )
                             )
                            *
                             1000000000
                            )
               +
                            ( 
                             ( 
                              FUNCTION LENGTH ( LOST )
                              + 
                              FUNCTION LENGTH ( LOST )
                             )
                            *
                             100000000
                            )
               +
                            ( 
                             ( 
                              (
                               FUNCTION LENGTH ( LOST )
                               *
                               FUNCTION LENGTH ( LOST )
                              )
                              -
                              (
                               FUNCTION LENGTH ( LOST )
                               /
                               FUNCTION LENGTH ( LOST )
                              )
                             )
                            *
                             1000000
                            )
               +
                            ( 
                             ( 
                              FUNCTION LENGTH ( LOST )
                              *
                              FUNCTION LENGTH ( LOST )
                             )
                            *
                             10000
                            )
               +
                            ( 
                             (
                              ( 
                               FUNCTION LENGTH ( LOST )
                               + 
                               FUNCTION LENGTH ( LOST )
                              )
                             +
                              ( 
                               (
                                FUNCTION LENGTH ( LOST )
                                *
                                FUNCTION LENGTH ( LOST )
                               )
                               -
                               (
                                FUNCTION LENGTH ( LOST )
                                /
                                FUNCTION LENGTH ( LOST )
                               )
                              )
                             )
                            *
                             100
                            )
               +
                            ( 
                             ( 
                              ( 
                               (
                                FUNCTION LENGTH ( LOST )
                                *
                                FUNCTION LENGTH ( LOST )
                               )
                               -
                               (
                                FUNCTION LENGTH ( LOST )
                                /
                                FUNCTION LENGTH ( LOST )
                               )
                              )
                             +
                              (
                               ( 
                                FUNCTION LENGTH ( LOST )
                                + 
                                FUNCTION LENGTH ( LOST )
                               )
                              +
                               ( 
                                (
                                 FUNCTION LENGTH ( LOST )
                                 *
                                 FUNCTION LENGTH ( LOST )
                                )
                                -
                                (
                                 FUNCTION LENGTH ( LOST )
                                 /
                                 FUNCTION LENGTH ( LOST )
                                )
                               )
                              )
                             +
                              ( 
                               FUNCTION LENGTH ( LOST )
                              )
                             )
                            *
                             1
                            )

       GOBACK
       .

This is written as a sub-program to emphasise that the COMPUTE is both calculating and formatting the output. One Verb for that, one Verb to return from whence it came.

Which is here:

   ID DIVISION.
   PROGRAM-ID. CALLLOST.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  15-BYTE-LUMP                        PIC X(15).
   PROCEDURE DIVISION.
       CALL "LOST"                  USING 15-BYTE-LUMP
       DISPLAY 
               15-BYTE-LUMP
       GOBACK
       .

Output, from the DISPLAY in the CAlling program, is:

4,8,15,16,23,42

In COBOL, there are no strings, just fixed-length fields. FUNCTION LENGTH or special register LENGTH OF give access to the length of the field (not the length of the content).

So, by calculating each of the elements using manipulations of the length of a four-byte field (content irrelevant), scaling each element (the last scaling is not required, but it seemed fun to leave it there) and using a numeric-edited PICture to format the total thus calculated, gives the required output.

The numeric-edited field just happens to be a re-mapping of storage area allocated in the CALLing program.

Note: The scaling could be done differently (no need ever to multiply/divide by a power of 10 unless for floating-point numbers, which already process slowly enough anyway) but then it could not be done in one instruction.

\$\endgroup\$
1
vote
\$\begingroup\$

C

My first answer on the site..

main(){for(1;;){printf("%d%d%d%d%d%d",2*2,5+3,3*5,9+7,18+5,21*2);}}
\$\endgroup\$
1
vote
\$\begingroup\$

F#

This solution references HtmlAgilityPack, a free and rather common library for parsing HTML.

[<EntryPoint>]
let main argv = 
let web = HtmlAgilityPack.HtmlWeb()
let doc = web.Load("http://codegolf.stackexchange.com/search?q=The+definition+of+%22The+Numbers+may+not+appear+in+your+source+code%22+is+as+follows%3A")
let root = doc.DocumentNode
let node = root.SelectSingleNode("//div[@class='summary']/div[@class='result-link']/span/a")
let content = node.InnerText.Trim().Substring(3)
while true do
    printfn "%s" content
0

At first, I thought of just browsing to http: //codegolf.stackexchange.com/questions/23808, but that would involve having to type "23808", which contains the dreaded character '8'. This is what I did:

use client = new System.Net.WebClient()
let illegal_number = 30000 - 6192
let str = sprintf "http://codegolf.stackexchange.com/questions/%d/" illegal_number |> client.DownloadString
let regex = Regex.Match(str,"\<meta name=\"og:title\" content=\"([\d, ]*)\"")
let txt = regex.Groups.[1].Value
for i = 0 to 100 do
    printfn "%s" txt

Although this is a better in a way, since it doesn't require third party libraries, I felt the '3000-6192' deal was a bit cheap, so I came up with the above. Also, the other solution doesn't involve the evil of parsing HTML with regex.

\$\endgroup\$
1
vote
\$\begingroup\$

C

Can you figure out what is going on?

#include <inttypes.h>

main() {
    uint32_t*E=">=~",*D="0sek\r\360ww?";

    uint16_t i=atoi(D);
    double d=D[i]^D[!i];
    uint32_t*o=&d;
    uint8_t s=D[D&&D],m=D[E[!E&&o]&-E[!o&&E]],w=D[~i]&-D[~i];

    while(o)d=sin(d+i++),printf("%d\n",(*o>>s&m)-w);

    return 0;
}

The code has undefined behavior due to pointer-punning and accessing an array out of its bounds.

The code compiles (with some warnings) with gcc (no optimization), and produces the expected sequence on my computer (Windows 7).

Spoilers

This is the original version of the code. The sequence is generated by taking 6 bits of the double numbers in the sequence generated by d = sin(d + i) where i increments from 0. The initial value is found by brute force.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <inttypes.h>

int main(void) {
    double d = 470975293;
    uint32_t *o = (uint32_t*) &d;

    for (uint16_t i = 0; ; i++) {
        d = sin(d + i);
        printf("%d\n", (*o >> 13 & 0x3F) - 2);
    }

    return 0;
}

This version still has undefined behavior due to pointer-punning.

\$\endgroup\$
1
vote
\$\begingroup\$

Python3

Adding a somewhat boring no-digit answer to the mix.

while id:c,*s=b'JNRYZat';print(*[i-c for i in s])
\$\endgroup\$
1
vote
\$\begingroup\$

Javascript Console

I ran across this question and I was like, "hey, I wrote a program that outputs that sequence of numbers without The Numbers appearing in the source code anywhere that one time" And now, months later, I found the file I saved it in... The file was named ._. .js because I'm so good at organization. I wrapped it in an interval.

setInterval(function(){var S=String, N=Number, s=Math.sqrt, n=function(a){console.log(a);return N(a)},
_={_:{_:document.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC/2}},twenty=N((_          
/* THIS IS IMPORTANT: */ ._. /* DO NOT REMOVE.*/ _).toString(s(_            
/* THIS IS IMPORTANT: */ ._. /* DO NOT REMOVE.*/ _))),_=_           
/* THIS IS IMPORTANT: */ ._. /* DO NOT REMOVE.*/ _[S.fromCharCode(twenty+_          
/* THIS IS IMPORTANT: */ ._. /* DO NOT REMOVE.*/ _)+S.fromCharCode(twenty+document.DOCUMENT_FRAGMENT_NODE)+S.name](),_=N(
/* THIS IS IMPORTANT: ⁎/ ._. /* DO NOT REMOVE.*/ _),$=n(2*n(s(_))),$=n(_-_/_),$=n(_+_+_
/* THIS IS IMPORTANT: */ -_- /* DO NOT REMOVE.*/ _),$=n(Array.prototype.slice.call(_+_+"").reverse().join("")),_=s(_+_+_
/* THIS IS IMPORTANT: */ -_- /* DO NOT REMOVE.*/ _)+_+_+_-(_.toString(_)),$=n(_+_+_
/* THIS IS IMPORTANT: */ -_- /* DO NOT REMOVE.*/ _);                                                                                n("The meaning of "+["life","the universe","and everything"].join(", ")+" is...    "
/* THIS IS IMPORTANT: */ +_+ /* DO NOT REMOVE.*/                                                                                                                                                                            ".")});;;
"kthxbai"

You can remove ⁎one⁎ of the faces that it iS IMPORTANT tHat you dON'T REMOVe.

\$\endgroup\$
1
vote
\$\begingroup\$

Marbelous

RR
:R
33
31
3035
3036
3735
33
QQ
:Q
}0
++20

RR references the board R, which doesn't have any input values and thus fires every tick. R has a bunch of ascii literals which it either throws onto the Q board or lets drop off the board. The Q board first prints a space and then the character the input value + 1 corresponds to. Throwing a value off the bottom of the board prints the corresponding ascii character.

\$\endgroup\$
1
vote
\$\begingroup\$

JavaScript

var numbers = (Math.pow(0.07697703609326959*99200,2)*6997299).toString().split('0')
var i = 0
setInterval(function(){
  document.getElementsByTagName('html')[0].innerHTML += numbers[i++%6]+' '
},50)

What I've done, is write a script that takes a number 408015016023042. Since there are no 0's in the sequence of numbers, I could put one in between every digit as splitting point.

The script then loops through some processes to find numbers by which the number can be:

  1. Divided
  2. Square-rooted
  3. Divided again

Without:

  1. Generating any of the forbidden numbers
  2. Creating a floating point issue

I simply took a random match from a whole list of matches, and there is my answer, simply put into a setInterval.

It splits the number at the 0's, and loops through them, pushing them into the DOM.

You can try it in this Fiddle.

I've also put my script in this Fiddle with which I've looked up my answer. It's also compatible with sequences that contain all of the 0 - 9 digits.

\$\endgroup\$
0
votes
\$\begingroup\$

VBA

Sub chr_la_head_chr_la()
n = 50
Do While (True)
MsgBox Chr(n + 2) & " " & Chr(n + 6) & " " & Chr(n - 1) & Chr(n + 3) & " " & Chr(n - 1) & Chr(n + 3 + 1) & " " & Chr(n) & Chr(n + 1) & " " & Chr(n + 2) & Chr(n)  
Loop
End Sub
\$\endgroup\$
0
votes
\$\begingroup\$

Objective-C

This is my first post on this forum, hopefully this code follows the rules:

int main(int argc, const char * argv[])
{
    @autoreleasepool {

        for (int i = 1; i < INFINITY; i++)   {
            int x = 2;

            int first = x + 2;
            int second = x + 6;
            int third = x + 13;
            int fourth = x + 7 + 7;
            int fifth = x + 21;
            int sixth = x + 10 + 30;

            NSLog(@"%i %i %i %i %i %i", first, second, third, fourth, fifth, sixth);      
        } 
    }
    return 0;
}
\$\endgroup\$
0
votes
\$\begingroup\$

C

How's this, haven't used any number.

int main() {

    int Four=2*2;
    int Eight=Four*2;
    int Fifteen=5*3;
    int Sixteen=Four*Four;
    int twenty3=fifteen+Eight;
    int fortytwo=21*2;
    printf("%d %d %d %d %d %d\n",Four,Eight,Fifteen,Sixteen,twenty3,fortytwo);

    main();
}
\$\endgroup\$
1 2 3
4

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