90
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\$

closed as too broad by Alex A. Apr 23 '16 at 0:25

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

locked by Alex A. Apr 23 '16 at 0:25

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

Read more about locked posts here.

  • 8
    \$\begingroup\$ I can count 6 downvotes but no comments :/ \$\endgroup\$ – Vereos Mar 12 '14 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\$ – Peter Taylor Mar 12 '14 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\$ – squeamish ossifrage Mar 12 '14 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 '14 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 '14 at 13:21

109 Answers 109

2
votes
\$\begingroup\$

C#

using System;

class Numbers
{
    const string s = "I have to be honest with you, this question turned "
                   + "out to be harder than I expected. I didn't want to "
                   + "use characters, because I think it is a really     "
                   + "lame way to 'solve' the challenge, but meh.        "
                   + "Guess I'm not as smart as I thought. I tried to    "
                   + "do it with a polynomial, but it's pretty much      "
                   + "impossible to write down the coefficients without  "
                   + "breaking one of the rules. Unless, of course, you  "
                   + "use characters, but that kinda defeats the purpose "
                   + "of the whole polynomial thing. Now, lets insert    "
                   + "some random characters, just for fun!              "
                   + "(I can hear you think 'yeah, right...')            "
                   + "BTW, I have tons of respect for you if you can do  "
                   + "this without the weird stuff at the end!           "
                   + "7`ypg6";

    static void Main(string[] args)
    {
        char b = '\0';
        for (int i = 0; ; i = ++i % 6, b = '\0')
        {
            for (int j = i; j < s.Length; j += 6) b ^= s[j];
            Console.WriteLine((int)b);
        }
    }
}

Not too compact, or hard to figure out, I guess.

The 'random' characters at the end make sure that if you XOR all every nth (n = 1 to 6) character in that long text, you end u with the right number in the sequence

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

Delphi

I chose to use primes to solve this.
First selected all primes < 55 and did some calculations with that.

uses
  System.sysutils,Generics.Collections;

  function ESieve(upperLimit:integer):TList<integer>;
  var
    i,j: integer;
    a:array of boolean;
    upperSqrt,sieveBound:integer;
  begin
    Result:=TList<integer>.Create;
    sieveBound:=Round((upperLimit-1)/2);
    upperSqrt:=Round((Sqrt(upperLimit)-1)/2);
    SetLength(a,sieveBound);
    for I:=0to sieveBound-1 do
      a[I]:=true;
    for I:=1to upperSqrt do
    begin
      if a[I] then
      begin
        J:=i*2*(i+1);
        while J<=sieveBound do
        begin
          a[J]:=false;
          J:=J+2*i+1;
        end
      end
    end;
    Result.Add(2);
    for I:=1to sieveBound-1do
      if a[i]then
        Result.Add(2*i+1);
  end;
var
  a,primes:TList<integer>;
  i:integer;
begin
  i:=1;
  primes:=ESieve(55);
  a:=TList<integer>.create;
  i:=i+3;
  a.Add(primes[i]-primes[i-1]);
  a.Add(primes[2]+primes[1]);
  a.Add(primes[i+1]+primes[0]);
  a.Add(a[a.Count-1]+1);
  a.Add((primes[1]*primes[3])+primes[0]);
  a.Add((a[a.Count-1]*2)-a[0]);

  while 1>0 do
  begin
    for I := 0 to a.Count-1 do
      write(Format('%d ',[a[i]]));
    write(#13#10);
    sleep(200);
  end;
end.
\$\endgroup\$
  • \$\begingroup\$ primes[8] probably needs to be changed as You may not use the numeral 8.. Maybe I am too strict in interpreting this. \$\endgroup\$ – TheConstructor Mar 13 '14 at 22:35
  • \$\begingroup\$ Ooops I didnt see that one lol.. let me fix that.. \$\endgroup\$ – Teun Pronk Mar 14 '14 at 8:51
  • \$\begingroup\$ Changed it to (primes[1]*primes[3])+primes[0] which is (3*7)+2 :) Thanks for noting that \$\endgroup\$ – Teun Pronk Mar 14 '14 at 8:54
2
votes
\$\begingroup\$

PHP

strtotime capabilities

echo date('n', strtotime('april')) .', ';
echo date('n', strtotime('august')) .', ';
echo date('n', strtotime('january')) . date('n', strtotime('may')).', ';
echo date('n', strtotime('january')) . date('n', strtotime('june')).', ';
echo date('n', strtotime('february')) . date('n', strtotime('march')).', ';
echo date('n', strtotime('april')) .date('n', strtotime('february'));
\$\endgroup\$
2
votes
\$\begingroup\$

PHP

<?php
    $x = crc32("KLEJl");
    $y = intval(dechex(ord(" ")) . ord("$"). ord("\t"));

    $r = false;
    for (;;) {
        $a = str_split(strval($x));
        $x ^= $y;
        foreach($a as $i => $c) {
            echo $c;
            if ($r || !$i) {
                echo "\n";
            }
            $r = !$r;
        }
    }
\$\endgroup\$
2
votes
\$\begingroup\$

Ruby

def seq_for(n)

  seq = [n*n, n*n*n, n*n*n*n, n*n*n*n, "#{n}#{-~n}", "#{n*n}#{n}"]

  seq[n]-=~-n

  seq.join(''<<(n + seq.last.to_i))

end

loop do
  n=-~(rand $$)
  puts(seq_for(n+n)) rescue n
end

No numbers in any base in the code, just a method that will output The Numbers if given a certain argument, and will error out for almost any other input. With the loop wrapper this will just output The Numbers at random intervals. Incidentally, the wrapper prevents this from happening, but with other input seq_for can produce

10000100

or

1
 1
  1
   1
    12
      11

or

9`27`81`79`34`93
\$\endgroup\$
2
votes
\$\begingroup\$

C

Not very creative, I'm afraid.

char*p="DHOPWj";main(){for(;;)!*p?p-=6:printf("%d, ",*p++&63);}
\$\endgroup\$
2
votes
\$\begingroup\$

Java

class N {
    public static void main(String[] args) {
        while(true) {
            int n = " ".length();
            System.out.print(
                (++n + n) + " " + 
                ((++n - n) + ++n + n) + " " + 
                ((n * n) - (n / n)) + " " +
                (n * n) + " " +
                ((n * n) + (n + n) - (n / n)) + " " +
                ((n * n * n)  - n * --n * --n + n) + "\n"
            ); 
        }
    }
}

Turned out to be rather simple.

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

Just:

while(1) document.write(parseInt(Math.random()*50));

There's a little noise, but that's contest OK.

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

Python

I found a quintic polynomial that goes through the numbers at x from 1 to 6:

-0.225x5 + 4.25x4 - 29.375x3 + 91.75x2 - 122.4x + 60

So here's my Python solution:

for x in range(1,6):print -0.225*x**5+2*2.125*x**(2+2)-29.375*x**3+91.75*x**2-2*61.2*x+60

I know it isn't the shortest and it uses numbers, but I like it because it uses a generating function.

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

Javascript

function f(a) {
var b=(a%6)-3; 
return ((1 - ~~(((a%6)+1)/(1<<2))) * (Math.pow (2,((a%6)+2)) - (~~(((a%6)+1)/3))))  + (~~(((a%6)+1)/(1<<2))*((2<<3)+(2<<2)*b*b-Math.pow(6,b*(b-1)/2)*Math.round(b/2)))
}
for (i=0;;i=(i+1) % Math.pow (2,52))
   console.log (f (i))
}  

Using this formula

enter image description here

The fomula basically does the following

function f(x) {
   var value = 0;                                        
   x = 1 + (x % 0);
   if (x < 3)  {
       value += 2^(x+3);                                //0:4, 1:8, 2:16, 3:0, 4:0, 5:0
       if (x > 2) {
           value -= 1                                   //0:0, 1:0, 2:1, 3:0, 4:0, 5:0
       }
   } else {
      value += 16;                                      //0:0, 1:0, 2:0, 3:16, 4:16, 5:16
      value += 8 * (x-3)^2                              //0:0, 1:0, 2:0, 3:0, 4:8, 5:32
      value -= ( 6 ^ ((x-3) - (x-4))) * round ((x-3)/2) //0:0, 1:0, 2:0, 3:0, 4:1, 5:6
   }
   return value;
}  

I don't know if that's the right way to construct a formula, but since i never studied math nor did something like this before, this was the only thing i could come up with. I was actually pretty surprised that you can give your algebra somewhat like a control flow. Took me a while to figure this out though

This is how it looks when you draw it It looks a lot less chaotic than i thought for not whole numbers

enter image description here

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

Python

Using simple bitshifts and XOR's

#!/usr/bin/python                                                                                                                                                                                                                        
while True:
    print 1 << 1 << 1
    print 1 << 1 << 1 << 1
    print ( 1 << 1 << 1 << 1 << 1 ) ^ 0b11111
    print ( 1 << 1 << 1 << 1 << 1 )
    print ( 1 << 1 << 1 << 1 << 1 << 1 ) ^ 0b110111
    print ( 1 << 1 << 1 << 1 << 1 << 1 ) ^ 0b001010
\$\endgroup\$
2
votes
\$\begingroup\$

C++

Never said we couldn't just take two other numbers and add 'em!
EDIT: Forgot to cast the ints as strings, now the code is really ugly!

#include <iostream>
#include <sstream> 

int main () {
     std::ostringstream convert1;
     std::ostringstream convert2;
     std::ostringstream convert3;
     std::ostringstream convert4;
     std::ostringstream convert5;
     std::ostringstream convert6;
     int fourint = 1 + 3;
     convert1 << fourint;
     std::string four = convert1.str();
     int eightint = 1 + 7;
     convert2 << eightint;
     std::string eight = convert2.str();
     int fifteenint = 2 + 13;
     convert3 << fifteenint;
     std::string fifteen = convert3.str();
     int sixteenint = 3 + 13;
     convert4 << sixteenint;
     std::string sixteen = convert4.str();
     int twentythreeint = 1 + 22;
     convert5 << twentythreeint;
     std::string twentythree = convert5.str();
     int fortytwoint = 21 * 2;
     convert6 << fortytwoint;
     std::string fortytwo = convert6.str();
     while (1) {
          std::cout << "\n" + four + " " + eight + " " + fifteen + " " + sixteen + " " + twentythree + " " + fortytwo;
     }
}
\$\endgroup\$
2
votes
\$\begingroup\$

C#

By using 7 that is allowed by question, start everything of wordcount from "0000"

int four ="0000".Length;
int eight = four + four;
int fifteen = eight + 7;
int sixteen = eight + eight;
int twentythree = sixteen + 7;
int fourtytwo = four + fifteen + twentythree;
List<int> list = new List<int> { four, eight, fifteen, sixteen, twentythree, fourtytwo };

//while (true) //for (; ;)
//{
//    foreach (int number in list)
//    {
//        Console.WriteLine(number);
//    }
//}

//infinite loop via number 0,7,9 that are allowed
//for (int i=0; i<7; i++)
//{
//    Console.WriteLine(list[i]);
//    if (i == (7-9+7))
//        i = 0;
//}

for (int i=0;;i++)
{
    Console.WriteLine(list[i]);
    i = i % (7-9+7);
}
\$\endgroup\$
2
votes
\$\begingroup\$

PHP

I took "You may not use the numeral 4" and 8 to mean anywhere in the code and went for an ultra simple mathematical solution...

while (1) {
    $x = 3;
    echo ++$x . ',';
    echo $x*=2 , ',';
    echo floor($x*=1.9) , ',';
    echo floor($x*=1.1) , ',';
    echo ceil($x*=1.35) , ',';
    echo floor($x*=1.9) , ',';
}
\$\endgroup\$
2
votes
\$\begingroup\$

JavaScript

while(1)[1,5,12,13,20,39].map(function(n){console.log(n+3)})

Okay, that's basically hard-coding the numbers. How about:

while(1)[].map.call('DHOPWj',function(n){console.log(n.charCodeAt()&63)})

or a shorter version of that one:

for(i=0;;i=++i%6)console.log('DHOPWj'.charCodeAt(i)&63)
\$\endgroup\$
2
votes
\$\begingroup\$

Python

while True:
    d = 57173610360
    while d:
        d,m = divmod(d, 67)
        print(m)

4
8
15
16
23
42
...

Constants found from the following:

>>> s, v = (4, 8, 15, 16, 23, 42), []
>>> for j in range(max(s)+1,101):
    sm = str(sum(n*j**i for i,n in enumerate(s)))
    if not any(x in sm for x in (str(y) for y in s)):
        v.append((j, sm))


>>> v
[(67, '57173610360')]
>>> 
\$\endgroup\$
2
votes
\$\begingroup\$

C#

Uses a single constant, 2:

using System;

namespace Seq
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = 2;
            var b = a;

            while (true)
            {
                a *= b;
                var x = a;
                Console.Write(" " + a);
                a *= b;
                var y = a;
                Console.Write(" " + a);
                a *= b;
                b = b / b;
                a = a - b;
                var z = a;
                Console.Write(" " + a);
                a = a + b;
                var w = a;
                Console.Write(" " + a);
                a = y + z;
                Console.Write(" " + a);
                a = x + y + z + w - b;
                Console.Write(" " + a);

                a = b + b;
                b = a;

                Console.ReadLine();
            }
        }
    }
}
\$\endgroup\$
2
votes
\$\begingroup\$

Java

I was inspired from the sample of how not to do it.

class TheNumbers 
{
    public static void main(String[] args) {

    int FOUR = 9+9-7-7;
    int EIGHT = 9+9-7-7 + 9+9-7-7;
    int FIFTEEN = (9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9 - 7)/(9-7);
    int SIXTEEN = 9+9-7-7+9+9-7-7 + 9+9-7-7+9+9-7-7;
    int TWENTY_THREE = (9+9-7-7+9+9-7-7 + 9+9-7-7+9+9-7-7 +  9+9-7-7+9+9-7-7 + 9+9-7-7+9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9-7 + 9-7+ 9-7)/(9-7);
    int FOURTY_TWO =  9+9-7-7+9+9-7-7 + 9+9-7-7+9+9-7-7 +  9+9-7-7+9+9-7-7 + 9+9-7-7+9+9-7-7 + 9+9-7-7 + 9+9-7-7 + 9-7;

    for(int n = 0;;) System.out.println(
        n == FOUR ? n = EIGHT :
        n == EIGHT ? n = FIFTEEN :
        n == FIFTEEN ? n = SIXTEEN :
        n == SIXTEEN ? n = TWENTY_THREE :
        n == TWENTY_THREE ? n = FOURTY_TWO : (n = FOUR)
        );
    }
}

Edited so that I do not use the numbers 1,2,3,4,5,6,8,0 anywhere. I originally had things like 14+1 to avoid using 15, but there is a 1 and a 4 that I am not allowed to use.

Sweet, I got upvotes?! I thought this would be ignored or even possibly downvoted xD <3

\$\endgroup\$
  • \$\begingroup\$ You have a lot of 4's in there \$\endgroup\$ – durron597 Mar 14 '14 at 13:32
  • \$\begingroup\$ Bah, I missed the fact that the number 4 couldn't be used anywhere in a number. I shall make the appropriate edits ;) \$\endgroup\$ – TheOneWhoPrograms Mar 14 '14 at 13:39
  • \$\begingroup\$ I would find this funnier in a personal way if they were named like NOT_FOUR, NOT_EIGHT, etc. You know, just to be sure what they "aren't". ; P \$\endgroup\$ – Radiodef Mar 18 '14 at 6:54
  • \$\begingroup\$ haha, that would be pretty good :p I'll keep that in mind for next one I do to do something funny with variables. \$\endgroup\$ – TheOneWhoPrograms Mar 18 '14 at 7:19
2
votes
\$\begingroup\$

Coffeescript, 142B

f = (x) -> Math.round(3+1-223*x/20+(2*13.1375+0.6)*x*x-2*7.3125*x*x*x+3.125*x*x*x*x-0.225*x*x*x*x*x)
document.body.append ' '+f(i%6) while i++

Solve a system of linear equations, echo result.

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

So print 4, 8, 15, 16, 23, 42 without using the actual numbers in the code.
Not the best looking solution, but it is definitly the easiest

2 * 2 = 4
4 * 2 = 8
8 * 2 - 1 = 15
15 + 1 = 16
16 + 7 = 23
23 + 19 = 42

<?php

while (true) {
    $nr = 2 * 2;        // 4
    echo $nr;
    $nr = $nr * 2;      // 8
    echo $nr;
    $nr = $nr * 2 - 1;  // 15
    echo $nr;
    $nr = $nr + 1       // 16
    echo $nr;
    $nr = $nr + 7       // 23
    echo $nr;
    $nr = $nr + 19      // 42
    echo $nr;
    echo PHP_EOL;
}

?>
\$\endgroup\$
  • \$\begingroup\$ Thx for the downvotes ... \$\endgroup\$ – BlueCacti Mar 24 '14 at 13:05
1
vote
\$\begingroup\$

C++

#include<iostream>
int main()
{
    for(;;)
        std::cout<<'\n'-6<<", "<<'\n'-2<<", "<<'\n'+5<<", "<<'\n'+6<<", "<<' '-9<<", "<<'*'+0<<", ";
}
\$\endgroup\$
  • \$\begingroup\$ Could down-voter explain why he/she don't like the answer ? \$\endgroup\$ – Mukul Kumar Mar 13 '14 at 3:24
  • 1
    \$\begingroup\$ Could be because this is basically the same as the "valid, but uninspired" version in the OP. \$\endgroup\$ – Geobits Mar 13 '14 at 12:56
1
vote
\$\begingroup\$

C

A few (implementation dependent) ideas:

1

main()
{
    char a[] = "uKyKrvKrwKstKusK";
    unsigned int i;

    for(i = 0; i >= 0; i++)
    {
        printf("%c", (char)(a[i&(sizeof(a)-2)] - 'A'));
    }
}

2

#include <stdio.h>
#include <string.h>
#include <float.h>

#define Answer_to_the_Ultimate_Question_of_Life_The_Universe_and_Everything  I_may_be_a_sorry_case_but_I_dont_write_jokes_in_base_13(Six by nine)
#define Six 0b110
#define by *
#define nine 0b1001
#define I_may_be_a_sorry_case_but_I_dont_write_jokes_in_base_13(x) 10*(x/13)+x%13

void PrintNumSequence(void);

int main(void)
{
    PrintNumSequence();
}

/*
Prints out the following sequence forever: http://lostpedia.wikia.com/wiki/The_Numbers
*/
void PrintNumSequence(void)
{
    int a[] = {sizeof(int), sizeof(double), DBL_DIG, strlen(__func__), __LINE__, Answer_to_the_Ultimate_Question_of_Life_The_Universe_and_Everything};
    unsigned int i;

    while(1)
    {
        for(i = 0; i < sizeof(a)/sizeof(a[0]); i++)
        {
            printf("%d \n", a[i]);
        }
    }
}
\$\endgroup\$
1
vote
\$\begingroup\$

Python

def main():
    a = range(3+1)
    b = range(7+1)
    c = range(3*5)
    d = range(13+3)
    e = range(20+3)
    f = range(6*7)
    All = [a,b,c,d,e,f]
    while True:
        for n in All:
            print(len(n))
main()
\$\endgroup\$
  • \$\begingroup\$ Thanks for the edit, I didn't think that could also work! \$\endgroup\$ – Ol' Reliable Mar 12 '14 at 17:47
1
vote
\$\begingroup\$

The following snippets will print 4, 8, 15, 16, 23, 42 infinitely often:

Python

OASIS

import urllib2
response = urllib2.urlopen('https://oeis.org/search?q=id:A104101&fmt=text')
html = response.read().split("\n")
while True:
    print(html[6][-15:])

Char-Codes:

four = ord('')
eight = ord("\n")-2
fifteen = ord("\n")+5
sixteen = ord("")
twentythree = ord("")
theanswer = ord("*")
numbers = "%s, %s, %s, %s, %s, %s" % (four, eight, fifteen, sixteen, twentythree, theanswer)
while True:
    print(numbers)

Substring of Pi

Pi contains 481516234 at position 176,025,488 (source). One could use that.

\$\endgroup\$
  • \$\begingroup\$ Of course to use your PI method, you would have to first calculate PI to 176,025,497 digits. And then you couldn't index into the digits using pi.substring(176025488) because that includes the digits 4 and 8. :-) \$\endgroup\$ – Jay Mar 18 '14 at 22:17
  • \$\begingroup\$ @Jay To get 176025488 you can use π again. You could split it up to 176025 and 488. You can use 176025 directly and use the 321-323 position to get 488. \$\endgroup\$ – Martin Thoma Mar 18 '14 at 22:26
1
vote
\$\begingroup\$

C

Here is an Ungolfed version using C. If you get too many initializations error, just initiate a[4] and a[5] seperately and it will do it.

#include<stdio.h>
main()
{
    char i,j,a[5] = {'Z'-'V','Z'-'R','Z'-'K','Z'-'J','Z'-'C','*'};
    for(i='Z';'a';i++) {
        for(j='Z'-'Z';j<='Z'-'U';j++) {
            printf("%d\n",a[j]);
        }
    }
}

Here's a Golfed Version:

#include<stdio.h>
main(){char i,j,a[5] = {'Z'-'V','Z'-'R','Z'-'K','Z'-'J','Z'-'C','*'};for(i='Z';'a';i++)for(j='Z'-'Z';j<='Z'-'U';j++)printf("%d\n",a[j]);}
\$\endgroup\$
1
vote
\$\begingroup\$

Python 2.7:

>>> a=len("four")
>>> b=a+a
>>> d=b+b
>>> c=d-(d/d)
>>> e=b+c
>>> f=b/a*e-d/a
>>> while a: print " ".join([str(i) for i in [a,b,c,d,e,f]]),

Pretty straightforward I'd say.

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

Python3

Here's another piece. My first try was improved by canaaerus (the final part of the code below is adapted from there), and now I'm using the following sequences to create the desired one: A075105, A070750 and A122115.

from math import floor, log, pi, sin
from fractions import Fraction

def log2(x):
    return log(x) / log(2)

def isprime(n):
    for i in range(2, n):
        if n % i == 0: return False
    return True

v = [ Fraction(n,floor(log2(n))).numerator for n in range(5,10) ]
p = filter(isprime,range(7,20))
s = [ sin(k*pi/2) for k in p ]
x = [ floor(a*b) for a,b in zip(s,v) ]

while x[-1] != 66:
    x.append(x[-5] + x[-3] + x[-1])

while True:
    print(x[-7:-1])
\$\endgroup\$
1
vote
\$\begingroup\$

C

main()
{
    int num;

    for (num=1;;num=1) {
        printf("%d\n", num<<=2);
        printf("%d\n", num<<=1);
        printf("%d\n", num|7);
        printf("%d\n", num<<=1);
        printf("%d\n", num|7);
        printf("%d\n", num<<1|num>>1|1<<1);
    }
}
\$\endgroup\$
1
vote
\$\begingroup\$

JavaScript

      var four = 3+1;
      var eight=7+1;
      var fifteen = 13+2;
      var sixteen = 13+3;
      var twentythree = 22+1;
      var fortytwo = 39+3;

while(true){
      var sequence = four  + ", " + eight+ ", " + fifteen  + ", " + 
                     sixteen  + ", " +     twentythree  + ", " + fortytwo ;
       console.log(sequence);
}

Kinda ridiculously easy task, unless I'm missing something...

\$\endgroup\$
  • 2
    \$\begingroup\$ It works, but it's essentially the same concept as the questioner's given example, "a valid (but not very inspired) Java program". p.s. Minor style point: custom is to use the Markdown header syntax ## JavaScript at the top of your answer instead of just bolding the text...unless you are deliberately trolling the folks with OCD. :) Welcome to the site! \$\endgroup\$ – Jonathan Van Matre Mar 15 '14 at 12:37
1
vote
\$\begingroup\$

PHP

<?php
$a[]=2;
$a[]=$a[0]*$a[0];
$a[]=$a[1]*$a[0];
$a[]=$a[2]*$a[0]-1;
$a[]=$a[2]*$a[0];
$a[]=strrev($a[$a[0]+$a[0]]*$a[0]);
$a[]=$a[0]*21;
unset($a[0]);

while(1){
  foreach($a as $b){
   echo $b.' ';
  }
  //optional for formatting
  echo "<br>\n";
}
?>

Slight Modification

<?php
$a[]=2;
$a[]=$a[0]*$a[0];
$a[]=$a[1]*$a[0];
$a[]=$a[2]*$a[0]-1;
$a[]=$a[2]*$a[0];
$a[]=strrev($a[$a[0]+$a[0]]*$a[0]);
$a[]=$a[0]*21;
unset($a[0]);

while($a){
  $b=array_reverse($a);
  while($b){
    echo array_pop($b).' ';
  }
//optional for formatting
echo "<br>\n";
}  
\$\endgroup\$

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