You are here: Home | Forum | Programming Challenges?
You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.
I prefer using Int32 because I prefer the highlighting in Visual Studio for it . As for var, there is little point in this case because I know the type of the variable, for the sake of clear code it is easier to explicitly declare it. Anyone reading the code will be very clear on what data type this is. (Also, Not everyone uses C# 3.5, which introduced Implicitly typed variables)
At the end of the day, it's your code, your choice, this is just how I've been taught by SAMS, Microsoft and tutorials across the web
The main advantage of using var is that unlike VB, it doesn't mean 'Variant' - CSC actually determines the most appropriate type for it based on your code - meaning less error margin. (i.e. say I used an integer then later in the code parsed values of over 2,147,483,648, it would auto assign it to be a double)
And I think you're getting your version numbers mixed, .NET 3.0 introduced C# 3.0 and .NET 3.5 is the most current version.
Quote:
Originally Posted by Damien
My example was writing to a String Builder which had a debug at the end. I changed it to console at the end. Probably should have added that.
That's fair enough
---------- Post added at 10:46 ---------- Previous post was at 10:44 ----------
Yeah - I chose Bubble Sort because from the basic programming challenges that were requested it's one of the simplest algorithms to use. By far not the fastest, but simple and easy to understand.
Seeing as you're only using 10 random numbers, I suggest you actually create your own code for a bubble sort algorithm - http://en.wikipedia.org/wiki/Bubble_sort
I remember doing a bubble sort at university. Its very inefficient. The way I did it at university (and last night) was on usually about twice as efficient. I did it both ways for fun last night anyway. I'll post both later if people want.
Quote:
Originally Posted by heero_yuy
Try coding the divisibility test without using the "%" operator.
I remember doing a bubble sort at university. Its very inefficient. The way I did it at university (and last night) was on usually about twice as efficient. I did it both ways for fun last night anyway. I'll post both later if people want.
We should probably decide on the size of the array and measure the performance for each different implementation.
Services: Depends on the person and the price they're offering
Posts: 12,384
Re: Programming Challenges?
Keep these coming guys, they're really helping my enthusiasm
Have to confess that I'm starting small and just going through the basics with some course materials that I've got to get myself back up to speed - I haven't even tried the challenges that you're posting above
I'm tempted to suggest a monthly coding challenge, but I'm not sure how we would judge who the winner was (there are so many 'correct' answers to these sorts of things.....answers on a postcard please
I'm tempted to suggest a monthly coding challenge, but I'm not sure how we would judge who the winner was (there are so many 'correct' answers to these sorts of things.....answers on a postcard please
Could either have a vote, or simply just get feedback from other people.
I mean the following requirements are all important:
Readability (Can I understand it?)
Performance (How quick is it compared to other implementations?)
Keep these coming guys, they're really helping my enthusiasm
Have to confess that I'm starting small and just going through the basics with some course materials that I've got to get myself back up to speed - I haven't even tried the challenges that you're posting above
I'm tempted to suggest a monthly coding challenge, but I'm not sure how we would judge who the winner was (there are so many 'correct' answers to these sorts of things.....answers on a postcard please
This sounds like a great idea and I like the ideas that Damien outlined, here are a few other suggestions:
Some people think code is the best if it can get the job done in the least amount of lines - this isn't always the case, so that's not a great one.
Elegance is one I really like - if it's a new piece of code - using cutting edge technology such as LINQ in C# - then that's great and should be given more marks. Other examples: Boo, Spark, etc
Voting would be a good idea - Perhaps having a programming challenge and then also giving the permission to expand on some previous code or develop new, intuitive ideas for it.
Perhaps having a beginner, intermediate and advanced classes for the challenge would be a good one?
Seems like we actually have a nice number of developers on CF, this could turn out quite nicely!
Could either have a vote, or simply just get feedback from other people.
I mean the following requirements are all important:
Readability (Can I understand it?)
Performance (How quick is it compared to other implementations?)
Elegance (Is it frakking Cool?)
Do they Support Spurs (Automatic Point Deduction)
Those are decent criteria, but the problem with the first one is that we may not all be using the same language (My quick-sort was in LISP; I don't do C). The second is best judged by runnning the different implementations on one machine, which again might cause compatibility issues. Three is cool. Four: what's Spurs?
__________________
Remember kids: We are blessed with a listening, caring government.
Services: Depends on the person and the price they're offering
Posts: 12,384
Re: Programming Challenges?
Ok, this thread appears to be deviating somewhat from my original intention, but that's cool as I think it's moving in an interesting direction.
With regards to the 'judging' how about if it were up to the person that set the task for that month to decide on the winner? Obviously they wouldn't be able to take part in their own task, but that's not always a bad thing..... A poll would be another good option, peer review is always a good way of telling how well you're doing. Given that a poll can be added to a thread at any time this could be added after a specified time has passed and then people just vote on the submissions (also saves cluttering everything up with loads of threads). Once the voting's over and the winners announced we could then allow alternative solutions, or discussions of the solutions that have been posted.
On that note, how would the submissions be handled? If they were posted up as people put them in using the [spoiler][/spoiler] tags then other people could potentially copy the entries.
Also, there's the issue of people submitting stuff that isn't actually their work.
I like the idea of multiple classes (might give me a chance of winning something ), but fear it could be complicated to organise and judge.
Ok, this thread appears to be deviating somewhat from my original intention, but that's cool as I think it's moving in an interesting direction.
With regards to the 'judging' how about if it were up to the person that set the task for that month to decide on the winner? Obviously they wouldn't be able to take part in their own task, but that's not always a bad thing..... A poll would be another good option, peer review is always a good way of telling how well you're doing. Given that a poll can be added to a thread at any time this could be added after a specified time has passed and then people just vote on the submissions (also saves cluttering everything up with loads of threads). Once the voting's over and the winners announced we could then allow alternative solutions, or discussions of the solutions that have been posted.
On that note, how would the submissions be handled? If they were posted up as people put them in using the [spoiler][/spoiler] tags then other people could potentially copy the entries.
Also, there's the issue of people submitting stuff that isn't actually their work.
I like the idea of multiple classes (might give me a chance of winning something ), but fear it could be complicated to organise and judge.
Submissions could be PM'd to the judge or a neutral member. Multiple classes wouldn't be too hard and we could simply have one experienced developer judge them all, or voting.
You're never going to get around the submitting other people's work, but you can however tell if they've entered a beginner contest, they aren't going to be able to push out the same standard as advanced, if we go with that idea.
Instead of 3 levels just have two. Beginner and Advanced. The Same Judge for both?
Guest Judges who set and judge the competition. A Judge must provide feedback on their decision process. A Calendar Month to do the code, 10 days for judging while the next judge starts the next one.
Maybe:
Contest will be to create something practical? A combination of elements rather than a quick puzzle? Mostly because programming is a combination of skills in which a quick puzzle is but one.
TBH this competition thing should only be a bit of fun away. I'd only be interested in doing it casually, if it gets too regimented then it might not be worth it. We can't turn this into Google's Summer Of Code or something.
TBH this competition thing should only be a bit of fun away. I'd only be interested in doing it casually, if it gets too regimented then it might not be worth it. We can't turn this into Google's Summer Of Code or something.
Well a Judge sets the two competitions and judges them. It will be akin to the Photo contents.
static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
if (Modulus(i, 3) == 0 && Modulus(i, 5) == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
else if (Modulus(i, 3) == 0)
Console.WriteLine(i + " is a multiple of 3");
else if (Modulus(i, 5) == 0)
Console.WriteLine(i + " is a multiple of 5");
else
Console.WriteLine(i + " is not a multiple of 3 (remainder " + Modulus(i, 3) + ") or a multiple of 5 (remainder " + Modulus(i, 5) + ")");
}
Console.In.ReadLine();
}
public static int Modulus(int num, int divisor)
{
while (num > divisor)
{
num -= divisor;
}
if (num == divisor)
num = 0;
return num;
}
Which produces:
1 is not a multiple of 3 (remainder 1) or a multiple of 5 (remainder 1)
2 is not a multiple of 3 (remainder 2) or a multiple of 5 (remainder 2)
3 is a multiple of 3
4 is not a multiple of 3 (remainder 1) or a multiple of 5 (remainder 4)
5 is a multiple of 5
6 is a multiple of 3
7 is not a multiple of 3 (remainder 1) or a multiple of 5 (remainder 2)
8 is not a multiple of 3 (remainder 2) or a multiple of 5 (remainder 3)
9 is a multiple of 3
10 is a multiple of 5
11 is not a multiple of 3 (remainder 2) or a multiple of 5 (remainder 1)
12 is a multiple of 3
13 is not a multiple of 3 (remainder 1) or a multiple of 5 (remainder 3)
14 is not a multiple of 3 (remainder 2) or a multiple of 5 (remainder 4)
15 is a multiple of both 3 AND 5!
...
Speaking of operators, in some OO (Object-Orrientated) languages like C# and Java you can actually overload operators (re-code them to do some different). I had to do this in university once - write a Matrix class (a matrix is like a grid/table of values) including defining the + - * / operations for them.
So there's another good educational challenge if someone wants. Don't complain, you're getting a programming degree for free in thread