9
0
Introduction
I have some ASCII cars that have velocity and direction. Their velocity is represented by their number. If a car is <>
then it has stopped. For example:
<>
1>
2>
3>
After one second, I get
<>
1>
2>
3>
After two, I get
<>
1>
2>
3>
If two cars are too close, they crash.
1> <1
1> <2
After a second, this becomes
###
##
If two cars intersect, they become hashtags were they would be.
If one car is fast enough to 'hop' over the other, it does not result in a crash.
3><1 2><1 4><>
becomes
<13> ### <>4>
If a car goes left off-screen, it disappears (unless there's a crash). There is no way for a car to go right off-screen.
<11>
<1 1>
1 1>
1>
Challenge
Based on the given car physics, you must create a program that can time-step one second into the future. The input will be cars with spaces and a maximum velocity of 5 (matching regex (<[1-5]|[1-5]>|<>| )+
). The simulation will happen on one line, however that line has no fixed size.
Test cases
<> 1> 2> 3> 4> 5>
<> 1> 2> 3> 4> 5>
1><1 1> <1 1> <1
## ### 1><1
2><2 2> <2 2> <2 2> <2 2> <2
<22> ### ## ### 2><2
<22> <1 3> <2
### ##
<><> 1><> 2><> 3><> 4><> 5><>
<><> ### ## ### <>4> <> 5>
<><1 <2 <3 <4 <5
###<2<3<4<5
Scoring
This is code-golf, so code with the smallest number of bytes wins!
1<22> <1 3> <2 2 ### ## 2 should not be there - there are other problemts with the outputs – DanielIndie – 2018-03-31T07:19:29.557
1i would suggest adding "<><1 <2 <3 <4 <5" "###<2<3<4<5" to the testcases - case were a crush happens but and other cars "touching" but not part of it – DanielIndie – 2018-03-31T08:06:21.730
@DanielIndie That's an interesting one. I went ahead and edited the challenge. – Arnauld – 2018-03-31T08:12:28.217
It costs me some time to know
<>
mean one of velocity 0 – l4m2 – 2018-03-31T13:00:41.540Sorry! I added that in after writing everything so I forgot to explain it. – Nathan Wood – 2018-03-31T13:02:28.547
Is it possible that more than two cars crash together? – l4m2 – 2018-04-17T01:34:50.900
@l4m2. Yes. If they intersect, then they all become hashes. – Nathan Wood – 2018-04-17T23:45:37.373