Programming Practice
Moderator: Coders of Rage
Programming Practice
Are you new to programming? Or perhaps you're just starting off with a new language? Trying to master syntax of a scripting language you're unfamiliar with?
Well, the best way to get there is to practice. Those crappy little apps that exist simply for the sake of practice are sometimes the correct route to go.
I'm officially dedicating this topic to practice problems and solutions. Have an interesting problem that will help to focus on a specific aspect of a language? Or just a great logical problem? Feel free to post here.
Need help answering one? Want to post some you've done at work, school, etc? Go for it.
There are tons of interesting, brainfuck programs that require logic you probably won't need in daily programming. And there are others that are practically a simulation of the brain activity required to during a long night of devving.
Well, the best way to get there is to practice. Those crappy little apps that exist simply for the sake of practice are sometimes the correct route to go.
I'm officially dedicating this topic to practice problems and solutions. Have an interesting problem that will help to focus on a specific aspect of a language? Or just a great logical problem? Feel free to post here.
Need help answering one? Want to post some you've done at work, school, etc? Go for it.
There are tons of interesting, brainfuck programs that require logic you probably won't need in daily programming. And there are others that are practically a simulation of the brain activity required to during a long night of devving.
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
Re: Programming Practice
Aight, I'll start off with some, and post more when I have time (and shouldn't be studying thermodynamics).
If this topic increases, I may even edit my first post and create a problem archieve.
Problem 1: (short app)
Most common approaches to this one are iteration or recursion...So it'll probably make heavy use of looping. If you want some correct output values, I'll post them later.
The more languages this is answered in, the cooler. XD
I can do it in Java, Lua, Blitz, and C++, if anyone needs help.
If this topic increases, I may even edit my first post and create a problem archieve.
Problem 1: (short app)
Click here to see the hidden message (It might contain spoilers)
Most common approaches to this one are iteration or recursion...So it'll probably make heavy use of looping. If you want some correct output values, I'll post them later.
The more languages this is answered in, the cooler. XD
I can do it in Java, Lua, Blitz, and C++, if anyone needs help.
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
Re: Programming Practice
I might be able to do it in just basic... But I really don't want to and it probably wouldn't help anyone...
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Programming Practice
Here's an idea for the up-and-coming network programmer:
Also helps with some file I/O.
Click here to see the hidden message (It might contain spoilers)
Also helps with some file I/O.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Programming Practice
Ginto, read beej's guide to network programming linked from here http://elysianshadows.com/phpBB3/viewto ... ?f=6&t=148
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
Hey Arce,
Very nice idea of yours ... I got pretty excited about it and with how I could improve my programming with those excercises!!
I have done the "coin handler" one, it works and shows every possibility, but it is not effective I guess, since I made it divided in several functions...
So, I ask you to look at my code and see if there is a way to put those 4 functions (checkQuarter, checkDime, checkNickle, checkPenny) in only one, using recursion maybe?
Ok here goes the code... bug free until now (I have fixed 2 since my first reply here)
Very nice idea of yours ... I got pretty excited about it and with how I could improve my programming with those excercises!!
I have done the "coin handler" one, it works and shows every possibility, but it is not effective I guess, since I made it divided in several functions...
So, I ask you to look at my code and see if there is a way to put those 4 functions (checkQuarter, checkDime, checkNickle, checkPenny) in only one, using recursion maybe?
Ok here goes the code... bug free until now (I have fixed 2 since my first reply here)
Click here to see the hidden message (It might contain spoilers)
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.
Re: Programming Practice
Haha, great job! As per usua1, I'm somewhat pressed for time...But I'11 definate1y take a 1ook at your code when I can and try to come up with a recursive so1ution.
Atm, though, I'd recommend trying to use compounded, nested "for" statements to try and so1ve it? That was my origina1 approach. If you need he1p with it I'd g1ad1y paste some code snippets.
And, if you guys 1ike this type of thing, I can post tons and tons more. Just 1emme know what you want.
A1so, I've got a fu11 competitive program even that I can post as we11 as samp1e and graded test data. It was the 2nd competitive program, to be done in any 1anguage, of the 2OO9 ACS1 senior division computer science competition. If anybody here is interested (honest1y, i thought it was god-easy, but some of you may not...) I can post it and some initia1 test va1ues. Then, when you're done, I'11 give you 'rea1 va1ues' to test it with, you give me your program's output, and I'11 score ya! (x/5) =P
Atm, though, I'd recommend trying to use compounded, nested "for" statements to try and so1ve it? That was my origina1 approach. If you need he1p with it I'd g1ad1y paste some code snippets.
And, if you guys 1ike this type of thing, I can post tons and tons more. Just 1emme know what you want.
A1so, I've got a fu11 competitive program even that I can post as we11 as samp1e and graded test data. It was the 2nd competitive program, to be done in any 1anguage, of the 2OO9 ACS1 senior division computer science competition. If anybody here is interested (honest1y, i thought it was god-easy, but some of you may not...) I can post it and some initia1 test va1ues. Then, when you're done, I'11 give you 'rea1 va1ues' to test it with, you give me your program's output, and I'11 score ya! (x/5) =P
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: Programming Practice
OK I have one for yout all. Now it seems alot of programmers(experienced ones too) have problems figuring this one out.
OK so here it is
Seems easy but I know people who have been scratching their respective heads on this. When I heard of it I figured it out in like 10 seconds
EDIT: You don't have to make it recursive but bonus points if you do.
Good Luck.
OK so here it is
Click here to see the hidden message (It might contain spoilers)
Seems easy but I know people who have been scratching their respective heads on this. When I heard of it I figured it out in like 10 seconds
EDIT: You don't have to make it recursive but bonus points if you do.
Good Luck.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
I tried to work it out real quick and here is what I got
Later on, when I have more time, I will try polishing the "coin handler" code and this one too xD
Click here to see the hidden message (It might contain spoilers)
Later on, when I have more time, I will try polishing the "coin handler" code and this one too xD
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: Programming Practice
Close but there is a better solution. and its one operator(thats a clue)KuramaYoko10 wrote:I tried to work it out real quick and here is what I got
Click here to see the hidden message (It might contain spoilers)
Later on, when I have more time, I will try polishing the "coin handler" code and this one too xD
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: Programming Practice
Close but there is a better solution. and its one operator(thats a clue)KuramaYoko10 wrote:I tried to work it out real quick and here is what I got
Click here to see the hidden message (It might contain spoilers)
Later on, when I have more time, I will try polishing the "coin handler" code and this one too xD
Also think whats the lowest common denominator for both a multiple of 3 and 5.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Programming Practice
I was bored...M_D_K wrote:OK I have one for yout all. Now it seems alot of programmers(experienced ones too) have problems figuring this one out.
OK so here it is
Click here to see the hidden message (It might contain spoilers)
Seems easy but I know people who have been scratching their respective heads on this. When I heard of it I figured it out in like 10 seconds
EDIT: You don't have to make it recursive but bonus points if you do.
Good Luck.
Click here to see the hidden message (It might contain spoilers)
and what do you mean by "recursive"?
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- M_D_K
- Chaos Rift Demigod
- Posts: 1087
- Joined: Tue Oct 28, 2008 10:33 am
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/++
- Location: UK
Re: Programming Practice
6 out of 10 for that Ginto. You must work harder Not that its bad or anything.
Recursion is where a function is the algorithm and it calls itself over and over(basically). For example
Extremely basic but thats the idea of it. Look here for more info.
BTW recursion will get you 10 bonus points.
Recursion is where a function is the algorithm and it calls itself over and over(basically). For example
Code: Select all
void PlusPlus(int end, int num)
{
num++;
printf("num:%d\n", num);
if(num < end)
PlusPlus(end, plus);
};
BTW recursion will get you 10 bonus points.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Programming Practice
Can I buy a T-Shirt with the points? If so I might consider trying. Interesting problems indeed :P.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
Nice... thanks to this problem and Ginto8's answers I got to know about the modulus operator '%' and how to implement it O.o
Now, what was the grade of my first trial ?? and the grade of this trial now?? xD
Here it is:
P.S.: I dont know if this is a "recursion" but I have tried, and looking to your example now, it looks alike xD
Now, what was the grade of my first trial ?? and the grade of this trial now?? xD
Here it is:
P.S.: I dont know if this is a "recursion" but I have tried, and looking to your example now, it looks alike xD
Click here to see the hidden message (It might contain spoilers)
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.