Sunday, August 29, 2010

Coding in C++ on Ubuntu Walk-through

I've been using Ubuntu as my main operating system for a month now. I haven't practiced coding for a whole month at least. I'm bad now. I didn't even remember exactly what to 'include' for a simple Hello World app. I'm still getting used to Ubuntu. I'm learning something new about Ubuntu everyday and just a couple days ago I learned how to make an app on Ubuntu using just the terminal and a text editor and C++.

step one: open the terminal

step two: mkdir ~/programs

Type mkdir ~/programs into the the terminal to create a folder or 'directory' called 'programs', in your 'home directory'. mkdir
stands for 'make directory'.

step three: cd ~/programs

Type cd ~/programs
to change the directory your terminal is referring to from your 'home folder' to your new 'programs' directory where you will write the code for your program.

step four: g++ --version

Type g++ -- version to make sure you have the GNU C++ compiler

g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The message above is the response I get from my terminal after I enter the command g++ --version. I believe this response indicates that I do have the GNU C++ compiler.

step five: Write the code

Now you have to open a text editor and write the code for your app. For my first app I wrote the code for "Hello World", simple text output. You have to save the text file with the .cpp extension or the G++ compiler may not recognize the source code file. Save the source code in the 'programs' directory you created.

step six: g++ -o hello_world hello_world.cpp

This command will compile the hello_world.cpp file to an executable called hello_world in the same directory.

step seven: Run your program with ./hello_world

./ means 'in current directory'. If you copy pasted or wrote the code yourself with no errors then the program should say "hello world" in the terminal. In Ubuntu you don't have to worry about the terminal shutting down as you have to in Windows.




Sudoku Cheater Fail

My first attempt to create a sudoku solver was a complete fail. Having a program go through the trial and error of billions of number combinations 'til the program finds the number combination that satisfies the conditions of a solved sudoku board is a bad way to go about coding a sudoku solver unless you're using a super computer maybe (I don't know). I thought i could apply the same function that I used for a simpler 3 by 3 sudoku 'board' to the standard 9 by 9 sudoku board but the difference in magnitude between the combinations of a 3 by 3 and the magnitude of combinations of a 9 by 9 are astronomical. I don't know when I'll try to make a sudoku solver again. I'm supposed to be looking for existing code for a sudoku solver in whatever other language and translate the same logic used in another language into C++ or find the code for a sudoku solver written in C++ but I'm lazy.

Tuesday, June 30, 2009

Beginning Sudoku Cheater Software

I'm planning on making a sudoku cheater program. Before I begin, I should study Sudoku. Sudoku is a board of 81 squares organized in 9 rows of 9 squares each. The typical sudoku board has just enough numbers on it for the player to guess the other numbers on the board. I guess I'm skipping a lot of necessary details. Each row must include numbers 1 through 9 and the same within each column. I play Sudoku sometimes ergo I'm aware of some of the techniques that are used to quickly find missing numbers and I think I may implement these techniques into the code but I've noticed that on the more difficult sudoku games where not many numbers are given or the numbers that are given strategically don't give you any hints as to what the other spaces could be, the trial and error method is required. The program could be entirely based on the trial and error method or I can have a couple functions that go through the most common techniques and then finally a function that looks for the rest of the numbers through trial and error.

Saturday, May 30, 2009

how many clicks?

blogspot:
to blog a new post on blogspot is 3 clicks (if i'm logged in)
1. clicking www.blogspot.com
2. clicking "new post"
3. clicking "publish post"

facebook:
depends on what you do there but that takes about 5 clicks as well

gmail
takes about 5 clicks to open chats with some friends and check some mails

google reader
takes about 5 clicks too... i wish google reader and google talk would come together so I didn't ahve to be on gmail for google talk and google reader at the same time. i'm not sure how much memory and bandwidth that takes up.

bottom line is that I can't wait for google wave. where else is that awesome spell checker being implemented?

Tuesday, April 28, 2009

Memorizing SDL

I read an article about the best study method. I want to learn how to use SDL, so I'm going to apply this method now. I'm going to try to recall whatever code I can from lesson 4 and type it here.

#include "SDL/SDL.h" // always need when SDL program
#include "SDL/SDL_Img.h" // need for .png files to display
#include <strings>

//screen attributes

const int scn_h = 640; //screen height
const int scn_w = 480; //screen width
const int scn_bpp = 32; // screen bits per pixel

/* darn, I'm not sure width was 480 (I'll check when I'm completely lost.) */

SDL_Event event; //structure to hold events for us to handle

// function prototypes

SDL_Surface * load_image (std::string); // returns pointer to SDL Surface with a parameter to a string

/*OK. I'm lost. Lazy Foo, defines several other functions before he gets into the main, but I barely remember I'm going to have to re read the whole section. Yes, I know that I said SDL was easy to understand since I pretty much know the C++ invovled but I don't want to be tutorial dependent for every function. I want to know the SDL library so I can do things off the top of my head with it.*/

In our experiments, when students repeatedly read something, it falsely inflates their sense of their own learning."

Saturday, April 18, 2009

C PLUS PLUS NEWB

I wanted to change my blog URL to www.cplusplusnewb.blogspot.com to avoid the negative connotations of the word "noob", but somebody already took that URL. I went to check out what cplusplusnewb is all about; turns out that cplusplusnewb is a very neat blog. I love the way this programmer organized the blog where you can see pictures of the the program in action, download the program, and download the source. The blog style is very clean, simple, and easy to learn from.

The Meaning of Noob

I just discovered that the word "noob" has very negative connotations.

"Contrary to the belief of many, a noob/n00b and a newbie/newb are not the same thing. Newbs are those who are new to some task* and are very beginner at it, possibly a little overconfident about it, but they are willing to learn and fix their errors to move out of that stage. n00bs, on the other hand, know little and have no will to learn any more. They expect people to do the work for them and then expect to get praised about it, and make up a unique species of their own. It is the latter we will study in this guide so that the reader is prepared to encounter them in the wild if needed." -urban dictionary on the definition of noob

I'm not a noob if that's what a noob is. I don't wish to be praised by others' works. I hope to become a great programmer, but I know now that I'm far from being one. I'm still a newbie learning from my programming errors and learning from programmers that I'm a mere fraction of. I think this blog's URL is cplusplusnoob.blogspot.com and I'm not sure there is anything I can do to change this. :(

edit: I managed to change the site name to www.cppnewb.blogspot.com

I wish I could have changed the site name to cplusplusnewb, but that was taken by somebody.