Python 2.7
To answer the question, one must know the question - and the question is:
What do you get when you multiply six by nine? Thanks to TRiG for the correction
So Deep Thought relies on the handy use of base 13:
613 x 913 = 4213
We import our constants:
from random import randrange as scrabbleBag, randint
from datetime import datetime,timedelta
life,universe,everything,nothing=6,9,1,-3
endOfTheUniverse = 80
We also define our earth-things, being a bag of scrabble tiles, Arthur (a predictable albeit it slightly odd, computer of sorts), Trillian (our rational heroine),
tile = lambda i: scrabbleBag(26)
arthur = lambda i: int(`i`,life+universe+everything+nothing)
trillian = lambda i: ''.join(map(str,divmod(i,life+universe+everything+nothing)))
We introduce Zaphod - a random sort, who eventually runs out of steam as we near the endOfTheUniverse
.
zaphod = lambda : not(randint(0,(endOfTheUniverse-(datetime.now() - start).seconds)**3))
And Marvin the Paranoid Android, whose positive attitude could stop any party:
marvin = lambda : endOfTheUniverse<(datetime.now() - start).seconds
And we continue to run these 4 characters through the mix until they compute it:
while answer is not life * universe * everything:
rack = sum(tile(i) for i in range(7))
answer = (zaphod or marvin) and arthur(rack)
print trillian(answer)
The complete deepthought.py
:
from random import randrange as scrabbleBag, randint
from datetime import datetime,timedelta
life,universe,everything,nothing=6,9,1,-3
endOfTheUniverse = 80
tile = lambda i: scrabbleBag(26)
arthur = lambda i: int(`i`,life+universe+everything+nothing)
trillian = lambda i: ''.join(map(str,divmod(i,life+universe+everything+nothing)))
start = datetime.now()
zaphod = lambda: not(randint(0,(endOfTheUniverse-(datetime.now() - start).seconds)**3))
marvin = lambda: endOfTheUniverse<(datetime.now() - start).seconds
answer = None
while answer is not life * universe * everything:
rack = sum(tile(i) for i in range(7))
answer = (zaphod() or marvin()) and arthur(rack)
print trillian(answer)
This should finish somewhere around the 75 second mark, definitely finishing by 80 seconds. Sometimes earlier to to Zaphods Infinite Improbability Drive.
1You should probably ban sleep and time functions, or else the solution will just be sleep(75);print 41+1 – tecywiz121 – 2014-02-04T21:03:43.970
6This might better serve as a popularity contest to see what ways people can creatively come up with an answer rather than variations of
sleep(75);print("%d\n",41+1);
– Josh – 2014-02-04T21:04:04.610@tecywiz121 you beat me to it! – Josh – 2014-02-04T21:04:25.970
30To calculate takes approx 75 seconds? But computer chips are so varied... How can this be possible - it might take 75 seconds on my machine, but the next computer might monster it in 7.5 seconds... – Fozzedout – 2014-02-04T21:05:38.777
7Without
sleep
available the answers are going to be very hardware dependent I imagine...what takes 75s on your machine will probably take 750s on my machine :P – Josh – 2014-02-04T21:05:40.367@Fozzedout the entire script must run in 75 seconds – Fez Vrasta – 2014-02-04T21:06:13.030
@Josh Not true; for example, Java has
System.currentTimeMillis()
– Justin – 2014-02-04T21:22:59.660@Josh Agreed, this should be popularity contest. As it stands there's nothing particularly interesting about this that makes it a code golf. Not to mention that the rules aren't even particularly well defined. The only real way to guarantee time is to use some form of timer. I might be inclined to close vote – Cruncher – 2014-02-04T21:43:29.003
Sorry I'm new here, if needed I can change it to a popularity contest. edit changed. – Fez Vrasta – 2014-02-04T21:44:40.190
3http://www.timeapi.org/utc/now. This seems like the best alternative to using sleep-like libraries of your language. All this takes is a few http requests. – Cruncher – 2014-02-04T21:49:29.010
3I accidentally made mine take 10 minutes! :O – Doorknob – 2014-02-04T22:26:38.483
I have found ways to generate 42 in a funny way, but they took much much more than 75s. Making a algorithm that take approx. 75 sec is really hard. – tigrou – 2014-02-05T12:54:17.747
1if it takes 7.5 milion years I think it could be accepted as answer :P – Fez Vrasta – 2014-02-05T12:55:25.007
2Well, darn. The time thing makes the most interesting solution too simple: If we define
a=0, b=1,...z=25
, then you can sum"earth"
(and subtractlength("earth")
due to it not finishing the calculation) to get 42... – Izkata – 2014-02-05T18:01:18.127The answer to Life, the Universe, and everything =
2**5+0x15f%11
– Braden Best – 2014-02-11T01:57:14.8471Proud to be the 42nd upvote on this question :) – thnkwthprtls – 2014-03-14T16:58:07.110
The votes on this are so almost perfect... is tempted to downvote to get the vote count back to 42 – Doorknob – 2014-04-28T02:28:46.853