Saturday, March 8, 2008

How many positive integers less than 1,000, 000 have exactly one digit equal to 9 and have a sum of digits equal to 13?


There are six choices for the position where 9 appears.

After that choice has been made, the problem reduces to figuring out how many ways are there to select a sequence of five positive integers summing to 4 (since 13 − 9=4).

This is the same as counting permutations of four stars and four bars; the first integer in the sequence corresponds to the number of stars before the first bar, the second to the number of stars between first and second bars, etc.

The total number of ways to permute four stars and four bars is Bin(8,4) . Therefore th number of positive integers less than 1, 000, 000 that have exactly one digit equal to 9 and the sum of digits equal to 13 is 6 Bin(8,4) .

Insert form value to MySQL table using PHP

Computer Description: $test
// Close the database connection


Only read unique values out of MySQL table

select all the values out of a MySQL Database that are UNIQUE:
$result = mysql_query("SELECT DISTINCT fieldNAME FROM tableName");


Sunday, March 2, 2008

ISBN-13 to ISBN-10 Convertion

Recommended Conversion Tool:

To convert an ISBN-13 to ISBN-10, you need not only to remove the first three characters. You also need to recompute the checksum.

Here is a piece of code that Febrice wrote:

public static String Isbn13to10(String isbn13)
if (String.IsNullOrEmpty(isbn13))
throw new ArgumentNullException("isbn13");
isbn13 = isbn13.Replace("-", "").Replace(" ", "");
if (isbn13.Length != 13)
throw new ArgumentException("The ISBN doesn't contain 13 characters.", "isbn13");

String isbn10 = isbn13.Substring(3, 9);
int checksum = 0;
int weight = 10;

foreach (Char c in isbn10)
checksum += (int)Char.GetNumericValue(c) * weight;

checksum = 11-(checksum % 11);
if (checksum == 10)
isbn10 += "X";
else if (checksum == 11)
isbn10 += "0";
isbn10 += checksum;

return isbn10;