12-08-2009, 18:22
|
#1
|
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
|
Programming Challenges?
Afternoon All,
I could do with getting some programming practice, and (whilst I'm at it) gaining at least a passing familiarity with a few different programming languages.
I know that there are a few sites out there that have daily/weekly/monthly programming challenges, but are there any that you would recommend?
Also, anybody got any thoughts on some little programming type tasks that might give me a little practice?
|
|
|
12-08-2009, 18:35
|
#2
|
Remoaner
Cable Forum Team
Join Date: Mar 2004
Posts: 32,719
|
Re: Programming Challenges?
What language?
I'll start with an easy one. (Don't look it up online  )
Program something that will print to console/throw an alert for every multiple of 5 and 3 between 1 and 100. For numbers that are both multiples of 3 and 5 do something special. It's a common test.
|
|
|
12-08-2009, 18:37
|
#3
|
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
|
Re: Programming Challenges?
Any language really, doesn't matter.
Will have a go at your challenge tomorrow at work, thanks for that
|
|
|
12-08-2009, 18:41
|
#4
|
Remoaner
Cable Forum Team
Join Date: Mar 2004
Posts: 32,719
|
Re: Programming Challenges?
I gonna try to do it in C# later in the shortest/most elegant way I can. I'll wack it here in spoiler tags.
|
|
|
12-08-2009, 18:46
|
#5
|
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
|
Re: Programming Challenges?
Cool, thanks.
I'll probably start with Python or something like that.
|
|
|
13-08-2009, 21:00
|
#6
|
Remoaner
Cable Forum Team
Join Date: Mar 2004
Posts: 32,719
|
Re: Programming Challenges?
|
|
|
13-08-2009, 21:13
|
#7
|
Inactive
Join Date: Jan 2007
Location: Doncaster, S. Yorks.
Age: 42
Services: TV:Sky+, BB:DRL VDSL2 40/10 with Ask4, Phone:Mobile Only
Posts: 2,320
|
Re: Programming Challenges?
You could try PERL, C-sharp (just noticed my Mac doesn't have a hash key  ) or JAVA as they seem to be popular languages lately.
|
|
|
13-08-2009, 21:13
|
#8
|
Inactive
Join Date: Jun 2003
Age: 44
Posts: 14,750
|
Re: Programming Challenges?
I did more or less the same. Just one suggestion i'd make regarding your code Damien:
|
|
|
13-08-2009, 21:19
|
#9
|
Inactive
Join Date: Mar 2007
Posts: 4,931
|
Re: Programming Challenges?
Quote:
Originally Posted by haydnwalker
(just noticed my Mac doesn't have a hash key  )
|
Alt + 3
|
|
|
13-08-2009, 21:27
|
#10
|
Inactive
Join Date: Jun 2003
Age: 44
Posts: 14,750
|
Re: Programming Challenges?
BTW the absolute classic programming challenge is to generate an array of random numbers and then sort it manually. Once you do it, then you can refine it to make it as efficient as possible.
I guarantee every programming course has that exercise.
|
|
|
13-08-2009, 21:29
|
#11
|
Remoaner
Cable Forum Team
Join Date: Mar 2004
Posts: 32,719
|
Re: Programming Challenges?
Quote:
Originally Posted by punky
I did more or less the same. Just one suggestion i'd make regarding your code Damien:
|
Opps! Miss that. Indeed.
---------- Post added at 21:29 ---------- Previous post was at 21:28 ----------
Quote:
Originally Posted by punky
BTW the absolute classic programming challenge is to generate an array of random numbers and then sort it manually. Once you do it, then you can refine it to make it as efficient as possible.
I guarantee every programming course has that exercise.
|
Let's do that one next then. An array of 10 random numbers should be fine...
I'll try tomorrow.
|
|
|
14-08-2009, 09:13
|
#12
|
Inactive
Join Date: Jan 2007
Location: Doncaster, S. Yorks.
Age: 42
Services: TV:Sky+, BB:DRL VDSL2 40/10 with Ask4, Phone:Mobile Only
Posts: 2,320
|
Re: Programming Challenges?
Quote:
Originally Posted by Ben B
Alt + 3 
|
Thanks for that!! Will be much use in the coming Mac usage years
|
|
|
14-08-2009, 10:06
|
#13
|
Inactive
Join Date: Jul 2004
Location: 127.0.0.1
Services: 50MB Virgin w/ TiVo 1TB
Posts: 1,255
|
Re: Programming Challenges?
Quote:
Originally Posted by punky
I did more or less the same. Just one suggestion i'd make regarding your code Damien:
|
I'll just point out a few things:
Int32 is actually the structure that contains "int" - so you can just as easily use 'int' or actually use an implicitly typed local variable - 'var' as it will actually pick up that your variable type is an integer.
Int32 is generally used to parse or switch another variable type into the integer type (Int32.Parse) or set the maximum or minimum value of a specified integer.
Good job with the if statements though - I like how you ignored the curly braces as they're not necessary when you only have the one line of code being executed.
However - your code will simply run through and then close when it's finished calculating all of the multiples, what you may want to do is stick
Code:
Console.ReadKey(true);
after your for loop - this will then only exit on keypress.
---------- Post added at 10:06 ---------- Previous post was at 09:54 ----------
Quote:
Originally Posted by Damien
Opps! Miss that. Indeed.
---------- Post added at 21:29 ---------- Previous post was at 21:28 ----------
Let's do that one next then. An array of 10 random numbers should be fine...
I'll try tomorrow.
|
For this, you can just use, in C#:
Code:
Array.Sort(yourArray);
but... that's cheating!
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
|
|
|
14-08-2009, 10:24
|
#14
|
Remoaner
Cable Forum Team
Join Date: Mar 2004
Posts: 32,719
|
Re: Programming Challenges?
Quote:
Originally Posted by LemonyBrainAid
Int32 is actually the structure that contains "int" - so you can just as easily use 'int' or actually use an implicitly typed local variable - 'var' as it will actually pick up that your variable type is an integer.
|
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)
Quote:
However - your code will simply run through and then close when it's finished calculating all of the multiples, what you may want to do is stick
Code:
Console.ReadKey(true);
after your for loop - this will then only exit on keypress.
|
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.
|
|
|
14-08-2009, 10:40
|
#15
|
cf.mega poser
Join Date: Jun 2003
Posts: 16,687
|
Re: Programming Challenges?
Quote:
Originally Posted by LemonyBrainAid
|
For large Ns, try quicksort.
http://en.wikipedia.org/wiki/Quicksort
__________________
Remember kids: We are blessed with a listening, caring government.
|
|
|
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
HTML code is Off
|
|
|
All times are GMT +1. The time now is 18:37.
|