Skip to main content
1 of 3
gmatht
  • 686
  • 4
  • 8

Produce the number 2014 without any numbers in your source code

Bash - 10

OK, these may not be the best solutions, but perhaps they are at least stupid in amusing ways.

cat /*/ur*

Does it generate 2014?

$ time bash -c "cat /*/ur*|grep -o 2014|head -n1"
Binary file (standard input) matches

real    0m3.005s

Apparently it does. Normally dumping /dev/urandom would be way too slow, but 2014 only requires testing about 4 billion possibilities, which is nothing to an i7! On my machine cat /*/*, du / and apt also work. It could have been an answer before the clarification that trailing junk wasn't allowed. Alas it is not, so instead I do:

date +%H%M

The question very specifically states that I can not depend on 2014 being the current year. The legal principle "The exception proves the rule" means that that the general rule is that using date is fine. So I deduce that I may rely on it being 8:14pm in my timezone. It will work just as well in (exactly) a years time. Of course in a years time you could also run:

date +%Y --date=last\ year

That does not depend on it being 2014, instead it depends on it not being 2014. Indeed, it will begin to work the precise moment it stops being 2014. As programmers we know order of operators is important this answer does not violate the rules. This is about as close as I can get to breaking the rules without technically breaking them.

gmatht
  • 686
  • 4
  • 8