The post Facebook hiring sample test – Missing Term in an Arithmetic Progression appeared first on Dreamshire.

]]>An Arithmetic Progression(AP) is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: Exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.

The first line contains an Integer N, which is the number of terms which will be provided as input.

This is followed by N consecutive Integers, with a space between each pair of integers. All of these are on one line, and they are in AP (other than the point where an integer is missing).

You are provided with 5 integers. As you can can observe, they have been picked from a series, in which the starting term is 1 and the common difference is 2. The only aberration, i.e. the missing term (7), occurs between 5 and 9. This is the missing element which you need to find.

A_{1} and A_{n} are included and valid.

Use this link to get the Project Euler Solution Python 2.7 source.

The post Facebook hiring sample test – Missing Term in an Arithmetic Progression appeared first on Dreamshire.

]]>The post Get the index (‘id’) from the most recently inserted record in MySQL using PHP appeared first on Dreamshire.

]]>In PHP:

```
$result = mysqli_query($link, "INSERT INTO `table` VALUES (NULL, 1005, 'secret');");
$id = mysqli_insert_id($link);
```

This PHP function simply calls the MySQL function: “SELECT LAST_INSERT_ID()”

**NOTE**: If you use the SELECT… query instead of the PHP function then __never__ include a FROM clause to specify the table (or any table), it will return the last id multiplied by the number of records in the table.

**ALSO NOTE**: Don’t query the Database and try to find the highest id, as this may belong to someone else INSERTing into the same table.

The post Get the index (‘id’) from the most recently inserted record in MySQL using PHP appeared first on Dreamshire.

]]>The post Source Code for Master Lock Combination Calculator appeared first on Dreamshire.

]]>```
<table summary="Possible Master Lock Combinations">
<caption>Possible Combinations</caption>
<?php
$default_c3 = 0;
$c3 = (int) isset($_GET["last_comb"])? $_GET["last_comb"] : $default_c3;
if ($c3<0 || $c3>39) $c3 = $default_c3;
for ($c2=($c3+2)%4; $c2<40; $c2+=4)
{
print "<tr>";
for ($c1=$c3%4; $c1<40; $c1+=4)
{
if ($c1-$c2==2 or $c1-$c2==6 or $c2-$c1==38 or $c2-$c1==34 or abs($c3-$c2)%36==2)
echo "<td> </td>";
else
echo "<td>$c1 - $c2 - $c3</td>";
}
print "</tr>\r\n";
}
?>
</table>
```

The post Source Code for Master Lock Combination Calculator appeared first on Dreamshire.

]]>