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
    Commented 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\$ Commented 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
    Commented 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
    Commented 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
    Commented Mar 13, 2014 at 13:21

109 Answers 109

4
votes
\$\begingroup\$

My first participation on CodeGolf.SE :

Objective-C (polynomial version)

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        for (int i = 1; ; i++) {
            NSLog(@"%.0f", (1200*2 - (9792/2)*i + 3670*pow(i,2) - 1175*pow(i,3) + 170*pow(i,3)*i - 9*pow(i,5)) / (20*2));
            if (i==6) i=0;
        }
    }
    return 0;
}

Polynomial used :

       2400 - 4896 * i + 3670 * i^2 - 1175 * i^3 + 170 * i^4 - 9 * i^5 
f(i) = ---------------------------------------------------------------
                                     40

Which gives the expected values for i in [1,6].

Objective-C (binary version)

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        while (YES) {
            NSLog(@"%i", 32 >> 3);
            NSLog(@"%i", 32 >> 2);
            NSLog(@"%i", 30 >> 1);
            NSLog(@"%i", 32 >> 1);
            NSLog(@"%i", 92 >> 2);
            NSLog(@"%i", 336 >> 3);
        }
    }
    return 0;
}
\$\endgroup\$
2
  • \$\begingroup\$ Does this output the number infinitely? Also, you are typically supposed to provide the full program or function when solving challenges. \$\endgroup\$
    – user10766
    Commented Mar 12, 2014 at 16:19
  • \$\begingroup\$ Yes, it does print infinitely beacause of the never-ending for loop. I updated the code with more context, I thought just the "interesting part" was enough :) \$\endgroup\$
    – rdurand
    Commented Mar 12, 2014 at 16:30
4
votes
\$\begingroup\$

PHP

(But method will work in any language). 28 chars:

while(1) echo 267509019*2*9;

How it works

We just factorize this 4815162342 as number. It has many divisors, thus, we'll be able to select those of them which won't violate our restriction.

About delimiters for numbers: it's not stated in question (well, that they should present) - and some of high-rated answers will not output any delimiters, so I won't use them as well - but it's not hard to add them (of course, code then will be little longer);

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

C

The formula

a[i] = a[i-1] + a[i-3] + a[i-5]

works with proper initialization: -5, -3, 7, 8, -3, -1, 4, 8, 15, 16, 23, 42, 66, and so on. (Note that unfortunately, the number 8 appears twice in this sequence.)

The following slightly golfed ANSI C program generates the six numbers by initializing and iterating. It then loops forever printing them, as was requested.

#include <stdio.h>
int main() {
    int a[] = { -5, -3, 7, 1<<3, -3, -1 };
    int j = 0;
    for (; ++j<7; ) a[(j-1)%6] = a[j%6] + a[(2+j)%6] + a[(4+j)%6];
    for (;;) for (j=0; j<6; j++) printf("%d\n", a[j]);
}
\$\endgroup\$
3
votes
\$\begingroup\$

Java

Here is a very straightforward icebreaker entry which does a little more than the 'bare-minimum' example in the OP.

The Numbers

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class TheNumbers {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JFrame() {
                    JLabel lbl = new JLabel("00", JLabel.CENTER);
                    int[] nums;
                    int i;
                    {
                        int n = '$' & '^';
                        nums = new int[] {
                            n,
                            n *= 2,
                            n += 7,
                            ++n,
                            n += 7,
                            n += 19,
                        };
                        lbl.setFont(lbl.getFont().deriveFont(63f));
                        lbl.setOpaque(true);
                        lbl.setBackground(Color.BLACK);
                        lbl.setForeground(Color.WHITE);
                        add(lbl);
                        pack();
                        setResizable(false);
                        setLocationRelativeTo(null);
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        lbl.setText(Integer.toString(nums[0]));
                        new Timer(500, new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent ae) {
                                lbl.setText(Integer.toString(nums[i = (i + 1) % 6]));
                                validate();
                            }
                        }).start();
                    }
                }.setVisible(true);
            }
        });
    }
}
\$\endgroup\$
4
  • \$\begingroup\$ Dat Swing... Why do you put code in an inner JFrame class? Why not extend JFrame or create an object and call methods on it? \$\endgroup\$
    – nrubin29
    Commented Mar 12, 2014 at 23:33
  • 1
    \$\begingroup\$ @nrubin29 Just to amuse myself. \$\endgroup\$
    – Radiodef
    Commented Mar 12, 2014 at 23:34
  • 1
    \$\begingroup\$ Alright, fair enough. \$\endgroup\$
    – nrubin29
    Commented Mar 12, 2014 at 23:54
  • \$\begingroup\$ Would the animated gif itself not count as an entry? It's a program, too. \$\endgroup\$
    – kojiro
    Commented Mar 13, 2014 at 13:20
3
votes
\$\begingroup\$

VBA

 ns = Split("I Di|dn't| like L|O|ST past| Season 2. Downhill", "|")
 Do While True: n = LBound(ns): For i = LBound(ns) To UBound(ns): n = n + Len(ns(i)): Debug.Print n: Next i: Loop

leave option explicit off

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

Haskell, 215 Characters

a=[1..]
b c(d:e)=(d`div`2):b(c+1)(f e)where f e=g++f h where(_:g, h)=splitAt(c+1)e
c@(_:d)=b 1 a
main=print.cycle.take 6$zipWith3(\e f g->(+g).(*3).head$filter((==f-e).(\h->length$filter((==0).mod h)[1..h]))a) c d a

Can you unravel the logic?

Spoiler:

c (line 3) is the result of halving the numbers in A056526, and main is then generated from A130826.

\$\endgroup\$
1
  • \$\begingroup\$ Perhaps you should post a spoiler - use >! at the beginning of the line to do so. \$\endgroup\$
    – user10766
    Commented Mar 12, 2014 at 22:31
3
votes
\$\begingroup\$

JavaScript

Technically, the numbers are not hard-coded !

var numbers = [
    parseInt(prompt("Please enter the number four : ", "")),
    parseInt(prompt("Please enter the number height : ", "")),
    parseInt(prompt("Please enter the number fifteen : ", "")),
    parseInt(prompt("Please enter the number sixteen : ", "")),
    parseInt(prompt("Please enter the number twenty-three : ", "")),
    parseInt(prompt("Please enter the number fourty-two : ", ""))
];

var i = 0;
while(true) {
    console.log(numbers[i]);
    i++;
    if(i >= numbers.length) i = 0;
}
\$\endgroup\$
3
votes
\$\begingroup\$

JAVA

Arithmetical variant with usage of literals "1", "-1" and operators "^", "<<". Just for fun;)

final ByteBuffer buffer = ByteBuffer.allocate(-1 << 1 << 1 << 1 ^ -1 ^ 1);
buffer.put((byte)(1 << 1 << 1));
buffer.put((byte)(1 << 1 << 1 << 1));
buffer.put((byte)(-1 << 1 << 1 << 1 << 1 ^ -1));
buffer.put((byte)(1 << 1 << 1 << 1 << 1));
buffer.put((byte)(-1 << 1 << 1 << 1 << 1 << 1 ^ -1 ^ 1 << 1 << 1 << 1));
buffer.put((byte)(((-1 << 1 << 1 << 1 << 1 << 1 ^ -1 ^ 1 << 1 << 1 << 1) << 1) ^
    1 << 1 << 1));

for (;;)
{    
    buffer.rewind();
    while (buffer.position() < buffer.capacity())
    {
        System.out.println(buffer.get());
    }            
}
\$\endgroup\$
3
votes
\$\begingroup\$

JavaScript, obfuscated in astral unicode characters

eval(unescape(escape('𩡯𬠨𞰻𚑣𫱮𬱯𫁥𛡬𫱧𚀴𛀸𛀱𝐬𜐶𛀲𜰬𝀲𚐠').replace(/uD./g,'')))

Step-by-step reverse-engineering:

// eval(unescape(escape('𩡯𬠨𞰻𚑣𫱮𬱯𫁥𛡬𫱧𚀴𛀸𛀱𝐬𜐶𛀲𜰬𝀲𚐠').replace(/uD./g,'')))
// ==
// eval(unescape('%uD866%uDC6F%uD872%uDC28%uD83B%uDC3B%uD829%uDC63%uD86F%uDC6E%uD873%uDC6F%uD86C%uDC65%uD82E%uDC6C%uD86F%uDC67%uD828%uDC34%uD82C%uDC38%uD82C%uDC31%uD835%uDC2C%uD831%uDC36%uD82C%uDC32%uD833%uDC2C%uD834%uDC32%uD829%uDC20'.replace(/uD./g,'')))
// ==
// eval(unescape("%66%6F%72%28%3B%3B%29%63%6F%6E%73%6F%6C%65%2E%6C%6F%67%28%34%2C%38%2C%31%35%2C%31%36%2C%32%33%2C%34%32%29%20"))
// ==
// eval("for(;;)console.log(4,8,15,16,23,42) ")
\$\endgroup\$
3
votes
\$\begingroup\$

C

Obligatory root finding answer.

#include <stdio.h>

long double coeffs[ 6 ] = {-1113609, -1109096, -1200771, -232037, -5353053, 6305379};

void dkw(long double* const r, long double* c, const int l) {
    int i = 10, j, k;
    long double f, a, t;
    for( j = 0 ; j < l ; j++ )
        r[j] = j * 5.53;
    while( i-- )
        for( j = 0 ; j < l ; j++ ) {
            f = 1;
            for( k = 0 ; k < l ; k++ )
                f = f * r[j] + c[k];
            a = 1;
            for( k = 0 ; k < l ; k++ )
                if(k != j)
                    a *= r[j] - r[k];
            r[j] -= f / a;
        }
}

int main() {
    int i;
    long double res[6];
    for( i = 0 ; i < 6 ; i++ )
        coeffs[i] += 1113501;
    putchar('\n');
    dkw(res, coeffs, 6);
    for( i = 0 ; ; i = ++i % 6 )
        printf("%.0Lf, ", res[i]);
}
\$\endgroup\$
3
votes
\$\begingroup\$

C

Uses the recurrence relation x(n)=x(n-1)+x(n-3)+x(n-5) to generate the sequence

#include <stdio.h>

int main()
{
int i,j;
    while(1)
    {
    int n[7]={0,-3,7,0,-3,-1,0};
    n[3]=-2*(n[1]+n[5]);
        for(j=0;j<6;j++)
        {
        n[6]=n[5]+n[3]+n[1];
            for(i=1;i<6;i++)n[i]=n[i+1];
        printf("%d\n",n[6]);
        }
    }
    return 0;
}
\$\endgroup\$
3
votes
\$\begingroup\$

C/C++

The numbers are encoded in acosh(acosh(1.65592)-2.6139625e-6)

main()
{
    for(;;)
        for(long long int y=acosh(acosh(1.65592)-2.6139625e-6)*1e12;y>1;y/=100)
            printf("%d ",y%100);
}
\$\endgroup\$
3
votes
\$\begingroup\$

C#

Alternative bases are restricted, but the question does not say anything about alternative numeral systems :)

using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static int RomanNumeral(string numeral) {
        var digits = new Dictionary<char, int>();
        digits['I'] = 1;
        digits['V'] = 5;
        digits['X'] = 10;
        digits['L'] = 50;

        int result = 0;
        int lastHighest = int.MaxValue;
        foreach(char character in numeral) {
            int current = digits[character];
            if(current > lastHighest) {
               result += current - 2 * lastHighest;
            } else {
               result += current;
               lastHighest = current;
            }
        }

        return result;
    }

    static void Main()
    {
        string[] numbers = new string[] {
            "IV", "VIII", "XV", "XVI", "XXIII", "XLII"
        };

        foreach(var number in numbers) {
            System.Console.WriteLine(RomanNumeral(number));
        }
    }
}

PS Answer #64 - shall we leave it at this or do we keep going to 128?

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

Python

Tried to see if I could avoid the use of literals (whether numeric or character) entirely. (Obviously most of these names point to literals, but I didn't actually write them down!) The only one I didn't manage to get rid of is the comma+space at the end.

import math

chocolate, vanilla = math.ceil, math.floor
cherry = math.e
pecan, caramel = math.pi, math.pi*vanilla(cherry)
mint = lambda x: int(math.log(x))

def icecream():
    candy_cane = vanilla(cherry)**vanilla(cherry)
    crunch = peanut_butter

    while True:
        if vanilla(cherry) + vanilla(pecan) == crunch:
            candy_cane = chocolate(caramel) * vanilla(caramel)
            crunch = chocolate(caramel) % mint(cherry)
        elif not crunch or crunch % (mint(cherry) + mint(cherry)):
            candy_cane = chocolate(pecan)
            candy_cane *= vanilla(cherry)**chocolate(crunch/vanilla(cherry))
            crunch += pecan**vanilla(pecan-cherry)
        else:
            candy_cane += chocolate(caramel)
            crunch += mint(cherry)
        yield candy_cane

if __name__ == '__main__':
    for flavor in icecream():
        print(flavor, end=", ")

Output: http://ideone.com/uwax5b

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

mawk

...as oneliner:

mawk 'BEGIN { while(1) for(i=1;i<ARGC;i++) { srand(ARGV[i]) ; printf int(rand()*100)" " } }' Byte Lyrik knistert emotionell neuartig wundervoll

(tested with mawk-1.3.3 on debian-6.0.9, debian-7.4 and netbsd-6.1)

...as mawk-progam avoiding digits completely:

BEGIN {
  split("Byte Lyrik knistert emotionell neuartig wundervoll",A)
  o=m++
  while(m)
    for(i=m;i in A;i++) {
      srand(A[i])
      printf int(rand()*(m o o))" "
    }
}
\$\endgroup\$
3
votes
\$\begingroup\$

Clojure

(dorun
  (map prn
    (let [t (+ (*) (*)) f (+ t t)]
      (cycle [f (+ f f) (- (* f f) (*)) (* f f) (- (* f (+ t f)) (*)) (* (+ t t t) (- (+ f f) (*)))]))))

Or perhaps this version will be more easily understood:

(dorun (map prn
  (let [_ (+ (*) (*))
        __ (+ _ _)
        _' (+ _ __)
        _- (* _ __)]
    (cycle [__
            _-
            (- (* __ __) (*))
            (* __ __)
            (- (* __ _') (*))
            (* _' (- _- (*)))]))))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to the PPCG Stack Exchange! Other users might find your answers more valuable if you provide information or brief explanations as to why your program is supposed to do what you say it does. \$\endgroup\$ Commented Mar 19, 2014 at 13:47
  • 1
    \$\begingroup\$ Okay… (*) is a multiply with no arguments; its result is 1. t is 2. f is 4. The rest should be pretty basic. \$\endgroup\$ Commented Mar 19, 2014 at 14:27
3
votes
\$\begingroup\$

I like Calendars

import java.util.Calendar;
public class Sequence {
    public static void main(String[] args) {
        while(true){
            System.out.println(Calendar.MAY);
            System.out.println(Calendar.SEPTEMBER);
            System.out.println(Calendar.SEPTEMBER + Calendar.AUGUST);
            System.out.println(Calendar.SEPTEMBER + Calendar.SEPTEMBER);
            System.out.println(Calendar.SEPTEMBER + Calendar.SEPTEMBER + Calendar.AUGUST);
            System.out.println(Calendar.DECEMBER + Calendar.DECEMBER+ Calendar.NOVEMBER + Calendar.NOVEMBER);
        }
    }
}
\$\endgroup\$
3
votes
\$\begingroup\$

Of course there's a formula:

int xx=0;
while (true)
{
  int x=xx++ % 6 + 1;
  System.out.println((-x*x*x*x*x*9 + x*x*x*x*170 - x*x*x*1175 + x*x*3670 - x*(612*2*2*2) + 1200*2)/(20*2));
}

The 153*32 and 20*2 are just to avoid using the digits 4 and 8. I'm not sure if the intent of the rules was that, e.g. "40" is illegal because it includes the digit "4", but whatever.

\$\endgroup\$
4
  • \$\begingroup\$ Nice job, but you accidentally included a 4 and a 1 followed by a 5. Is there anyway you can fix this? \$\endgroup\$
    – user10766
    Commented Mar 18, 2014 at 23:11
  • \$\begingroup\$ @hosch250 Arggh, I rewrote a couple of the constants as products -- like I put 20*2 instead of 40 -- just to get around that. But obviously I missed a couple. But it's easy enough to eliminate them. Change 2400 to 1200*2, and 153*32 to, umm, 612*2*2*2. One could, of course, work in some of the techniques used by others to do it without using digits at all, "four".length() to get 4 for example. But it seemed inelegant to mix techniques. \$\endgroup\$
    – Jay
    Commented Mar 19, 2014 at 14:11
  • \$\begingroup\$ You can edit your answer--how about fixing those problems? \$\endgroup\$
    – ErikE
    Commented Mar 19, 2014 at 17:24
  • \$\begingroup\$ Well, okay. I generally avoid making those kinds of edits to keep the original comment comprehensible. But there, done. \$\endgroup\$
    – Jay
    Commented Mar 19, 2014 at 20:44
3
votes
\$\begingroup\$

Perl

@list=( "aaaa", 
        "aaaaaaaa", 
        "aaaaaaaaaaaaaaa", 
        "aaaaaaaaaaaaaaaa", 
        "aaaaaaaaaaaaaaaaaaaaaaa", 
        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

while (@list) {
    for($i=0;$i<6;$i++){
        print length($list[$i])." ";
    }
    print "\n";
}
\$\endgroup\$
2
votes
\$\begingroup\$

Python

can be made to look horrible too

from itertools import cycle
for x in cycle((2**2,2**2*2,2**2**2-7+2*2+2,2**2**2,(2**2*2*6-2)/2,2**2*2*6-6)):print x
\$\endgroup\$
2
votes
\$\begingroup\$

Fortran 95

program NO_NUMBERS_ALLOWED
implicit none

integer :: i, aux_A, aux_B
integer, allocatable :: array(:)

aux_A = iachar("!") - iachar(" ")
aux_B = iachar("&") - iachar(" ")

allocate(array(aux_A:aux_B))

array(aux_A:aux_B) = (/(iachar("$") - iachar(" ")), (iachar("(") - iachar(" ")), (iachar("/") - iachar(" ")), &
(iachar("~") - iachar("n")), (iachar("{") - iachar("d")), iachar("*")/)

i = aux_A
do
  print*, array(i)
  i = i + aux_A
  if (i==(aux_B + aux_A)) i = aux_A
enddo

end program NO_NUMBERS_ALLOWED

The variables aux_A and aux_B have their values defined via the function iachar(c), which converts a character into its integer ASCii value. The variable array contains all six values defined via mathematical operations and the already mentioned function. This array is then infinitely printed in order in the screen via an endless loop.

\$\endgroup\$
2
  • \$\begingroup\$ Why the negative vote? Did I miss something here? \$\endgroup\$ Commented Mar 12, 2014 at 17:00
  • \$\begingroup\$ Probably because there has been another answer with the same idea, or it is because the idea is boring. \$\endgroup\$ Commented Mar 22, 2014 at 16:38
2
votes
\$\begingroup\$

JavaScript (ES6)

while(true) "$(/07J".split('').map(i=>String.charCodeAt(i)-32).forEach(i=>console.log(i));

or, with non-printable characters,

while(true) "*".split('').map(i=>String.charCodeAt(i)).forEach(i=>console.log(i));
\$\endgroup\$
2
votes
\$\begingroup\$

C++

Haven't decided yet how ugly I think this is. Probably very :-)

#include <iostream>

double b, f[2];

float func(float x)
{
  // Maybe I should just choose a value for b here, instead of randomizing
  return 2+(x-1)*((x-b)*((-b+x-1)*(((((7/(b+1)-1/b)/(2*b+1)-
         (1/b-7)/(b+1))/(2*b+2)-((1/b-7)/(b+1)-(7-2/(b-1)*2)/b)/(2*b))*
         (-2*b+x-1))/(3*b+1)+((1/b-7)/(b+1)-(7-2/(b-1)*2)/b)/(2*b))+
         (7-2/(b-1)*2)/b)+2/(0.5*b-0.5))+2;
}

float fib()
{
  return f[0] = (f[1] += f[0]) - f[0], f[1];
}

int levels = 0;

int main() {
  f[0] = 1;
  b = f[1] = ((int)(&f)) & 0xee;

  std::cout << func(f[0]) << std::endl;
  std::cout << func(f[1]) << std::endl;
  std::cout << func(fib()) << std::endl;
  std::cout << func(fib()) << std::endl;
  std::cout << func(fib()) << std::endl;

  return main();
}

If you intend to have it run forever, make sure you have enough (i.e. infinite) stack.

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

C

void main(int a, char **b){
    char s[]={'/'-'\'','/'- ' ','_' - 'O','^' - 'G','~' - 'T',',' - '('};
    c:printf("%d ", s[(++a)%6]); goto c;
}
\$\endgroup\$
2
votes
\$\begingroup\$

Brainf**k

-[----->+<]>+.-[
--->++<]>--.----
[->++<]>.[-->+<]
>++++.[-->+++<]>
+.++++.--[--->++
<]>--.[-->+++<]>
+.+++++.[-->+<]>
+++++.[-->+++<]>
++.+.[--->++<]>-
-.++[-->+++<]>+.                       :=-=-=.
\$\endgroup\$
2
votes
\$\begingroup\$

Javascript

So this isn't very exciting but works.

var golf=(function() {
var zero = "";
function go() { 
    var str = "EIPQXk", output = new Array();
    for (var i = zero.length; i < str.length; i++) {
        output.push(str.charCodeAt(i) - "A".charCodeAt(zero.length));
    }
    return output;
}

while(true) {
    alert(go());
}
})();

Fairly clear what it's doing, but just in case, we're using ASCII character codes to pull back the numbers, starting at A (char code 65), just because A is nice and has no numerical connotations. First answer. Be gentle. :)

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ Commented Mar 12, 2014 at 23:38
2
votes
\$\begingroup\$

Python

while 1:print ' '.join([`int(3*5+57*x/20-31*x*x/2**3+11*x**3/2**3+7*x*x**3/2**3-9*x**5/(2**3*5))` for x in [-2.,-1,0,1.,2,3]]),

Interpolation over the sequence -2..3

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

Java

THE NUMBERS

I tried to golf/obfuscate it a little - as you can see I didn't try super hard. The program looks a lot better than the LICEcap gif.

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;

public class N extends JFrame implements ActionListener {
    public static void main(String[] args) throws Exception {
        i=new ImageIcon(ImageIO.read(new URL("http://i.imgur.com/oMloP1J.jpg")));
        EventQueue.invokeLater(new Runnable() {public void run() {new N().setVisible(true);}});
    }
    static ImageIcon i;
    JPanel c;
    Rectangle r;
    public N() {
        JLabel a=new JLabel(i);
        JLabel b=new JLabel(i);
        c=new JPanel();
        c.setLayout(new BoxLayout(c,1));
        c.add(a);
        c.add(b);
        JScrollPane j=new JScrollPane(c,21,31);
        Dimension d=j.getPreferredSize();
        d.setSize(d.width,d.height/2+1);
        j.setPreferredSize(d);
        r=new Rectangle(d);
        JPanel t=new JPanel();
        t.add(j);
        setContentPane(t);
        setResizable(false);
        pack();
        setDefaultCloseOperation(3);
        new Timer(20,this).start();
    }
    public void actionPerformed(ActionEvent e) {
        r.translate(0,1);
        if(r.getY()==r.height)r.translate(0,-r.height);
        c.scrollRectToVisible(r);
    }
}
\$\endgroup\$
2
votes
\$\begingroup\$

C#

using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = "ruLOST";
            var b = "nm=?<*";
            var i = 0;
            while (true)
            {
                Console.WriteLine(a[i] - b[i]);
                if (++i > 5) i = 0;
            }
        }
    }
}
\$\endgroup\$
2
votes
\$\begingroup\$

Java 7

Being old-school this is a real tree-shredder: (Tested against PDF-printer; respects page-ranges in regards of page-count)

import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.swing.*;
import java.awt.*;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class Sequence {
    public static void main(String[] args) {
        // initialize numbers
        long z = 12731310;
        for (long l = 1; l <= 9 * 17 * 263 * 1021; l++) {
            z += l;
        }
        long n = 9;
        for (int i = 0; i < 5; i++) {
            n *= 729;
        }
        n--;
        // Get into printing. Use the cross-platform dialog as it also asks for paper
        systemLookAndFeel();
        final PrinterJob printerJob = PrinterJob.getPrinterJob();
        printerJob.setJobName("Tree Shredder");
        printerJob.setPrintable(new PrintableSequence(z, n));
        final HashPrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
        if (printerJob.printDialog(attributeSet)) {
            try {
                printerJob.print(attributeSet);
            } catch (PrinterException e) {
                e.printStackTrace();
            }
        }
    }

    private static void systemLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
            // this should only happen if UIManager.getSystemLookAndFeelClassName() is broken
            e.printStackTrace();
        }
    }

    private static class PrintableSequence implements Printable {

        private       long z;
        private final long n;
        private       int  lastPage = -1;
        private       long lastZ;

        public PrintableSequence(long z, long n) {
            this.z = z;
            this.n = n;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            // First call ist just to check that the page exists and we need to produce the same page again
            if (pageIndex != lastPage) {
                lastPage = pageIndex;
                lastZ = z;
            } else {
                z = lastZ;
            }
            final FontMetrics fontMetrics = graphics.getFontMetrics();
            final double imageableWidth = pageFormat.getImageableWidth();

            graphics.translate((int) pageFormat.getImageableX(), (int) pageFormat.getImageableY());

            for (int y = fontMetrics.getMaxAscent();
                 y < pageFormat.getImageableHeight(); y += fontMetrics.getHeight() * 1.2) {
                for (int x = 0; x < imageableWidth; ) {
                    z = (z % n) * 9;
                    final char c = Character.forDigit((int) (z / n), 9);
                    final String s = c == '0' ? ", " : String.valueOf(c);
                    final double width = fontMetrics.getStringBounds(s, graphics).getWidth();
                    if (x + width > imageableWidth) {
                        z /= 9;
                        break;
                    }
                    graphics.drawString(s, (int) x, (int) y);
                    x += width;
                }
            }
            return PAGE_EXISTS;
        }
    }
}

The sequence is generated as in Implement arbitrary precision division.

\$\endgroup\$

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