Programming Practice
Moderator: Coders of Rage
- 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
Your first attempt was a total fail
It printed "FooBar" before 1 and your app stopped at 99 which is an off by one error. This make it a fail.
You second attempt much better you successfully did a recursive version and no off by one error. So 10 points for the recursive and I gonna assume that you also fixed the for loop version so total 18
Also other scores:
BOMERMAN: 16 points did both the for loop version and recursive gained the full 16.
MakazeGamer: 20 points and beat BOMBERMAN to completion.
M_D_K(thats me): 30 points since I made the challenge
OMFG EDIT!!!!2 BOMERMAN has 16 points total.
It printed "FooBar" before 1 and your app stopped at 99 which is an off by one error. This make it a fail.
You second attempt much better you successfully did a recursive version and no off by one error. So 10 points for the recursive and I gonna assume that you also fixed the for loop version so total 18
Also other scores:
BOMERMAN: 16 points did both the for loop version and recursive gained the full 16.
MakazeGamer: 20 points and beat BOMBERMAN to completion.
M_D_K(thats me): 30 points since I made the challenge
OMFG EDIT!!!!2 BOMERMAN has 16 points total.
Last edited by M_D_K on Thu Feb 12, 2009 5:16 pm, edited 2 times in total.
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
M_D_K wrote:Your first attempt was a total fail
It printed "FooBar" before 1 and your app stopped at 99 which is an off by one error. This make it a fail.
You second attempt much better you successfully did a recursive version and no off by one error. So 10 points for the recursive and I gonna assume that you also fixed the for loop version so total 18
Also other scores:
BOMERMAN: 20 points did both the for loop version and recursive gained the full 20.
MakazeGamer: 20 points and beat BOMBERMAN to completion.
M_D_K(thats me): 30 points since I made the challenge
Nice... I am happy I got better and a 18 out of 20!!
However I dont see those two errors in the first program attempt... I copied and paste the code I posted here in the forum and I got it all right - starting on 1 , and finishing on Bar (100 is a multiple of 5)!!
lol but it is ok... send more challenges =D
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
Sparda: 19 out of 20. So close but no cookie for you sparda.
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
OK then, with recursion:
Click here to see the hidden message (It might contain spoilers)
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
Umm you did pretty bad. riddle me this batman do you ever see a foobar in your output? I doubt it. Since you put it at the bottom of an else if chain. no bonus points for youGinto8 wrote: OK then, with recursion:
Click here to see the hidden message (It might contain spoilers)
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.
Re: Programming Practice
MDK, i did yours since it's simple and easy...For those of you who're having trouble with it, I'd recommend acquainting yourselves with the modulus operator (% in most languages). It's very useful, and I use it several times in the editor.
Also, has nobody else been able to do the coin one? I wasn't very specific, but what I wanted was this output:
Anyone want to try it? Doing it iteratively really presses your brain with compound loops, haha.
Click here to see the hidden message (It might contain spoilers)
Also, has nobody else been able to do the coin one? I wasn't very specific, but what I wanted was this output:
For every correct combination of change to create the given amount. I'm NOT testing for efficiency, and no huge numbers will be tested. Again, I have some sample outputs if you need them...10 cents = 0 quarters + 0 dimes + 0 nick1es + 1O pennies
10 cents = 0 quarters + 0 dimes + 1 nick1es + 5 pennies
10 cents = 0 quarters + 0 dimes + 2 nick1es + O pennies
10 cents = 0 quarters + 1 dimes + 0 nick1es + O pennies
Anyone want to try it? Doing it iteratively really presses your brain with compound loops, haha.
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
Hey Arce.. have you tried my code yet?? ... it is there on the first page!!
BTW, can you pm me your solution for the coin problem written in C/C++ ??
thanks in advance
BTW, can you pm me your solution for the coin problem written in C/C++ ??
thanks in advance
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.
Re: Programming Practice
I'11 give your code a try nexttime I'm at schoo1. Current1y don't have a C++ dev environment setup! (working on it right now). Uninsta11ed my i11egit MVC++ too1s in favor of freeware so1utions (in the event that I create something worthwhi1e and don't want to get sued...)
Current1y have Jcreator for java and will upgrade to NetBeans when I get time. Will likely give codeblocks another try, or *shudder*Bloodshed DevC++...If I don't like either, I may revert to my legit MVC++ 6 (outdated, but I liked it...)
Current1y have Jcreator for java and will upgrade to NetBeans when I get time. Will likely give codeblocks another try, or *shudder*Bloodshed DevC++...If I don't like either, I may revert to my legit MVC++ 6 (outdated, but I liked it...)
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
Re: Programming Practice
Here's my attempt at M_D_K's challenge.
Since I have already seen all the other solutions I tried to solve it using a different approach.
- Not using % operator.
- No special code to print foobar when the number is a multiple of 3 and 5.
Since I have already seen all the other solutions I tried to solve it using a different approach.
- Not using % operator.
- No special code to print foobar when the number is a multiple of 3 and 5.
Click here to see the hidden message (It might contain spoilers)
177
-
- Chaos Rift Junior
- Posts: 209
- Joined: Thu Feb 12, 2009 8:46 pm
Re: Programming Practice
I'm not that content with my code for a dirth of eloquence, but here's my solution to the coin handling problem in Java using nested for loops:
I'd like to have a go at this using recursion tomorrow.
I'd also like to see yours, Arce.
Click here to see the hidden message (It might contain spoilers)
I'd like to have a go at this using recursion tomorrow.
I'd also like to see yours, Arce.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Programming Practice
There are definitely foobar's in there. I put it at the bottom of an if else chain, but that doesn't matter because I was using && every time.M_D_K wrote:Umm you did pretty bad. riddle me this batman do you ever see a foobar in your output? I doubt it. Since you put it at the bottom of an else if chain. no bonus points for youGinto8 wrote: OK then, with recursion:
Click here to see the hidden message (It might contain spoilers)
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.
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
That should matter, since if it is in the bottom of the loop, it will check first for the first 'if' and if it that works it will skip the others 'else if' ...Ginto8 wrote:There are definitely foobar's in there. I put it at the bottom of an if else chain, but that doesn't matter because I was using && every time.M_D_K wrote:Umm you did pretty bad. riddle me this batman do you ever see a foobar in your output? I doubt it. Since you put it at the bottom of an else if chain. no bonus points for youGinto8 wrote: OK then, with recursion:
Click here to see the hidden message (It might contain spoilers)
But since Ginto8 have added a new argument in his 'if', denying other possibilities, it should work:
Code: Select all
if(divBy3 && !divBy5)
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
OOOOPS I skimmed it since I was up for 30+ hrs
10 points for Ginto.
10 points for Ginto.
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.
Re: Programming Practice
Hey Kurama...KuramaYoko10 wrote: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)
Click here to see the hidden message (It might contain spoilers)
I Remade your code with recursion (just learned with the foobar-Arce`s post up there...so i don`t know if that`s the best way ^^)
Click here to see the hidden message (It might contain spoilers)
- KuramaYoko10
- Chaos Rift Cool Newbie
- Posts: 55
- Joined: Fri Oct 31, 2008 8:02 pm
Re: Programming Practice
Ok... I dont know if I should bring this topic up again, but I like the idea of it, and I will post a very simple challenge which I remember doing when I was learning the basics of C (which I still am... kinda lol)
You are requested to print on screen X numbers of the fibonacci sequence (starting from 0), being X the variable that the user inputs.
The fibonacci sequence is an interesting sequence of numbers in which you get the previous number, add to your current number to get the result of the next number of the sequence ... here is how it starts:
*more info at: http://en.wikipedia.org/wiki/Fibonacci_sequence
I have the code done, but I will try thinking on different ways of solving it, so it will be an exercise to me as well ... I will wait for some replys and then post my code here (and because i am not on my computer right now =P)
You are requested to print on screen X numbers of the fibonacci sequence (starting from 0), being X the variable that the user inputs.
The fibonacci sequence is an interesting sequence of numbers in which you get the previous number, add to your current number to get the result of the next number of the sequence ... here is how it starts:
Code: Select all
0 1 1 2 3 5 8 13 ...
I have the code done, but I will try thinking on different ways of solving it, so it will be an exercise to me as well ... I will wait for some replys and then post my code here (and because i am not on my computer right now =P)
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.