Is LinkedIn perfect for grown ups? My books on LibraryThing
2007 03 01

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)

Popularity: 1% [?]

Add comments

written by avinash

14 Responses to “Programming Quiz #1”

  1. Splash says:

    thxs to this quiz im motivated to do some programing again after some months of rest :D

    need to try the cool part now…

  2. Splash says:

    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…

  3. al says:

    http://tryruby.hobix.com/

    mone deza try sa… li interessant..mais ti tro paresse pu contigne learn Ruby la :P lol

  4. avinash says:

    Paresse?

    How old are you?

  5. flyjason says:

    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 :)

  6. avinash says:

    Anyone has written something cool?

  7. Ketwaroo D. Yaasir says:

    One extremely important caracteristic of the function is that it must return a different integer each time it is called

    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…

  8. avinash says:

    Different from all the numbers ever returned of course :-)

  9. Sundeep says:

    pretty simple…
    the only difficult part is to write a program in O(1) :s

  10. Sundeep says:

    is it a good thing that i put the code on my blog??

  11. avinash says:

    Hi Sundeep,

    You are free to put YOUR program anywhere you like ;-)

  12. Adarsh says:

    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)

  13. avinash says:

    Congratulations Adarsh. Your algorithm works really well. Have you had a look at the metaprogramming part?

  14. Adarsh says:

    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.

Leave a Reply