PDA

View Full Version : Vomjom's first challenge


vomjom
06-16-2002, 08:11 AM
Challenge board doesn't seem to be getting anything new... so, here's something:
You have to read a series of signed integers from a file. They will range from -16 million to 16 million, so a 32-bit integer should be fine. They will be separated by new lines.
You must then sort them using quicksort and make sure your results are correct. Record the time of the quicksort (leave out the time it took to read the file). You can use a watch to time it :)
If you don't know quicksort, try a google search and look for pseudo code - it helps a lot.
The catch is: you have to program this in a language that you don't know _at all_. I suggest goo (http://www.googoogaga.org/)

Jonathan Hseu

vomjom
06-16-2002, 08:16 AM
Here's a C program that can generate random numbers:
#include <stdio.h>

int main(int argc, char *argv[])
{
int i;
int byte1, byte2, byte3;
for(i = 0; i < atoi(argv[1]); i++)
{
int byte1 = getchar();
int byte2 = getchar();
int byte3 = getchar();
printf("%d\n", byte1 | (byte2 << 8) | (byte3 << 16));
}
return 0;
}

You can run it with (make-random being the program name and 50000 being how many numbers you want):
cat /dev/urandom | ./make-random 50000 > random.txt

Use /dev/random if you want _real_ random numbers instead of pseudo random numbers.

inkedmn
06-16-2002, 02:40 PM
you were able to code that pretty fast for not knowing C _at all_ ;)

me will do it in java (since i don't know it, for all intents and purposes).

vomjom
06-16-2002, 04:09 PM
That program is only for testing your own program :)

GnuVince
06-16-2002, 08:21 PM
It seems to me that this challenge won't be popular for 2 reasons:

1. Who would want to learn a new language just for a simple challenge?
2. We've had enough sorting challenges. You can find about quicksort in Dru's second challenge.
3. One of the goal of challenges is to learn about the languages we know. In one of ink's challenges I learned how to manipulate Hash tables in O'Caml and this taught me that they should be avoided when order is needed.

Bradmont
06-16-2002, 09:11 PM
I think it's a really cool idea for a challenge. :)

kmj
06-17-2002, 11:37 AM
Originally posted by GnuVince
It seems to me that this challenge won't be popular for 2 reasons:

1. Who would want to learn a new language just for a simple challenge?


You would; admit it.


2. We've had enough sorting challenges. You can find about quicksort in Dru's second challenge.


The sorting isn't really the issue, since you know you're using quicksort


3. One of the goal of challenges is to learn about the languages we know. In one of ink's challenges I learned how to manipulate Hash tables in O'Caml and this taught me that they should be avoided when order is needed.

I think the two goals of the challenges are Learning (in general) and fun. Not just learning more about the languages you know, but learning a little about other languages. One certainly won't learn java by doing this challenge in java; but they'll get a good idea of how it works.


edit - stupid broken quote tags.

edit II - stupid me.

Strike
06-17-2002, 03:29 PM
No offense, but I don't really think I'll do this challenge either. I might give Ruby a shot with it, but other than that, I already have 20-some languages in my head bouncing around. I took a look at Goo and don't really want to learn it, so that's right out. I like learning a language because of what paradigm it suits and what things it can do better than other languages, generally.