Techgig gaming console

Techgig gaming console

A new type of computer game is launched in the market, which requires a special type of gaming console. Makers of the games has made a new generation gaming console with a very unique remote. The keys/Layout of remote is as shown below

This remote contains 12 keys with 2 nonfunctional keys. Each functional key has been given a unique label as shown above.





The Computer game for this console has N levels. There are certain moves in the game which are controlled using the remote. The keys for each moves changes with the number of levels i.e. number of keys for an operation is dependent on the game level, for example for third level, single move require three key [you have to press three keys in sequence for a move in third level]. A player can only press keys that are left, right, up or down to the current key and he is not allowed to press bottom row corner keys.

Suppose a player is at level 2. According to the rules he has to press 2 keys for a move (the number of keys is equal to the level). The possible Moves key will be ‘HH’, ‘HI’, ‘HG’, ‘HE’, ‘HJ’, ‘IF’ ,.. Etc

1. If a Move start from ‘J’, possible keys are ‘JJ’, ‘JH’ (count 2)

2. If a Move start from ‘H’, possible keys are ‘HH’, ‘HI’, ‘HG’, ‘HE’, ‘HJ’ (count 5)

3. If a Move start from ‘I’, possible keys are ‘II’, ‘IH’, ‘IF’ (count 3)

————-

————-

So for level 2, number of possible moves would be 36.

If a player is at level N, you have to find the total possible number of moves for that level.

Input/Output Specifications

Input Specifications:

Input is an integer N, which is level of the game

Output Specifications:

Output is an integer M, which is the total possible number of Moves

Examples

Example:

Input: 2

Output: 36

Solution in C# using dynamic programming:

using System;

using    System.Collections.Generic;

    public static int combinationCounts(int input1)

            {

                        //Write code here

                        System.Collections.Generic.SortedDictionary<string,char[]> myDictionary;

                        myDictionary = new SortedDictionary<string, char[]> { { “A”, new char[] { ‘A’, ‘B’,’D’ } },

                        { “B”, new char[] { ‘A’, ‘B’,’C’,’E’ } },

                        { “C”, new char[] { ‘F’, ‘B’,’C’ } },

                        { “D”, new char[] { ‘A’, ‘G’,’D’,’E’ }} ,

                        { “E”, new char[] { ‘F’, ‘B’,’D’,’E’,’H’ }} ,

                        { “F”, new char[] { ‘I’, ‘F’,’C’,’E’ }} ,

                        { “G”, new char[] { ‘D’, ‘G’,’H’ }} ,

                        { “H”, new char[] { ‘G’, ‘H’,’I’, ‘E’,’J’} } ,

                        { “I”, new char[] { ‘H’, ‘I’,’F’ }} ,

                        { “J”, new char[] { ‘H’, ‘J’ }}};

                         int[,] max = new int[input1,10];

        for(int i=0 ; i < 10 ; i++)

        {

            max[0,i]=1;

        }

        for(int i=1 ;i < input1;i++ )

        {

            int j=0;

            foreach (KeyValuePair<string, char[]> p in myDictionary)

            {

                int count=0;

                char[] temp =p.Value;

                for(int k=0 ; k < temp.Length;k++)

                {

                    count+=max[i-1,temp[k] – ‘A’];

                }

                max[i,j]=count;

                j++;

            }

        }

        int sum=0;

        for(int i=0;i<10;i++)

         sum+=max[input1-1,i];

         return sum;

            }

Resolving technical problems:

Solve your technical problems instantly

We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM

Mail your problem details at [email protected] along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.

12 thoughts on “Techgig gaming console”

  1. Ankit ,
    What part you couldn’t understand ?
    Can you debug & check & let me know any difficulty in understanding it .

    1. could you explain line by line please,, each line what exactly doing, please . i m weak in C .

      1. Ankit
        First I create a dictionary in which i save for every key , what is the next key a user can press.(adjacent keys as value)
        Now it use a dynamic approach.
        First number of moves for level 1 is calculated for every key.
        Then number of moves for level 2 is calculated for every key using level 1 data.
        Similarly number of moves for level n is calculated for every key.

    1. No Karina
      I don’t work in PHP.
      But it must be simple once you understand the above logic clearly.

  2. i could not understand

    for(int k=0 ; k < temp.Length;k++)
    {
    count+=max[i-1,temp[k] – ‘A’];
    }

    If it is possible. please could each level of result.
    for example : level 1 = 10 ,level 2 = 36 like..

  3. package com;

    import java.util.Map;
    import java.util.TreeMap;

    public class IgInfotech {

    public static void main(String[] args) {
    Map myDictionar= new TreeMap();
    myDictionar.put(“A”, new char[] { ‘A’, ‘B’,’D’ });
    myDictionar.put(“B”, new char[] { ‘A’, ‘B’,’C’,’E’ } );
    myDictionar.put(“C”, new char[] { ‘F’, ‘B’,’C’ });
    myDictionar.put(“D”, new char[] { ‘A’, ‘G’,’D’,’E’ });
    myDictionar.put(“E”, new char[] { ‘F’, ‘B’,’D’,’E’,’H’ });
    myDictionar.put(“F”, new char[] { ‘I’, ‘F’,’C’,’E’ });
    myDictionar.put(“G”, new char[] { ‘D’, ‘G’,’H’ });
    myDictionar.put(“H”, new char[] { ‘G’, ‘H’,’I’, ‘E’,’J’});
    myDictionar.put(“I”, new char[] { ‘H’, ‘I’,’F’ });
    myDictionar.put(“J”, new char[] { ‘H’, ‘J’ });

    int level=3;
    int[][] max = new int[level][10];

    for(int i=0 ; i < 10 ; i++)
    {

    max[0][i]=1; //level 1 count=1 for every 10 charcharactor of the keyboard

    }

    for(int i=1 ;i < level;i++ )
    {

    int j=0;

    for (String p: myDictionar.keySet()) //run 10 times
    {

    int count=0;

    char[] temp =myDictionar.get(p);

    for(int k=0 ; k < temp.length;k++)
    {
    System.out.println("DIFF START");
    System.out.print("A:"+('A'-'A'));
    System.out.print('B'-'A');
    System.out.print('D'-'A');
    System.out.println("DIFF END");
    count=count + max[i-1][temp[k] -'A'];//'A', 'B','D'
    // System.out.println("count:"+count+" max["+i+"- 1][temp["+k+"]-A]"+max[i-1][temp[k] -'A']);

    }

    max[i][j]=count;

    j++;

    }

    }

    int sum=0;

    for(int i=0;i<10;i++)

    sum+=max[level-1][i];

    System.out.println(sum);

    }

    }

    1. it is simple dynamic programming example.

      each level there is 10 keys. so we have taken 2 dimentional arry
      in which 1st demention represent level and send dimention represent place to hold the count of each kay.

      initially, when level=1 i.e
      a[0][0]=1,a[0][1]=1…….a[0][9]=1 . for each key in level one count=1

      now go the next level i.e level=2 and
      fill [1][0]=count. which is count of adjecent charactor
      which is obtained by substuting the value from the lower level array and keep on summing.

      i.e
      max[i-1][temp[k]-‘A’]
      max[previous-level][index of key in the initial count aaray]
      ….similarly substitue and store.

      finally the max get the sum of count of all the 10 key by passing the fixed current level number.

    2. Iam getting can u help me out
      CandidateCode.java:13: error: illegal start of expression
      public static void main(String[] args)
      ^
      CandidateCode.java:13: error: illegal start of expression
      public static void main(String[] args)
      ^
      CandidateCode.java:13: error: ‘;’ expected
      public static void main(String[] args)
      ^
      CandidateCode.java:13: error: ‘.class’ expected
      public static void main(String[] args)
      ^
      CandidateCode.java:13: error: ‘;’ expected
      public static void main(String[] args)
      ^
      5 errors

Comments are closed.