4 ms·
Not everyone will agree with the following, so you'll need to take this, and their comments as well, with a large dollop of critical thinking. Use Python and w
by RiderOfGiraffes 16y ago
Not everyone will agree with the following, so you'll need to take this, and their comments as well, with a large dollop of critical thinking.
Use Python and write a program that prints the numbers from 1 to 100. Then change it so that when a number is divisible by 3 it prints "Fizz" instead. Then change it again so that when a number is divisible by 5 it prints "Buzz". If the number is divisible by both 3 and 5 have it print "FizzBuzz".
Then write it again in C++.
Now ask, how could your program be made simpler? How could it be made clearer? If someone came to it in 6 months time, what would the y need to know in order to assess whether it's doing the right thing?
If you can do all that effortlessly then you're a long way there and in need of a harder challenge that gives you some satisfaction. If it requires any real thought then you need lots and lots of practice at writing code.
- mipnix 16y agoI will look into the Python. The coding in C++ is not a problem. I do the puzzles on ProjectEueler and the exercises in the textbooks but I don't see how they apply to real world development. I understand the need to practice code and take to it religiously. My wife hated when I was gone all the time. Now I am home and she hates that I am on the computer. You are right about increasing the level of difficulty. Thanks.
- RiderOfGiraffes 16y agoHere are some random questions to help you explore what you want to do. Just to get a feel for the kind of code you write, perhaps you could take this little challenge: Write a C routine with the following prototype: void condense_by_removing( char *z_terminated , char char_to_remove ); Your routine should modify the given zero-terminated string in place, removing all instances of the given char. If you're brave you can post your code here ... Apart from that, the challenge is to decide what kind of job you want, then make sure you develop a resume to get it. If you want a web developer job then you have to write some web apps. If you want a systems programmer job then you need to write some slick algorithmic code. Do you know what a B-tree is and when you would use it?
- mipnix 16y agoDon't know it well enough to code it from scratch at work. Have an idea. Will post something by tonight. Just finished a Data Structures class and still wrapping my head around Trees and hashing. Thank you, kindly.
- mipnix 16y agoOk. Had to get this out quick... Back to work. Don't know if it will compile <code> #include<iostream> using namespace std; int main() { for(int i = 1; i <= 100; ++i) { if(i%3==0 &&i%5==0) cout <<"Fizzbuzz "; else if(i % 3==0) cout <<"FIzz "; else if(i%5==0) cout<<"buzz "; else cout << i << " "; } return 0; } </code>
- RiderOfGiraffes 16y ago#include<iostream> using namespace std; int main() { for(int i = 1; i <= 100; ++i) { if(i%3==0 && i%5==0) cout <<"Fizzbuzz "; else if(i%3==0) cout <<"FIzz "; else if(i%5==0) cout<<"buzz "; else cout << i << " "; } return 0; } Cool. Assuming you knocked that out as quickly as you suggest it shows that you've got good basic skills. Design and control of larger tasks/projects is untested, but it looks like you're well ahead of the basics. Now here's a question: Do you find anything "unsatisfactory" about that code?
- mipnix 16y agoBesides not knowing how to post it properly...? The looping sequence, I imagine, doesn't need the if else queries. Probably simpler way to code it. I am definitely untested with larger projects.
- DEADBEEF 16y agoSomething like... (Pseudocode) for( i= 1,100 ) { if( i%3==0 ) { print( 'Fizz' ) } if( i%5==0 ) { print( 'Buzz' ) } print( '\n' ) } There's no need to treat FizzBuzz as a special case, as if the number is divisible by both it will have already met the conditions of the previous two statements. I wonder if there's some magic you could sprinkle in to the iterator so it only iterates through numbers which are divisible by 3/5, ignoring the rest? It probably wouldn't speed the operation up much (if at all) in this case, in a more complex real world scenario though it's best to look at every angle.