Do You Need to Pay for MySQL On a Closed Source Project?

Although MySQL is open source, the software is not actually free. If you visit MySQL’s website you’ll notice they charge for it. But since it’s open source shouldn’t you be able to use it without paying? I was curious about this topic, and I found an interesting answer on StackOverflow. The original question was: Is […]

Generating Permutations in C++

Suppose you have the following set: {0,1,2}. How do you generate all the possible permutations of such set? One possible approach is to use recursion. First we need to break the problem into smaller sub-problems. This could be done by splitting the set into two parts. We keep the right side fixed, and then find […]

Basics of Object Oriented Programming

Below you’ll find some of the basic concepts of Object Oriented Programming: OOP: Object Oriented Programming is a software design philosophy or approach, which aims to model software closer to what we see in real life. While procedural languages like C focus on functions that manipulate data, OOP languages like C++ or Java focus on […]

Powerset Algorithm in C++

A powerset of a given set is the combination of all subsets, including the empty subset and the set itself. Suppose we have the following set: {1,2,3}. Its powerset would be: {1,2,3} {1,2} {1,3} {2,3} {1} {2} {3} Creating an algorithm to generate a powerset is not trivial. The first idea you can use is […]

Sets, Sequences and Tuples

If you are not sure about the differences between sets, sequences and tuples, here they are: Sequences: A sequence is an ordered list of elements, which can also be infinite (e.g., the sequence composed of the real numbers). Since order of elements matter, the sequence (1,2,3) is different from the sequence (1,3,2) or from the […]

Programming Challenges and Contests Online

I am noticing an interesting trend lately: there are a bunch of website emerging with the goal of connecting programmers and tech companies by using programming challenges and contests. Some that you might wanna check out: Gild.com CodeEval InterviewStreet Code Chef Top Coder is probably the pioneer in this area, by those upcoming sites seem […]

C Programming Puzzle #3

The code of the previous puzzle was the following: #include <stdio.h> void foobar(char *str1, char *str2){   while (*((str1++)+6) = *((str2++)+8)); } int main(){   char str1[] = "Hello World";   char str2[] = "Foo Bar Bar";   foobar(str1,str2);   printf("%s %sn",str1, str2);   return 0; } The answer is that it prints “Hello Bar Foo Bar Bar”. Function foobar will […]

How To Concatenate Two Integers in C

This might not be the most efficient way, but it’s certainly one of the easiest. You simply need to convert both integers into strings using sprintf, concatenate those using strcat, and then reverse the combined string to an integer using the atoi function. int concat(int x, int y){     char str1[20];     char str2[20];     sprintf(str1,"%d",x);     sprintf(str2,"%d",y);     strcat(str1,str2); […]

C Programming Puzzle #2

The code of the first puzzle was: #include <stdio.h> int main(){     if("Hello World" == "Hello World"){        printf("Yes ","No ");     }     printf(10+"Hello World"-4); return 0; } The answer is that it prints “Yes World”. First of all the statement inside the IF will be executed because we compare the same pointer, which returns 1 (although […]

Solution to Project Euler 8

In Problem 8 you need to find the greatest product of five consecutive digits of a 1000-digit number that is given. To find the solution I simply read the number into an array and then traversed it comparing the product of five digits at a time. #include <stdio.h> int main(){   int vet[1000];   int z,max,c,j,i=0;   while(i<1000){ […]