Tomorrow I am asking my Computer Science & Engineering students to solve this small programming problem:
Write a function in C which returns a random integer between 1 and 20. One extremely important caracteristic of the function is that it must return a different integer each time it is called. This, obviously, implies that it can only be called twenty times.
There is a second part (and in my opinion it is the coolest part):
Write the same function using a more modern programming language (e.g. Ruby).
Care to give this a go?
(Image courtesy of Sega Japan)
thxs to this quiz im motivated to do some programing again after some months of rest :D
need to try the cool part now…
Indeed Ruby seems very nice & Cool
was playing with http://tryruby.hobix.com/
dwl just completed
need to learn how to use it in class now…
mone deza try sa… li interessant..mais ti tro paresse pu contigne learn Ruby la :P lol
How old are you?
De nos jours, nous avons tendance ÃƒÂ dire Ã‚Â« La paresse est une vertu Ã‚Â» au dÃ©pend de Ã‚Â« La paresse est la mÃƒÂ¨re de tout les vices Ã‚Â» lol ;-)
…du moins cÃ¢â‚¬â„¢est ce que je pense :D
Quote somewhere : Ã‚Â« Comme la paresse est une vertu en informatique et que… Ã‚Â»
On ne peut donc que de sÃ¢â‚¬â„¢en rÃ©jouir :)
Anyone has written something cool?
Ketwaroo D. Yaasir says
wait. different from the previous number returned only. or different from all the the numbers ever returned.
If the first, any random number from 1-20 will do
but for the second, we’ll need to keep track of all numbers returned.
off topic. i got this up and running: http://blog.nbnakama.com/ it still reeks of new…
Different from all the numbers ever returned of course :-)
the only difficult part is to write a program in O(1) :s
is it a good thing that i put the code on my blog??
You are free to put YOUR program anywhere you like ;-)
The program in o(1) was also pretty simple.(check my blog for my code)
Still,I,m trying to enhance further without using the rand() funtion but still using the same algorithm(That should be interesting)
Congratulations Adarsh. Your algorithm works really well. Have you had a look at the metaprogramming part?
I am working on that but not yet finished(just started).However,I’ve finishing modifying the previous version i.e not using the rand() function to generate random number but still using the same algorithm.
I’ve already posted the new version.