Last ant on rod, C/C++ Programming

Assignment Help:
There are ''n'' ants on a ''n+1'' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving either in left direction (denoted by ''-1'') or in the right direction (denoted by ''1''). Whenever an ant crosses the boundary of the rod it falls off the rod. You are given the initial direction of the ants. Now, whenever two ants collide their direction switches, i.e. the ant going in left direction (''-1) changes it''s direction towards right (''1'') and the ant going in the right direction (''1'') changes it''s direction towards left (''-1''). Find last ant to fall off the rod.
Note: In case two ants are falling simultaneously in the end print the index of the lower indexed ant.

Related Discussions:- Last ant on rod

Padovan sequence, write a program to generate padovan sequence in c++

write a program to generate padovan sequence in c++

What difficulty does the namespace feature solve out?, A: Multiple provider...

A: Multiple providers of libraries might employ common global identifiers causing a name collision whereas an application attempt to link with two or more such libraries. The names

Assigment, Hi is there any chance to get assignment for fresher tutor

Hi is there any chance to get assignment for fresher tutor

Write a program that takes the image, Write a program that takes the image ...

Write a program that takes the image tracks.jpg and finds Canny edges, and then finds lines in these edges using the Hough transform. The easiest way to do this is to take the prog

Program to write c++ program, program to write superposition of waves using...

program to write superposition of waves using class and objects

What is inheritance, What is inheritance? Class, the vehicle, which is ...

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

Tree, Write algorithm and program for the conversion of a Tree to a Binary ...

Write algorithm and program for the conversion of a Tree to a Binary Tree

Single string programme, write a programme that allows a user to enter 5 di...

write a programme that allows a user to enter 5 distinct words and returns them as a single string

Write a c program to calculate the equation, Write a C program to calculate...

Write a C program to calculate the output Y for a given value of X for the following formula   Y=X 2 + 2X +3   #include stdio.h   void main()   {   char promt;   float y,x

Minimum shelves, write a program to find the minimum number of shelves

write a program to find the minimum number of shelves

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd