16
This challenge is based off a riddle I read in some book a while ago, which I found again here. It is about bullets fired from a gun once per second at varying speeds that travel in a straight line forever. When one bullet hits another, both are destroyed completely. (Feel free to replace all instances of "bullet" with "missile".)
The Task
Given a list of bullet speeds in the order they're fired in, determine whether all bullets are destroyed.
The Rules
- Input is a list of non-negative integers, separated by any delimiter and with one optional character before and after. These are valid inputs:
1 2 3 4 5 6
and[1,2,3,4,5,6]
. The programmer makes the choice. - Output a truthy value if at least one bullet survives forever and a falsy value otherwise.
- Bullet speeds are given in units per second.
- Bullets move simultaneously and continuously.
- Bullets may collide at fractional offsets.
- Multiple bullets which simultaneously reach the exact same position, whether at an integral or fractional offset from the origin, all collide with each other.
Examples
In these diagrams, G
represents the gun, >
the bullets, and *
are times when bullets collide and explode.
Truthy
Input: 0
0123456789
Time 0 G>
1 G>
2 G>
...
Output: 1
Input: 0 0 0
0123456789
Time 0 G>
1 G*
2 G>
3 G>
4 G>
...
Output: 1
Input: 1
0123456789
Time 0 G>
1 G >
2 G >
3 G >
...
Output: 1
Input: 2 1
0123456789
Time 0 G>
1 G> >
2 G > >
3 G > >
4 G > >
...
Output: 1
Input: 2 3 1
0123456789
Time 0 G>
1 G> >
2 G> >>
3 G > *
4 G >
5 G >
...
Output: 1
Falsy
Input: 1 2 3 4 5 6
Unit 1111111111
01234567890123456789
Time 0 G>
1 G>>
2 G> *
3 G> >
4 G> > >
5 G> > >>
6 G > > *
7 G > >
8 G > >
9 G >>
10 G *
111111111122222222223
0123456789012345678901234567890
Output: 0
Input: 1 0 0 3
Unit
0123456789
Time 0 G>
1 G>>
2 G* >
3 G> >
4 G >>
5 G *
(The second collision is at time 4.5)
Output: 0
Input: 2 1 2 3 6 5
Unit 1111111111
01234567890123456789
Time 0 G>
1 G> >
2 G>> >
3 G> * >
4 G> > >
5 G> * >
6 G > >
7 G > >
8 G >>
9 G *
1111111111
01234567890123456789
Output: 0
Input: 2 3 6
Unit
0123456789
Time 0 G>
1 G> >
2 G> >>
3 G *
Output: 0
can i require input be delimited like
1<enter>2<enter>3...
? – cat – 2015-12-10T12:39:41.467@sysreq: That's pushing it, but I'll allow it. – El'endia Starman – 2015-12-10T21:26:20.867
I agree with qunitopia - this challenge is wicked hard, but I'm working on a solution... – zmerch – 2015-12-11T14:31:24.960