HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free and registered users see less advertising! If you just want to browse through the existing questions, just select the forum that you want to visit from the selection below. Otherwise, click here to register!. We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Re: Should we have a small programming challenge?

Sounds like a good idea, I wish I was better at coding, but I suppose it's things like this that make you better. Seeing how other people handle the same problem different ways would be interesting too.

Re: Should we have a small programming challenge?

I see now how Bradmont figured out how to put cows in my httpd.log file. Well actually I don't since no one answered that on the thread but still... I do think that a programming challenge would be interesting. It shouldn't be language specific though. Any programmer should be able to participate. Maybe it should be something that's easy to do, but it can be done at different levels. I can't explain very well so let me give an example. A few weeks back I remember someone wrote a program that would find the factorial of a number. The challenge could be to write such a program, which most programmers could do, and the one who's finishes fastest on a given computer wins. That's just an example though.

Re: Should we have a small programming challenge?

How about a program to find every pair of factors for a gien number? And let's make the code catch as many user errors (bad input, id10t users, etc). *Do we post our code here?

I just thought: Since some people will do it with compiled languages and others with interpreted, should we seperate the comparaisons in 2? *Shortest code will probably be interpreted, but fastest will be compiled.

Re: Should we have a small programming challenge?

That could be a decent challenge. And yes, we post our code here so someone can compare all of them. This isn't for a prize or anything so I don't see any reason to be paranoid about people cheating. And yes, you do have a point about the different languages. But again, this isn't a serious contest, so we could just have different goals to go for, like both speed and user interaction. There can be a winner for each of these goals. That's my idea at least.

Re: Should we have a small programming challenge?

That could be a decent challenge. And yes, we post our code here so someone can compare all of them. This isn't for a prize or anything so I don't see any reason to be paranoid about people cheating. And yes, you do have a point about the different languages. But again, this isn't a serious contest, so we could just have different goals to go for, like both speed and user interaction. There can be a winner for each of these goals. That's my idea at least.

Here's mine:

Code:

#!/usr/bin/env ruby
# Make sure the user at least inputs something
if ARGV.size &lt; 1 then
puts &quot;Usage: factor.rb &lt;integer&gt;&quot;
exit
end
# Display an error message if the user input something else than an integer
if not /^\s*(\d*)\s*$/ === ARGV[0] then
puts &quot;Error: You must input an integer&quot;
exit
end
# Our number to factor, when to stop factoring (the square root of the number
# beyond that, it's the same but backwards) and the number of pair of factors
# found
target = ARGV[0].to_i
limit = Math.sqrt(target)
number_of_fact = 0
# The actual factoring, for every number from 1 to limit, check whether
# the division with target as no decimals, and if so, display both factors
# and add 1 to the number of pair of factors found
for i in 1 .. limit do
if (target % i == 0) then
puts &quot;#{i} and #{target/i}&quot;
number_of_fact += 1
end
end
# Display the number of factors found
puts &quot;#{number_of_fact} pairs of factors found!&quot;