# Challenging Task: The Bar and the Ants

## Recommended Posts

Hi,

You have a bar which is exactly 1 meter long and very narrow.

Anywhere on this Bar you can drop Ants, as many you want. Every Ant have a speed of 0,1 m/s.

So if you drop an ant on the left side of the bar, and it goes to the right side, it takes 10 seconds.

If an Ant reaches the end, it fall off, if an ant collides with another ant, both change directions.

Now the Challenge:

Create a script where you can input the number of Ants you wanna drop onto the bar and which calculates the time from the point where the Ants start walking, to the point the last Ant fell off.

And for every number of ants, you have to calculate the longest possible walk time.

So first you have to think about, where you do have to set the starting positions and moving directions for every ant, but that should be clear after some thinking

Good luck

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

##### Share on other sites

So the ants move 0.1 meters per second? We need to know the length of a single ant, otherwise results may vary.

Also are they all dropped on the bar at the same time?

Can you start the ants in different directions?

Edited by weaponx

##### Share on other sites

We need to know the length of a single ant, otherwise results may vary.

Also are they all dropped on the bar at the same time?

Lets assume the ants have no length, cause this would make this more complicated. Just think of mathematical Points.

They are dropped at the same time. But dont include the drop time or anything, just the time when they all start to move, till the last one reaches the end of the bar.

Can you start the ants in different directions?

Yes of course, but remember you have to choose the places and moving directions so that you have the longest walking duration possible.

So just drop 100 Ants at the left side of the bar and let them all instantly walk left over the edge, is not intended

Btw weaponx: did you get my PM about the Battlefield Tool?

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

##### Share on other sites

heh, i knew this would be too difficult. So you never will know the suprising solution. A shame

But maybe there is one out there who could be smart enough...

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

##### Share on other sites

heh, i knew this would be too difficult. So you never will know the suprising solution. A shame

But maybe there is one out there who could be smart enough...

I would write some code up but I still don't see how the ants can have zero length, its illogical. It would be better to say the bar is 1 meter (100 cm) and the ants are 10 mm, giving us 100 ants on the bar.

If they have zero length then we can have an infinite number of them, which means they have the possibility of moving an infinite distance.

Edited by weaponx

##### Share on other sites

I would write some code up but I still don't see how the ants can have zero length, its illogical.

I get it. I think it makes more sense for them to be zero length because they fall off the edge when they get there. Otherwise, do they fall off when the front of the ant hits the edge, the back of the ant, or somewhere in the middle. Of course that still doesn't make me smart enough to answer the question. I'm imagining it like the Koopa Troopa's from Super Mario Brothers.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

##### Share on other sites

heh, i knew this would be too difficult. So you never will know the suprising solution. A shame

But maybe there is one out there who could be smart enough...

But you drop ants just on a single point of the bar? or you simultaneously drop ants at different positions? Because if so (single point), then you will never have two ants colliding, only if you drop them head to head, which is the same thing as you would drop them back to back (we suppose the time they need to rotate is 0).

And it's very simple from this point, if you think only of a 1m bar and dropping 2 ants, back to back on a certain point.

Edited by Kiti

##### Share on other sites

I assume wherever you drop them they start going to the end that's the furthest away. So if you drop one on the left and one on the right they will bump near the middleand each turn around then.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

##### Share on other sites

If the ants have no length and they can all be dropped at the same time at the same point, then the answer is 10 seconds. Drop them all at one end of the bar and they will all make it to the other end in 10 seconds. The total number of ants is irrelevant to the outcome of this problem.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - \$7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

##### Share on other sites

The first post states that we can drop as many ants, whereever we like, in either direction.

So first you have to think about, where you do have to set the starting positions and moving directions for every ant

Personally I would put 50 ants on the left side walking right, and 50 on the right side walking left.

The inner 2 ants would collide and turn around, they would each turn around and collide into the ones behind them. This would cause a ripple effect and the number of collisions would increase exponentially.

##### Share on other sites

If the ants have no length and they can all be dropped at the same time at the same point, then the answer is 10 seconds. Drop them all at one end of the bar and they will all make it to the other end in 10 seconds. The total number of ants is irrelevant to the outcome of this problem.

I think the key here is to get a center ant to bounce back and forth a number of times between several ants making it a lot longer than 10 seconds.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

##### Share on other sites

I think the key here is to get a center ant to bounce back and forth a number of times between several ants making it a lot longer than 10 seconds.

But you cannot do so unless you assume facts not presented in the problem. There is no specified length or width of the ants, and there is no specified width of the bar. It's either a trick question or it is missing a few details.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - \$7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

##### Share on other sites

But you cannot do so unless you assume facts not presented in the problem. There is no specified length or width of the ants, and there is no specified width of the bar. It's either a trick question or it is missing a few details.

I don't think the width of the bar is relevent, but the length is given (1 meter). I would assume the ants are single file.

##### Share on other sites

I don't think the width of the bar is relevent, but the length is given (1 meter). I would assume the ants are single file.

Okay... Even if the width of the bar is irrelevant, how can you calculate anything based on a single-file line without the length of each ant? If the length is 0, then they can all occupy the same point.

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - \$7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

##### Share on other sites

Okay... Even if the width of the bar is irrelevant, how can you calculate anything based on a single-file line without the length of each ant? If the length is 0, then they can all occupy the same point.

Think about the ants as points in a cordinate system where the position in the line is the x value or something.

Edit: Fixed image

Edited by monoceres

Broken link? PM me and I'll send you the file!

##### Share on other sites

This is different from what the OP asked:

Placed on a 1 meter long horizontal bar, an ant moving with a speed of 1 m/s, will fall off one end in at most 1 second. When two ants run into each other, they both turn around and keep running with the same speed. Suppose 1000 ants are placed on the bar arbitrarily and start running in arbitrary directions. How long will it take them all to fall off the bar ends? Assume that ants have zero size.

The OP said the ants move at 0,1 m/s (0.1 m/s) which would not solve the above riddle, it relies upon the ant moving the same distance in a second as the length of the bar.

## Create an account

Register a new account