How to shoot yourself in the foot
Jay Dobies Commented on the last post about coding and religion, and I thought the link he posted was worth another blog post in its own right.
How to shoot yourself in the foot
Of all of those, I really enjoyed the “Unix” one:
Unix
% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm: .o: No such file or directory
% ls
%
And Perl:
Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.
Anyway, if you are at all interested in programming languages, it’s worth a read. It certainly made the joke of the day for me!
self.take_note(git)
getting git running is a bit odd if you don’t know your way around. After some fighting, I figured it out, and so, here is a note to self in case I need to refer to it later.
$ git init
$ git remote add origin git@example.org/project.git
$ git add my_folder file1 file2
$ git commit -m ‘commit message’
$ git push origin master
$ git push
coding and religion
What would you call your favorite programming language if it was a religion?
http://www.aegisub.net/2008/12/if-programming-languages-were-religions.html
I just found it funny and wanted to share it
a step a little ahead, gui with python/Tk
I just started to write a very very VERY simple phonebook for my own use. This is just a quick note, and I will keep you posted with snippets here and there. this link helped me get through understanding how I would go about doing it. Anyway, I’ll get started now, will post snippets whenever possible!
is that really prime?
so, today I wrote my second python script ( big accomplishment ) which just lists prime numbers. I put it in a file called prime.py so I might be able to use it later on!! This is how it looks like:
====================================================
#printing a range of prime numbers def isPrime( n ): factor = n // 2 while factor > 1: if n % factor == 0: return 0 break else: factor -= 1 else: return 1 def listPrimes( num ): for n in range( num + 1 ): if n > 1: if isPrime( n ): print n, 'is prime' listPrimes( 100 );
====================================================
and that’s all there is to it! Well, just add the indentation yourself, I still haven’t figured out how to keep the indentation when posting scripts!
hahahaha and on a side note, I had to check all of the output numbers myself ( not thoroughly though ) just to make sure I didn’t make any mistakes in the script! funny way of debugging.
UPDATE: thanks to a fantastic blogger, Vlad Dolezal ( anamazingmind.com ) I’m able to keep the formatting of the code!
autopoker, looking good!
Ladies and Gentlemen, I’m now presenting the most precious invention of mankind ever!!!
ok, don’t take it seriously, I finally managed to gather all the code into one file ( it’s now 4 files! ). Now you can take a look and see what I did so far. If you have any questions or you don’t understand some parts, just comment and I’ll get to you
here’s the link to download a .txt file
change the extension to .cpp and use it
rewriting everything, top to bottom
I finally know how to use classes
yay, the only trick is that you should put it BEFORE int main() which I didn’t know and I used to put it AFTER int main(). The result? error: no “Something something1;” has not type! where Something is a class and something1 is an object. Anyway, I did it and therefore, I rewrote every single line of autopoker.cpp and also created a new header file player.h for it. Today, however, I was talking to my friend on the phone and he accidentally brought up a good point. He said that I can make a card class and instantiate ( create ) 52 objects of that class. Just think about it, FIFTY TWO OBJECTS!!! O_O that’s a lot and takes a lot of time! I might do that though, but first I try to fix the current one!
God bless OOP
I’m still having difficulty implementing OOP ( stands for Object-Oriented Programming ) into my sources. But if you think about it, OOP makes life much easier and faster! Well it doesn’t make life faster but programming at least. And that, in turn, makes life more “enjoyable” specially when you don’t have compile-time errors as I just had! I don’t know why it just doesn’t work! OOP I mean. And that is exactly why I’m passionately waiting for my book C++ How to Program ( a great book by the way ) to come. Its early classes approach is what I was looking for. I doesn’t really make you wait years ( figuratively ) to know what is a class and what is an object, which are, in fact, what make C++, a real C++. Anyway, I gave up on classes and OOP for now till my book comes and I can finally see how to work efficiently with objects. For now, I think the development of autopoker.cpp ( refer to previous posts && the same as poker.cpp just changed the name ) is in a soft freeze
because of the fact that I can’t think of ANY way to continue it without classification ( implementing OOP ). And because I don’t know how to work with objects, therefore, it’s stalled!
first bits of poker.cpp
It’s going well, I’m working on the first bits of it. Some starting points such as just shuffling and dealing a deck of cards.
This is what I’ve got so far:
//put random numbers in slots
#include iostream
#include ctime
#include cstdlib
#include iomanip
using namespace std;
int main ()
{
const int totalCards = 52;
const int deckRows = 4;
const int deckColumns = 13;
int deck[ deckRows ][ deckColumns ] = { 0 };
char *suite[] = { “Hearts”, “Clubs”, “Diamonds”, “Spades” };
char *face[] = { “Ace”, “Two”, “Three”, “Four”, “Five”, “Six”, “Seven”, “Eight”, “Nine”, “Ten”, “Jack”, “Queen”, “King” };
srand( time( 0 ) );
for( int card = 1; card <= totalCards; card++ ) {
int randrow = rand() % deckRows;
int randcolumn = rand() % deckColumns;
while( deck[randrow][randcolumn] != 0 ) {
randrow = rand() % 4;
randcolumn = rand() % 13;
}
deck[randrow][randcolumn] = card;
}
/*
//print the deck
for( int i = 0; i < deckRows; i++ ) {
for( int j = 0; j < deckColumns; j++ ) {
cout << setw( 5 ) << deck[ i ][ j ] << ” “;
}
cout << endl;
}
//check for wrong numbers
for( int x = 0; x < deckRows; x++ ) {
for( int y = 0; y 52 || deck[ x ][ y ] < 1 ) {
cout << “INVALID NUMBER DETECTED IN LOCATION: ” << x << “, ” << y << endl;
}
}
}
*/
for( int card = 1; card < totalCards; card++ ) {
for( int i = 0; i < deckRows; i++ ) {
for( int j = 0; j < deckColumns; j++ ) {
if( deck[ i ][ j ] == card ) {
cout << face[ j ] << ” of ” << suite[ i ] << endl;
}
}
}
}
}
again, add the indentation yourself!
It essentially shuffles a deck of cards and deals all 52 cards and says what they are in order! If you don’t understand part of the code, just let me know by writing a comment!
put random numbers in slots!
I did it finally! a very easy thing but quite annoying because I didn’t know my mistake and I still don’t know it. Here is the code I was “working on” for the last 2 days:
//put random numbers in slots
#include iostream
#include cstdlib
#include ctime
#include iomanip
using namespace std;
int main ()
{
const int totalCards = 52;
const int arrayRows = 4;
const int arrayColumns = 13;
int array[ arrayRows ][ arrayColumns ] = { 0 };
srand( time( 0 ) );
for( int card = 1; card <= totalCards; card++ ) {
int randrow = rand() % arrayRows;
int randcolumn = rand() % arrayColumns;
while( array[randrow][randcolumn] != 0 ) {
randrow = rand() % 4;
randcolumn = rand() % 13;
}
array[randrow][randcolumn] = card;
}
//print the array
for( int i = 0; i < arrayRows; i++ ) {
for( int j = 0; j < arrayColumns; j++ ) {
cout << setw( 5 ) << array[ i ][ j ] << " ";
}
cout << endl;
}
//check for wrong numbers
for( int x = 0; x < arrayRows; x++ ) {
for( int y = 0; y 52 || array[ x ][ y ] < 1 ) {
cout << "INVALID NUMBER DETECTED IN LOCATION: " << x << ", " << y << endl;
}
}
}
}
Anyway, this doesn’t have any mistakes but it uses a very very very poor algorithm of “retry if it’s taken.” Well, I know that, but I will try to work on a better algorithm for it! Or maybe make it into a bigger thing! Programming is fun, but up to when you don’t have any mistakes. Leave comments if you are thinking of a better algorithm ![]()
And by the way, I finished my math exam last Thursday, it was easy as always! Looking forward to next semester when I have Physics 12
must be better than Physics 11 I had this semester!
Also, indent this code yourself, this blog doesn’t show indentation! and put “” around cstdlib, iomanip, ctime, and iostream!
Don’t forget to comment!