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
2010-07-14 09:44:39
`A = A * 2` is unnecessary
Nick D
2010-07-14 09:49:35
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
2010-07-14 10:01:33
lol @graham :P haha
khelll
2010-07-14 10:21:14
+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
2010-07-14 09:52:09
+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
2010-07-14 10:11:53