90
24
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.
- Deriving it to a formula. My impression is there is not one but maybe there is or it can be faked.
- Fixing a pseudo-random generator to return the sequence.
This is a popularity contest, so be creative. The answer with the most up votes on March 26th is the winner.
8I can count 6 downvotes but no comments :/ – Vereos – 2014-03-12T13:52:43.713
1“You may not use the numeral 1 followed by the numeral 5” – So “1_5” is valid? Because
ruby
andperl
just interprets it as 15. – manatwork – 2014-03-12T13:57:06.0172@Vereos I was just thinking the same thing (... and 8 answers). I don't think the question is great, but I gave an upvote (and a comment) to even it out a bit. – daniero – 2014-03-12T13:59:02.030
1"Should I post these suggestions?" If you are changing the rules of the contest, no. If you just want to provide some ideas to get people to try approaching the challenge differently, go for it! Also, bear in mind there are no bonuses in a popularity contest...the votes reign supreme. – Jonathan Van Matre – 2014-03-12T14:01:22.313
This might have been funny as code-golf... – V-X – 2014-03-12T14:30:11.087
11@Vereos, "This is a stupid question" isn't very constructive, which might be why no-one posted it as a comment. – Peter Taylor – 2014-03-12T15:26:37.037
18
There are 11 types of people in this world: those that watched Lost, those that didn't, and those that don't understand binary.
– r3mainer – 2014-03-12T16:26:35.8577@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 thanThis is a stupid question.
, but that's just my personal opinion. – Vereos – 2014-03-12T16:57:25.1902
@Vereos 'Pretty trivial to solve' isn't even particularly constructive considering that many popularity contests are trivial to solve and the point is not to do the bare minimum.
– Radiodef – 2014-03-12T17:29:19.777@manatwork That's a good point, I forgot about underscores. Not sure if I should edit the OP. I thought about loopholes like this but ultimately figured that answers that take advantage of loopholes would be unpopular so it didn't make much of a difference. – Radiodef – 2014-03-12T17:31:54.040
@Radiodef The point of my sentence was not that; I just wanted to enhance the fact that in my opinion a downvote should always be paired to a (more or less) kind comment. – Vereos – 2014-03-12T17:48:11.787
@Vereos I get what you meant, I am just saying I still don't understand where the down votes came from. – Radiodef – 2014-03-12T17:55:34.267
@Radiodef aha I see what you did there... haven't seen Lost in quite some time! – CompuChip – 2014-03-12T18:01:06.780
When I saw the edit that added a link to "fix a pseudo-random generator", I thought it would point to my answer below. Instead it links to a page on SO :(
– Geobits – 2014-03-12T18:13:22.673@Geobits I didn't see you had actually already done it until after the edit but you got an up vote from me since it was a thing I had in mind. : ) I tried to find a seed myself but wasn't able to. – Radiodef – 2014-03-12T18:16:50.593
1You just didn't look far enough. It's around 8.45e9 ;) – Geobits – 2014-03-12T18:19:21.837
1
Some formulas are available at OEIS.
– Ypnypn – 2014-03-12T19:53:56.077a(i)=a(i-1)+a(i-3)+a(i-5)
seems like it could help.Thou shall not count to two, unless they proceed to three! :) – user1853181 – 2014-03-13T09:19:35.030
3I 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. – kojiro – 2014-03-13T13:21:59.987
const int four = 1+1+1+1; – Spook – 2014-03-14T12:14:04.230
@kojiro I left it open to interpretation so I suppose that would be a valid entry. "Outputs infinitely" implies you have infinite time to output them. But it would be difficult to demonstrate it works and unfiltered output wouldn't be obvious on its own. – Radiodef – 2014-03-14T18:27:29.130
1@squeamishossifrage Haven't watched lost, understand binary. Uh oh! – George Reith – 2014-03-15T12:34:23.180
Out of curiosity - what is the background for this particular sequence? – Thorbjørn Ravn Andersen – 2014-03-17T12:01:57.380
1@ThorbjørnRavnAndersen The numbers appear in the television show Lost. There is actually not really a whole lot more to it than that. They are a plot device and part of the lore. – Radiodef – 2014-03-18T16:31:11.793
1PHP (80chr)
$i=2;while($i){$i=$i%9==6?4:$i<<1;if($i%9==7)echo $i-1,$i,2+$i+=5;else echo $i;}
can't post answer??? – CSᵠ – 2014-03-27T16:42:57.090