An interesting problem solving question.
This questions has been adapted from a codejam session.
Let us take a hacker who wants to identify passwords from fingerprints.
There are M keys with fingerprints and N letters in the password.
The hacker knows both M and N but there are different permutations for the password and the hacker does not know the order in which the fingerprints were made.
Take for instance M = 3 and N = 4 and the fingerprints on the numbers 3,5 and 7.
This means that the following passwords are possible 3357, 3557 and 3577.
and the corresponding permutations.
The permutations for 3357 are 4! / 2 = 12 in number because two of the letters are identical and so the resulting permutations will be the same.
Since any of the M characters can appear in duplicate to make a set of 4 in the password, we have 3 * 12 = 36 possible passwords with this configuration.
The permutations can be generated by a sample code below
Void Permute (String a, StringBuilder b, bool[] used)
{
If ( b.Length == a.Length) { print b.ToString(); return;}
For (int I = 0; I < a.Length ; i++)
{
If (used[i]) continue;
used[i] = true;
B += A[i];
Permute(a, b, used);
B [B.Length – 1] = ‘/0’;
used[i] = false;
} ms
}
But let us look at how to find out the number of such permutations for different values of M and N
if M = 3 and N = 5, then we know that two letters are repeated or one letter appears thrice.
In general, repetitions are taken care of by dividing the permutation by the factorial of the number of objects that are identical.
33557 = 5!/(2!2!) = 120/4 = 30
33357 = 5!/3! = 120/3! = 20
In the latter case 5 and 7 can each occupy one of the five positions times the remaining four positions for the other
now the above two cases can be repeated with 5 and 7 as well so we have a total of 3 * (30+20) = 150 cases.
As N increases we have further breakouts of the difference between M and N.
If M = 3 and N = 6, then we can have three letters repeating twice, two letters with one repeating thrice and another repeating twice and one letter or one letter repeating four times.
#billing in AWS
ImageType to vCPU
Sample bill generated with : https://github.com/ravibeta/PHPSamples/blob/master/billing.php
This questions has been adapted from a codejam session.
Let us take a hacker who wants to identify passwords from fingerprints.
There are M keys with fingerprints and N letters in the password.
The hacker knows both M and N but there are different permutations for the password and the hacker does not know the order in which the fingerprints were made.
Take for instance M = 3 and N = 4 and the fingerprints on the numbers 3,5 and 7.
This means that the following passwords are possible 3357, 3557 and 3577.
and the corresponding permutations.
The permutations for 3357 are 4! / 2 = 12 in number because two of the letters are identical and so the resulting permutations will be the same.
Since any of the M characters can appear in duplicate to make a set of 4 in the password, we have 3 * 12 = 36 possible passwords with this configuration.
The permutations can be generated by a sample code below
Void Permute (String a, StringBuilder b, bool[] used)
{
If ( b.Length == a.Length) { print b.ToString(); return;}
For (int I = 0; I < a.Length ; i++)
{
If (used[i]) continue;
used[i] = true;
B += A[i];
Permute(a, b, used);
B [B.Length – 1] = ‘/0’;
used[i] = false;
} ms
}
But let us look at how to find out the number of such permutations for different values of M and N
if M = 3 and N = 5, then we know that two letters are repeated or one letter appears thrice.
In general, repetitions are taken care of by dividing the permutation by the factorial of the number of objects that are identical.
33557 = 5!/(2!2!) = 120/4 = 30
33357 = 5!/3! = 120/3! = 20
In the latter case 5 and 7 can each occupy one of the five positions times the remaining four positions for the other
now the above two cases can be repeated with 5 and 7 as well so we have a total of 3 * (30+20) = 150 cases.
As N increases we have further breakouts of the difference between M and N.
If M = 3 and N = 6, then we can have three letters repeating twice, two letters with one repeating thrice and another repeating twice and one letter or one letter repeating four times.
#billing in AWS
ImageType to vCPU
$imageTypeVCPU = array(
"t2.nano" => 1,
"t2.micro" => 1,
"t2.small" => 1,
"t2.medium" => 2,
"t2.large" => 2,
"m4.large" => 2,
"m4.xlarge" => 4,
"m4.2xlarge" => 8,
"m4.4xlarge" => 16,
"m4.10xlarge" => 40,
"m3.medium" => 1,
"m3.large" => 2,
"m3.xlarge" => 4,
"m3.2xlarge" => 8,
"c4.large" => 2,
"c4.xlarge" => 4,
"c4.2xlarge" => 8,
"c4.4xlarge" => 16,
"c4.8xlarge" => 36,
"c3.large" => 2,
"c3.xlarge" => 4,
"c3.2xlarge" => 8,
"c3.4xlarge" => 16,
"c3.8xlarge" => 32,
"r3.large" => 2,
"r3.xlarge" => 4,
"r3.2xlarge" => 8,
"r3.4xlarge" => 16,
"r3.8xlarge" => 32,
"g2.2xlarge" => 8,
"g2.8xlarge" => 32,
"i2.xlarge" => 4,
"i2.2xlarge" => 8,
"i2.4xlarge" => 16,
"i2.8xlarge" => 32,
"d2.xlarge" => 4,
"d2.2xlarge" => 8,
"d2.4xlarge" => 16,
"d2.8xlarge" => 36,
);
Sample bill generated with : https://github.com/ravibeta/PHPSamples/blob/master/billing.php
No comments:
Post a Comment