# Flame the inner gamer in you with FLAMES

As we all know, we have played the game Flames during our school time and teenage. Using this game, we can predict the relationship between two names, under these:

``````F - Friends
L - Love
A - Affection
M - Marriage
E - Enemies
S - Siblings
``````

To find the relationship, we can do in this way. The names must be different and must contain at least 2 letters each. The steps in finding out the relationship is as follows:

Step 1: List down the two names. For Eg., here I am taking two names, namely Aboo and Bob.

``````ABOO
BOB
``````

Step 2: The common letters in them are stroked off, each (highlighted), and the remaining number of letters are counted. In this case, it is 3.

ABOO
BOB

The resultant we are left with:

``````AO
B
``````

Step 3: The main calculation is as follows. strike off the nth letter in FLAMES for each iteration until we are left with only one letter. In our case, it is 3rd (nth) letter.

``````FLAMES           # A
FLMES            # S
FLME             # M
FLE              # E
FL               # F
L
``````

Step 4: The final step: Now we are left only with one letter, which is L, which resolves to Love.

The Program

Now lets create a program for this in PHP. The source code for `flames.php` is as follows:

``````<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Flames by Praveen</title>
<style type="text/css">
body, input {font-family: 'Segoe UI', tahoma; font-size: 12px; width: 150px;}
form div {margin: 5px;}
</style>

<body>
<?php
\$flames = array(
"F" => "Friends",
"L" => "Lovers",
"A" => "Affectionate",
"M" => "Married",
"E" => "Enemies",
"S" => "Siblings"
);
if (isset(\$_GET["names"]))
if (count(\$_GET["names"]) == 2) {
\$n1 = strtoupper(str_replace(" ", "", \$_GET["names"][0]));
\$n2 = strtoupper(str_replace(" ", "", \$_GET["names"][1]));
if (\$n1 == \$n2)
echo "<div>Both the names are same!</div>";
else {
for (\$i = 0; \$i < strlen(\$n1); \$i++) {
if (isset(\$n1[\$i]))
for (\$j = 0; \$j < strlen(\$n1); \$j++)
if (isset(\$n2[\$j]))
if (\$n1[\$i] == \$n2[\$j]) {
\$n1[\$i] = \$n2[\$j] = "/";
break;
}
}
\$n1 = str_replace("/", "", \$n1);
\$n2 = str_replace("/", "", \$n2);
\$count = strlen(\$n1) + strlen(\$n2);
\$flame = "FLAMES";
echo "<div>";
while (strlen(\$flame) != 1) {
\$flame[\$count%strlen(\$flame)] = "/";
\$flame = str_replace("/", "", \$flame);
}
echo "You both are <strong>" . \$flames[\$flame] . "</strong></div>";
}
}
else ; // Had to give, else the parser will get confused.
else
{ ?>
<form method="get" action="">
<div>Enter the Names</div>
<div><input type="text" name="names[]" /></div>
<div><input type="text" name="names[]" /></div>
<div><input type="submit" value="Get Relation" /></div>
</form>
<?php } ?>
</body>
</html>
``````

Hope you enjoyed this cutie snippet to make pranks. Let me know if you have any issues in the comments.

### Praveen Kumar Purushothaman

Cook, Cat Lover, Front End Architect, Web Developer Evangelist & Cloud Computing Consultant