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 12-08-2009, 18:22   #1
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
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?
Raistlin is offline   Reply With Quote
Advertisement
Old 12-08-2009, 18:35   #2
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?

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.
Damien is online now   Reply With Quote
Old 12-08-2009, 18:37   #3
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?

Any language really, doesn't matter.

Will have a go at your challenge tomorrow at work, thanks for that
Raistlin is offline   Reply With Quote
Old 12-08-2009, 18:41   #4
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?

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.
Damien is online now   Reply With Quote
Old 12-08-2009, 18:46   #5
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?

Cool, thanks.

I'll probably start with Python or something like that.
Raistlin is offline   Reply With Quote
Old 13-08-2009, 21:00   #6
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?

Spoiler: 

for (Int32 i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
if (i % 3 == 0)
Console.WriteLine(i + " is a multiple of 3");
if (i % 5 == 0)
Console.WriteLine(i + " is a multiple of 5");

}
Damien is online now   Reply With Quote
Old 13-08-2009, 21:13   #7
haydnwalker
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
haydnwalker has reached the bronze age
haydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze age
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.
haydnwalker is offline   Reply With Quote
Old 13-08-2009, 21:13   #8
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 did more or less the same. Just one suggestion i'd make regarding your code Damien:

Spoiler: 
I'd use else ifs instead of ifs otherwise you'd get unnecessary repitition.

for (Int32 i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
else if (i % 3 == 0)
Console.WriteLine(i + " is a multiple of 3");
else if (i % 5 == 0)
Console.WriteLine(i + " is a multiple of 5");

}

i.e you get:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
18 is a multiple of 3

instead of this:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
15 is a multiple of 3
15 is a multiple of 5
18 is a multiple of 3
punky is offline   Reply With Quote
Old 13-08-2009, 21:19   #9
Ben B
Inactive
 
Join Date: Mar 2007
Posts: 4,931
Ben B has a bronze arrayBen B has a bronze arrayBen B has a bronze array
Ben B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze arrayBen B has a bronze array
Re: Programming Challenges?

Quote:
Originally Posted by haydnwalker View Post
(just noticed my Mac doesn't have a hash key )
Alt + 3
Ben B is offline   Reply With Quote
Old 13-08-2009, 21:27   #10
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?

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.
punky is offline   Reply With Quote
Old 13-08-2009, 21:29   #11
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
I did more or less the same. Just one suggestion i'd make regarding your code Damien:

Spoiler: 
I'd use else ifs instead of ifs otherwise you'd get unnecessary repitition.

for (Int32 i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
else if (i % 3 == 0)
Console.WriteLine(i + " is a multiple of 3");
else if (i % 5 == 0)
Console.WriteLine(i + " is a multiple of 5");

}

i.e you get:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
18 is a multiple of 3

instead of this:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
15 is a multiple of 3
15 is a multiple of 5
18 is a multiple of 3
Opps! Miss that. Indeed.

---------- Post added at 21:29 ---------- Previous post was at 21:28 ----------

Quote:
Originally Posted by punky View Post
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.
Damien is online now   Reply With Quote
Old 14-08-2009, 09:13   #12
haydnwalker
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
haydnwalker has reached the bronze age
haydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze agehaydnwalker has reached the bronze age
Re: Programming Challenges?

Quote:
Originally Posted by Ben B View Post
Alt + 3
Thanks for that!! Will be much use in the coming Mac usage years
haydnwalker is offline   Reply With Quote
Old 14-08-2009, 10:06   #13
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 punky View Post
I did more or less the same. Just one suggestion i'd make regarding your code Damien:

Spoiler: 
I'd use else ifs instead of ifs otherwise you'd get unnecessary repitition.

for (Int32 i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
else if (i % 3 == 0)
Console.WriteLine(i + " is a multiple of 3");
else if (i % 5 == 0)
Console.WriteLine(i + " is a multiple of 5");

}

i.e you get:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
18 is a multiple of 3

instead of this:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
15 is a multiple of 3
15 is a multiple of 5
18 is a multiple of 3
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 View Post
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
LemonyBrainAid is offline   Reply With Quote
Old 14-08-2009, 10:24   #14
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 LemonyBrainAid View Post
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.
Damien is online now   Reply With Quote
Old 14-08-2009, 10:40   #15
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 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
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
__________________
Remember kids: We are blessed with a listening, caring government.
danielf 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 08:04.


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