views:

89

answers:

2

I'm seeking a(very) short statement(in any language) that can make the CPU busy for like a second or a half. The statement should consume CPU cycles, not IO stuff.

+3  A: 

Psuedocode:

A = 2
StartTime = GetTime()
While (GetTime() - StartTime) < 1.0
  A = A * 2
graham.reeds
`A = A * 2` is unnecessary
Nick D
My flippant answer was going to be `exec Outlook.exe`. Then I realised he only wanted to keep the CPU busy for a couple of seconds not about 30!
graham.reeds
lol @graham :P haha
khelll
+1  A: 

Using java BigIntegers, you could try and implement http://en.wikipedia.org/wiki/Ackermann_function.

That'll keep you going for a while.

Erwin Smout
+1 I thought of Ackermann, but even the tightest implementation is going to be more than "a (very) short statement". Mind you, I suppose asker also says "in any language", and I bet the J / APL implementation of Ackermann is about one third of a line...
AakashM