Forum Articles
  Welcome back Join CF
You are here 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.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

Programming Challenges?
Reply
 
Thread Tools
Old 14-08-2009, 10:46   #16
LemonyBrainAid
Inactive
 
Join Date: Jul 2004
Location: 127.0.0.1
Services: 50MB Virgin w/ TiVo 1TB
Posts: 1,255
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
Re: Programming Challenges?

Quote:
Originally Posted by Damien View Post
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 View Post
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 ----------

Quote:
Originally Posted by danielf View Post
For large Ns, try quicksort.

Spoiler: 

(defun quick-sort (a-list)
(let ((pivot nil)
(lesser nil)
(greater nil))
(when a-list
(cond ((= (length a-list) 1)
(list (first a-list)))
(t
(setf pivot (first a-list))
(dolist (item (rest a-list))
(if (<= item pivot)
(push item lesser)
(push item greater)))
(append (quick-sort lesser) (list pivot) (quick-sort greater))
)))))


http://en.wikipedia.org/wiki/Quicksort
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.
LemonyBrainAid is offline   Reply With Quote
Advertisement
Old 14-08-2009, 10:48   #17
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,719
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Quote:
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.
Yeah Sorry. C# 3.0. Either way, The latest release.
Damien is offline   Reply With Quote
Old 14-08-2009, 10:51   #18
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Programming Challenges?

Quote:
Originally Posted by LemonyBrainAid View Post
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 View Post
Try coding the divisibility test without using the "%" operator.
Excellent idea for test #3.

BTW remember my post on this before: http://www.cableforum.co.uk/board/34528914-post11.html
punky is offline   Reply With Quote
Old 14-08-2009, 10:54   #19
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,719
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Quote:
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.
Damien is offline   Reply With Quote
Old 14-08-2009, 11:02   #20
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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
Raistlin is offline   Reply With Quote
Old 14-08-2009, 11:05   #21
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,719
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Quote:
Originally Posted by Rob M View Post
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?)
  • Elegance (Is it frakking Cool?)
  • Do they Support Spurs (Automatic Point Deduction)
Damien is offline   Reply With Quote
Old 14-08-2009, 11:13   #22
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Programming Challenges?

As I have my code I might as well post it now. I've not beautified or robustified it yet:

Creating the initial random array:

Spoiler: 
Code:
            
            int[] unsorted = new int[10];
            Random random = new Random();

            for (int i = 0; i < 10; i++)
            {
                unsorted[i] = random.Next(0, 10);
            }


The way I did it at university and how it initially last night:

Spoiler: 
Code:
            int[] sorted = new int[10];
            int temp = 99;
            int loc = 0;


            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (unsorted[j] < temp) 
                    { 
                        temp = unsorted[j]; 
                        loc = j;
                    }
                }
                sorted[i] = temp;
                unsorted[loc] = 99;
                temp = 99;
            }


And my bubble sort:

Spoiler: 
Code:
            int[] sorted = (int[])unsorted.Clone();
            Boolean swapped;
            int temp = 0;
            int i = 0;

            do
            {
                swapped = false;
                i = 0;
                while (!swapped && i < 10 - 1)
                {

                    if (sorted[i] > sorted[i + 1])
                    {
                        temp = sorted[i];
                        sorted[i] = sorted[i + 1];
                        sorted[i + 1] = temp;
                        swapped = true;
                    }
                    else
                    {
                        i++;
                    }
                }

            } while (swapped);


---------- Post added at 11:13 ---------- Previous post was at 11:08 ----------

Quote:
Originally Posted by Damien View Post
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?)
That's decent criteria. We could also get an experienced developer to act as a judge but maybe rotate the position so everyone gets a go.
punky is offline   Reply With Quote
Old 14-08-2009, 11:15   #23
LemonyBrainAid
Inactive
 
Join Date: Jul 2004
Location: 127.0.0.1
Services: 50MB Virgin w/ TiVo 1TB
Posts: 1,255
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
Re: Programming Challenges?

Quote:
Originally Posted by Rob M View Post
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:

  1. 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.
  2. 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
  3. 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.
  4. 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!
LemonyBrainAid is offline   Reply With Quote
Old 14-08-2009, 11:23   #24
danielf
cf.mega poser
 
danielf's Avatar
 
Join Date: Jun 2003
Posts: 16,687
danielf has a golden auradanielf has a golden auradanielf has a golden aura
danielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden auradanielf has a golden aura
Re: Programming Challenges?

Quote:
Originally Posted by Damien View Post
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.
danielf is offline   Reply With Quote
Old 14-08-2009, 11:25   #25
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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.
Raistlin is offline   Reply With Quote
Old 14-08-2009, 11:31   #26
LemonyBrainAid
Inactive
 
Join Date: Jul 2004
Location: 127.0.0.1
Services: 50MB Virgin w/ TiVo 1TB
Posts: 1,255
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
LemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze arrayLemonyBrainAid has a bronze array
Re: Programming Challenges?

Quote:
Originally Posted by Rob M View Post
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.
LemonyBrainAid is offline   Reply With Quote
Old 14-08-2009, 11:43   #27
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,719
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

We should:

  • 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.
Damien is offline   Reply With Quote
Old 14-08-2009, 12:14   #28
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Programming Challenges?

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.
punky is offline   Reply With Quote
Old 14-08-2009, 12:21   #29
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,719
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Quote:
Originally Posted by punky View Post
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.
Damien is offline   Reply With Quote
Old 14-08-2009, 16:02   #30
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Programming Challenges?

I've had a bash at the modulus one:

Spoiler: 

Code:
        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
punky is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:41.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum