Recent Automata AMCAT questions answers

Recent Automata AMCAT questions answers

SHARE:

Hello here is a solution of a problem asked in automata AMCAT exam. The solution is in C++ but logic can be applied to any programming language.

Hello here is a solution of a problem asked in automata AMCAT exam. The solution is in C++ but logic can be applied to any programming language.

Problem: There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour). Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes inactive the next day, otherwise it becomes active the next day.
Assumptions:

The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumsed to be always inactive.
Even after updating the cell state. consider its previous state for updating the state of other cells. Update the cell information of all cells simultaneously.

Write a function cellCompete which takes takes one 8 element array of integers cells representing the current state of 8 cells and one integer days representing te number of days to simulate.

An integer value of 1 represents an active cell and value of 0 represents an inactive cell.

program:
int* cellCompete(int* cells,int days)
{/
/write your code here
}
//function signature ends
Recent Automata AMCAT questions answers
Example automata AMCAT fig
TESTCASES 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]
TESTCASE 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]
#include<iostream>
using namespace std;

int cellCompete(int *cells ,int day){
//write your code here

for (int i=0;i<day;i++){
 
 cells[-1]=0; //assumptions
 cells[8]=0;//assumptions
 int u[8]; //another array to copy value
 for (int i=-1;i<9;i++){
 u[i]=cells[i]; 
 }
 
 for(int j=0;j<8;j++){
 if(u[j-1]==u[j+1]){ //comparing the value of the neighbouring cells of u[]
 cells[j]=0; //changing value of cell according to condition
 }
 else
 cells[j]=1;
 } }
 
for (int i=0;i<8;i++){
cout<<cells[i];
}
return 0;}


int main(){ //main function
int days,cells[]={1,0,0,0,0,1,0,0}; //array to pass through function
int *cellsptr=cells; //creating array values to pointer
cout<<"enter days:"; //for days
cin>>days; 
cout<<"n[1,0,0,0,0,1,0,0]n";
cellCompete(cellsptr, days); //passing to function
return 0;
}

COMMENTS

BLOGGER: 1
  1. int* cellComplete(int* cells,int days){
    int previous = 0,i=0,j=0,temp=0;
    for(j=0;j<days;j++){
    previous = 0;
    for(i=0;i<8;i++){
    if(i==0){
    previous=cells[i];
    cells[i]=cells[i+1];
    continue;
    }
    if(i==7){
    temp=previous;
    previous=cells[i];
    cells[i]=temp;
    continue;
    }
    if(previous==cells[i+1]){
    previous=cells[i];
    cells[i]=0;
    }
    else{
    previous=cells[i];
    cells[i]=1;
    }
    }
    }
    }

    ReplyDelete

Related Articles

Name

Android,41,Blogger,24,Blogging,28,Business,21,Computer,71,Development,5,Games,5,Guest,330,Health,16,iOS,8,Marketing,11,Online Tools,1,Programming,25,SEO,68,Social,266,Software,4,Startup,13,Technology,21,Website,14,Wordpress,18,
ltr
item
MindxMaster: Recent Automata AMCAT questions answers
Recent Automata AMCAT questions answers
Hello here is a solution of a problem asked in automata AMCAT exam. The solution is in C++ but logic can be applied to any programming language.
https://2.bp.blogspot.com/-O_amnY3J7LY/WGEgQ-eDSVI/AAAAAAAADwE/O890ehWWuYM2JLBzMoeYDb3HyA_h3GPpQCK4B/s1600/amcat.jpg
https://2.bp.blogspot.com/-O_amnY3J7LY/WGEgQ-eDSVI/AAAAAAAADwE/O890ehWWuYM2JLBzMoeYDb3HyA_h3GPpQCK4B/s72-c/amcat.jpg
MindxMaster
https://www.mindxmaster.com/2015/11/recent-automata-amcat-questions-answers.html
https://www.mindxmaster.com/
https://www.mindxmaster.com/
https://www.mindxmaster.com/2015/11/recent-automata-amcat-questions-answers.html
true
5332415103371288268
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy