News for hackers. Stuff that matters.
Re:How far off am I? by RiderOfGiraffes on Wednesday August 11, 2010 @09:58AM (#1594660)
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.

Re:How far off am I? by mipnix on Wednesday August 11, 2010 @10:34AM (#1594800)
I 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.

Re:How far off am I? by RiderOfGiraffes on Wednesday August 11, 2010 @10:40AM (#1594819)
Here 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?

Re:How far off am I? by mipnix on Thursday August 12, 2010 @01:38AM (#1597320)
Here's what I came up with. It compiles and executes but the result is a random symbol on the console. Definitely missing something.

  #include<iostream>
  #include<string>
  #include<cstring>

  using namespace std;
  void condense_by_removing(char *x, char y);

  int main()
  {
	char *string;
	string = new char[50];
	cout << "ENter your name: ";
	cin >> string;
	cout << endl << "Enter the character to remove: ";
	char ch;
	cin >> ch;
	condense_by_removing(string, ch);
	cout << endl << "new string is: " << *string;

	char dit;
	cin >> dit;

	return 0;
  } 

  void condense_by_removing(char *z_terminated, char  char_to_remove)
  {
	char *chPtr = new char;
	char *trailPtr = new char;

	for(int i = 0; i <= strlen(z_terminated); ++i)
	{
		chPtr = z_terminated;
		if(z_terminated[i] == char_to_remove)
		{
			trailPtr = chPtr;
			delete chPtr;
		}
	}
  }
Re:How far off am I? by RiderOfGiraffes on Thursday August 12, 2010 @06:31AM (#1597723)
OK, now's the time to learn about debugging. Writing clean code to solve small problems from scratch is easy. Debugging existing code, especially well-written code, is hard. This is where you need to use your problem solving skills.

Pretend that you're the computer and walk through the code in small steps, tediously detailed. Make sure you really understand what the code is doing.

What exactly happens when you execute "char *chPtr = new char;" ?

What exactly happens when you execute "delete chPtr;" ?

And why do I say that debugging well-written code is especially hard? Because the names, clarity and simplicity in well-written code seduce you into the same mindset as produced the code that has the bug.

Re:How far off am I? by mipnix on Thursday August 12, 2010 @09:39AM (#1598041)
I could have used you as my professor in my recent data structures class.

I imagine you have myriad responsibilities in the course of your day and I am grateful for the time you are affording me.

I will work on this tonight.

Re:How far off am I? by mipnix on Wednesday August 11, 2010 @11:01AM (#1594881)
Don'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.

Re:How far off am I? by mipnix on Wednesday August 11, 2010 @12:09PM (#1595086)
Ok. 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>

Re:How far off am I? by RiderOfGiraffes on Wednesday August 11, 2010 @02:49PM (#1595621)

  #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?

Re:How far off am I? by mipnix on Wednesday August 11, 2010 @03:19PM (#1595747)
Besides 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.

Re:How far off am I? by DEADBEEF on Saturday August 14, 2010 @12:34AM (#1602956)
Something 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.

Re:How far off am I? by RiderOfGiraffes on Sunday August 15, 2010 @07:20AM (#1604941)
You haven't printed any of the other numbers. Read the spec more carefully. You still need to print 1, 2, 4, etc.