# Generating All Subsequences Of A Given Length

I am working on a small poker game, and at one point I need to evaluate the hands of all players left. Here’s how the Texas Hold’em (the one I am using) poker style works: at the end of the round you’ll have 5 cards turned on the table, and each player has 2 cards […]

# What’s The First Number to Have N Factors or More?

I am working on a problem where I need to find the first integer which has N or more factors, where N is provided. My approach was to pre-generate a table using the number of factors as index, and the first integer that has that number of factors or more as value. I make the […]

# Counting the Factors of Large Integers

How do you count the factors of large integers? You could go from 1 up to N trying to divide it for all numbers in between, but this wouldn’t be very efficient. A better approach is to use only the prime factors of a number, as all other factors can be derived from those. In […]

# Using the Built-in Sort and Search Functions in C++

Being able to implement your own versions of quicksort (as well as other sorts that might be suitable for the occasion) and binary search algorithms is important (you can check my own implementations here). However, when you are participating in programming contests and challenges the last thing you want to worry about is whether or […]

# Quicksort and Binary Search Algorithms in C/C++

Being able to sort and search efficiently is one of the most important and most studied aspects of computer science. In my opinion any programmer worth his salt should be able to, in a matter of 10 minutes or so, be able to write the algorithms of binary search as well as those of the […]

# CodeSprint 2 Problem: Permutations

This problem appeared on the Code Sprint 2 competition by InterviewStreet.com (check out my review here). Given n, print a permutation(p) of (0,1,2…n-1). From the permutation p, you can create n-1 (x,y) coordinates, where x and y are consecutive pairs in the permutation. You are also given the n x n square matrix V. For […]

# CodeSprint 2 Problem: Picking Cards

This problem appeared on the Code Sprint 2 competition by InterviewStreet.com (check out my review here). There are N cards on the table and each has a number between 0 and N. Let us denote the number on the ith card by ci. You want to pick up all the cards. The ith card can […]

# Make Sure to Participate on the Next Code Sprint

This weekend I took part on Code Sprint 2, a programming competition organized by the folks at InterviewStreet.com. The whole contest was very well organized. What I liked was the fact that you could follow a live leaderboard with the rankings of all participants, and the problems were well structured and explained. They were pretty […]

# 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 […]