Factorials, Permutations, Etc.

Today, I partially rewrote a program which I initially wrote last year. The program, written in c++, deals with combinations for a combination lock. It has several different modes available, allowing one to make one number constant, or display only combinations containing a given number, or numbers. Naturally, I had to check the programs work, so, for the hell of it, I will post that here. ( yeah, I know, I am weird. )

mode 1: list all possible combinations.
. No digits are allowed to repeat, so this is simply (50)(49)(48), or 50!/47!

Mode 2: list all possibilities where the xth number is constant.
This one is a little bit harder, but still, not all that hard. It is given as: (50)(49), or 50!/48!.

Mode 3: list all combinations containing x
This one is a little bit harder. 3!(50)(49)(1)/2!. The three factorial comes from the fact that the three numbers can be permuted three ways. The 2! there is because we are dealing with combinations. (all digits unique)

That was really poorly written… I’ll post something less educational tomorrow…

Leave a Reply