Program to implement FLAMES game

FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately predict whether or not an individual is right for you, but it can be fun to play this with your friends.

There are two steps in this game:

    Get the count:

    • Take the two names.
    • Remove the common characters with their respective common occurrences.
    • Get the count of the characters that are left .

    Get the result :

    • Take FLAMES letters as [“F”, “L”, “A”, “M”, “E”, “S”]
    • Start removing letter using the count we got.
    • The letter which last the process is the result.

Example :

Input: Player1 = AJAY, Player2 = PRIYA
Output: Friends

Explanation: In above given two names A and Y are common letters which are occurring one time(common count) in both names so we are removing these letters from both names. Now count the total letters that are left here it is 5. Now start removing letters one by one from FLAMES using the count we got and the letter which lasts the process is the result.

Counting is done in an anti-clockwise circular fashion.

counting starts from F, E is at 5th count so we remove E and start counting again but this time start from S.
M is at 5th count so we remove M and counting starts from S.
S is at 5th count so we remove S and counting start from F.
L is at 5th count so we remove L and counting starts from A.
A is at 5th count so we remove A. now we have only one letter is remaining so this is the final answer.
So, the relationship is F i.e. Friends .

Approach: Three counters are required, two for the names initialized at zero, and one for flames initialized at 5. Three strings are used, two for names and one, where FLAMES is already stored. Here the program first calculated the number of letters in the first name and then calculated the number of letters in second name Then after storing them using strlen into integer variables, one for loop is run for each name to count the common letters. Then by using nested if-else the letters are cancelled from each name, which is represented by a string. The for loop is again repeated to continue this process. Accordingly, the counter rotates and each letter in FLAMES is pointed at. As letters get canceled the loop is run again. Then for each letter, an If else statement is used, Print the result corresponding to the last letter.

Below is the implementation :






// C program to implement FLAMES game
#include <stdio.h>
#include <string.h>
// Function to find out the flames result
void flame(char* a, char* b)
    int i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;
    char q[25], w[25], c;
    char f[] = "flames";
    strcpy(q, a);
    strcpy(w, b);
    n = strlen(a);
    m = strlen(b);
    tc = n + m;
    for (i = 0; i < n; i++) {
        c = a[i];
        for (j = 0; j < m; j++) {
            if (c == b[j]) {
                a[i] = -1;
                b[j] = -1;
                sc = sc + 2;
    rc = tc - sc;
    for (i = 0;; i++) {
        if (l == (rc)) {
            for (k = i; f[k] != '\0'; k++) {
                f[k] = f[k + 1];
            f[k + 1] = '\0';
            fc = fc - 1;
            i = i - 1;
            l = 0;
        if (i == fc) {
            i = -1;
        if (fc == 0) {
    // Print the results
    if (f[0] == 'e')
        printf("%s is ENEMY to %s ", q, w);
    else if (f[0] == 'f')
        printf("%s is FRIEND to %s ", q, w);
    else if (f[0] == 'm')
        printf("%s is going to MARRY %s", q, w);
    else if (f[0] == 'l')
        printf("%s is in LOVE with %s ", q, w);
    else if (f[0] == 'a')
        printf("%s has more AFFECTION on %s ", q, w);
        printf("%s and %s are SISTERS/BROTHERS ", q, w);
// Driver code
int main()
    char a[] = "AJAY";
    char b[] = "PRIYA";
    flame(a, b);







# Python3 program to implement FLAMES game
# Function to find out the flames result
def flame(a, b):
    l, sc = 1, 0
    rc, fc = 0, 5
    f = "flames"
    f = [i for i in f]
    q = "".join(a)
    w = "".join(b)
    # print(q, w)
    n = len(a)
    m = len(b)
    tc = n + m
    for i in range(n):
        c = a[i]
        for j in range(m):
            if (c == b[j]):
                a[i] = -1
                b[j] = -1
                sc = sc + 2
    rc = tc - sc
    i = 0
    while (i):
        if (l == (rc)):
            for k in range(i,len(f)):
                f[k] = f[k + 1]
            f[k + 1] = '\0'
            fc = fc - 1
            i = i - 1
            l = 0
        if (i == fc):
            i = -1
        if (fc == 0):
        l += 1
        i += 1
    # Print the results
    if (f[0] == 'e'):
        print(q, "is ENEMY to", w)
    elif (f[0] == 'f'):
        print(q, "is FRIEND to", w)
    elif (f[0] == 'm'):
        print(q, "is going to MARRY", w)
    elif (f[0] == 'l'):
        print(q, "is in LOVE with", w)
    elif (f[0] == 'a'):
        print(q, "has more AFFECTION on", w)
        print(q, "and", w, "are SISTERS/BROTHERS ")
# Driver code
a = "AJAY"
b = "PRIYA"
a = [i for i in a]
b = [j for j in b]
# print(a,b)
flame(a, b)
# This code is contributed by Mohit Kumar




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : mohit kumar 29

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.