![]() |
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? |
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. |
Re: Programming Challenges?
Any language really, doesn't matter.
Will have a go at your challenge tomorrow at work, thanks for that :tu: |
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.
|
Re: Programming Challenges?
Cool, thanks.
I'll probably start with Python or something like that. |
Re: Programming Challenges?
Spoiler:
|
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.
|
Re: Programming Challenges?
I did more or less the same. Just one suggestion i'd make regarding your code Damien:
Spoiler:
|
Re: Programming Challenges?
Quote:
|
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. |
Re: Programming Challenges?
Quote:
---------- Post added at 21:29 ---------- Previous post was at 21:28 ---------- Quote:
I'll try tomorrow. |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
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); ---------- Post added at 10:06 ---------- Previous post was at 09:54 ---------- Quote:
For this, you can just use, in C#: Code:
Array.Sort(yourArray); 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 |
Re: Programming Challenges?
Quote:
Quote:
|
Re: Programming Challenges?
Quote:
Spoiler:
http://en.wikipedia.org/wiki/Quicksort |
Re: Programming Challenges?
Quote:
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:
---------- Post added at 10:46 ---------- Previous post was at 10:44 ---------- Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
Quote:
BTW remember my post on this before: http://www.cableforum.co.uk/board/34528914-post11.html |
Re: Programming Challenges?
Quote:
|
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 :) |
Re: Programming Challenges?
Quote:
I mean the following requirements are all important:
|
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:
The way I did it at university and how it initially last night: Spoiler:
And my bubble sort: Spoiler:
---------- Post added at 11:13 ---------- Previous post was at 11:08 ---------- Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
|
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 :LOL:), but fear it could be complicated to organise and judge. |
Re: Programming Challenges?
Quote:
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. |
Re: Programming Challenges?
We should:
|
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.
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
I've had a bash at the modulus one:
Spoiler:
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 :p: |
Re: Programming Challenges?
Here's an interesting one, well I think it's interesting if only from a counter-intuitive statistical perspective.
The 'Monty Hall problem'. Today's challenge (if you're interested) is to implement the conditions: there's a Ferrari hidden randomly behind one of 3 doors, and a goat behind the other two. You want the Ferrari. You choose one door, and the host then eliminates one of the goats (the host knows where the Ferrari is). So now there's two choices left. The statistical conundrum is: should you stick with your choice or change to the other door? Which one has the best odds? Run the program in both conditions (switch/no switch) for a decent number of trials, and record the probabilities of getting the car. You'll be surprised. BTW: I've done this one before, and it really is quite simple. My code is about 30 lines, but a third of that is variable declaration and printing. It prints "Hello World" as well... :) |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
When I were't lad.........
My first programming language in 1980 was IBM Mainframe Assembler, with 2, 4, and 6 byte instructions, and if you weren't careful, you could overwrite the instruction, which would result in "interesting" outputs (and the code was input in punch cards.....). |
Re: Programming Challenges?
Quote:
---------- Post added at 06:39 ---------- Previous post was at 06:37 ---------- Quote:
I like perl, it's useful for writing code that looks like characters from comics when they swear. |
Re: Programming Challenges?
Well when I started in the 1980's I was writing code on ICL Mainframes using COBOL. Can't beat that language.....
|
Re: Programming Challenges?
My java version of the 3&5 divisor in one line (ignoring all the usual boilerplate java
Spoiler:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
I can answer that question if it will help anybody with the code? :D |
Re: Programming Challenges?
Quote:
I should really do the sorting challenge and the Monty Hall Problem one. (P.S It's a pretty famous one, you always change). If you program all week it's tiring :P |
Re: Programming Challenges?
Apologies for the lack of indentation but I couldn't get it to look right. Anyway, here's my effort -
Spoiler:
|
Re: Programming Challenges?
Quote:
Quote:
|
Re: Programming Challenges?
Quick and dirty 3 and 5 divisibility test in vbscript
Spoiler:
|
Re: Programming Challenges?
Excel vba.
Spoiler:
|
Re: Programming Challenges?
I've added spoiler tags to the last two just to maintain the convention and so as not to spoil the fun for anybody else that's playing along :)
|
Re: Programming Challenges?
Cool ... I didn't know how to do them! :)
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Monty Hall Problem:
Spoiler:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
If someone wants to add lines they can easily add them. It's just personal choice. Neither is better than the other. |
Re: Programming Challenges?
Doesn't anybody comment their code any more :erm: :D :D
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
Liked your shortcut for resetting the list. However, i dont think the code works the way it should for the case when the contestant changes their choice. Quote:
I suspect this will give results of 33% and 50% in your output which is not the correct answer. |
Re: Programming Challenges?
Quote:
Quote:
|
Re: Programming Challenges?
Quote:
Wait just figured it out. Tis Wrong. ---------- Post added at 21:39 ---------- Previous post was at 21:00 ---------- The CORRECT Answer: Spoiler:
Didn't change: 33.5% chance of winning Did Change: 66.78% chance of winning Also got to remove the nasty loop adding/removing. Bonus points for spotting the Beatles reference. |
Re: Programming Challenges?
Quote:
Though that said they also say you should avoid the compound if statement because some programmers find it hard to understand - my opinion is if you can't understand it then you shouldn't be a programmer... |
Re: Programming Challenges?
Quote:
Code:
if (ProductType == ProductType.Software) Code:
if (ProductType == ProductType.Software) |
Re: Programming Challenges?
I tend to prefer
Code:
if (this == whatever) { |
Re: Programming Challenges?
Here's my Monty Hall. It's in LISP again, but nobody speaks LISP :(
Spoiler:
|
Re: Programming Challenges?
What the hell is THAT language!!:confused:
|
Re: Programming Challenges?
Quote:
Seriously though, still thinking about the format - gonna sit and take a look at it today :) |
Re: Programming Challenges?
Quote:
ah..... lisp.....next thing we know we'll have code in Occam and Prolog ---------- Post added at 07:27 ---------- Previous post was at 07:25 ---------- Quote:
well, again, Sun coding standards say that you should do : Code:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Probably better ways to do it.
Spoiler:
|
Re: Programming Challenges?
Quote:
Anyway, they're both essentially hacked versions of C... |
Re: Programming Challenges?
I think hacked is a unfair description..
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
C#:
Spoiler:
VB.NET: Spoiler:
PHP: Spoiler:
BASIC: (Not actually 100% this works, hah!) Spoiler:
|
Re: Programming Challenges?
We need another challenge, of the Monty Hall Type...
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
BTW, Here's my attempt at the Monty Hall solution. I did via Object-Orientated programming, but its probably a bit more cumbersome than Damien's attempt. Still at least its good simple intro it using it as most of the important base principals are used. Its not pure OO though but thereabouts
Spoiler:
I'll have a go at the mortgage calculator tonight probably. |
Re: Programming Challenges?
Nice Punky. It's only not 'proper' OO because it's limited in scope (i.e the project is too small) to use many features. OO becomes more central to your application structure in bigger applications anyway. I mean all you can do is make door an object really...(which you did, smart).
You probably know this but when accessing a variable outside of it's containing class you should make it a property.. |
Re: Programming Challenges?
Got this so far, it appears to work...
Spoiler:
|
Re: Programming Challenges?
Before we move on too far here's my attempts at the previous challenges
Both are VB.net console Apps. Mutliples of 3 and 5 without using any type of Modulus functions: Spoiler:
And a quick and dirty way of calculating the Monty Hall probabilities (with thanks to Damien for coding tips) Spoiler:
|
Re: Programming Challenges?
Quote:
Here's the Door class with proper encapsulation (I would normally prefix private class variables with _ (like _doorNumber) but that's just convention) Spoiler:
I tend to find because I use OO a lot now that unless something is really small (i.e. an algorithm rather than a game) that I start building it in OO first and then scaling back if it really gets unnecessary. BTW the point being of all that is that you can control what comes in and out of the class. For example for the prize, I can make sure its one of x pre-determined prizes, that a door number is greater than 0, etc. |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Here's my mortgage length calculator:
Spoiler:
|
Re: Programming Challenges?
Here's my mortgage calculator, using recursion
Spoiler:
How do you get indentation in the code? My code is indented when I paste it, but I lose indentation in the spoiler tags. Even spaces don't stick... |
Re: Programming Challenges?
I did wonder about recursion...
Spoiler:
I'm still sure there must be an equation for it rather than just iterating through. |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
Try wrapping the code in [Code][/Code] tags inside the [Spoiler][/Spoiler] tags. i.e. [Spoiler][Code] ..... ...... [/Code][/Spoiler] or similar. Can anyone tell me how to stop my code appearing in colour when I Copy from the standard VB 2005 Express Editor and Paste in here ?? like this: Code:
PrivateSub StopTheseColours() |
Re: Programming Challenges?
Paste into Notepad first?
Or, highlight the pasted text and set the font color to black? |
Re: Programming Challenges?
I did it simply but the results where wrong. I thought interest was a set % amount of the total balance. I take it you need to apply it per month instead?
|
Re: Programming Challenges?
Quote:
Mine calculates on the yearly balance, however. |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
Spoiler:
|
Re: Programming Challenges?
Quote:
Thanks for answering :). I'd already used the Paste to Notepad route which works but unfortunately strips out blank lines between code lines, which means you have to edit the code in Notepad to double every blank line. Changing the Font colour is a nice thought, but the coloured code in here is also broken code. Spaces between keywords are stripped and the indentation is also stripped. Guess I'm just looking for the laziest way of doing it (as usual, lol). |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
That does the trick. Many thanks. Never noticed the stuff in the top right before. Must be old age :o: |
Re: Programming Challenges?
When I was learning C in the 80's, I used to write programs to prove or disprove if a number is prime. Specifically the Lucas Lehmer test.
Easy to do in C. Re-writing in 8051 assembler will make you a real programmer. Moreso if you then re-write code to get your graphics card to do it using ultrafast VRAM. Dissassembling programs is also good practise. Compile a program to multiply two numbers, go and look at the generated code and try to work out what's going on. I personally always find assembly programming more challenging. Getting a floating point divide to work is easy. Not in 128bytes of stack in 512bytes of reserved code space it isn't. |
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
|
Re: Programming Challenges?
Quote:
For example the optimisations we were doing on Month Hall would have no noticeable effect, if you were doing a website and sending too much kb to the client it would be very notable. |
Re: Programming Challenges?
What's wrong with this c code?
Code:
#include <stdio.h> ---------- Post added at 10:19 ---------- Previous post was at 10:10 ---------- NVM - nothing wrong with the code, something wrong with Ubuntu. It doesn't include the standard libraries as part of the install, which means that the code above won't compile. Sorted now. |
Re: Programming Challenges?
This may be a good place to ask this question which is probably too simples to have a thread of it's very own. Working on upgrading our current flat db to a more complex relational db in order to speed things up both in use and data entry. This bit of code is the index of dates.
I have 2 tables - courses and dates and each course can be associated with many dates. This went well till a 4th date was added now I get an error. Quote:
Can anyone explain what I'm doing wrong? Code:
<?php |
Re: Programming Challenges?
I remember what heero was saying about microprogramming, so I thought this was worth posting. Its an IP stack (sort of) that fits inside a Twitter tweet.
http://www.sics.se/~adam/twip.html Code:
char b[140];unsigned short *s=b;*l=b;t;main(){while(1){read(0,b,140);b[20]=0;s[11]+=8;t=l[4];l[4]=l[3];l[3]=t;write(1,b,140);}} |
Re: Programming Challenges?
Bit of a bump, I stumbled on a great programming blog today (well judgng by the latest few articles anyway)
http://cafe.elharo.com/ Its aimed at experienced programmers but novice ones can learn a lot from those more experienced. |
Re: Programming Challenges?
Try Perl, nice easy and big following. Head over to Perlmonks for support, help and Perl chat.
|
All times are GMT +1. The time now is 03:40. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum