Skip to content
Prev 343570 / 398506 Next

Bus stop sequence matching problem

Adam Lawrence <alaw005 <at> gmail.com> writes:
Adam,

Yet another way...

See inline code. BTW, you should have mentioned that you are
a transit planner or included a signature block so folks would know this
is not a homework question.

As others have noted/hinted, there are some unstated assumptions, so
you need to try some test cases to be sure any solution always works.

You only have one outbound/inbound cycle in stop_onoff, right??
If not, I think almost any approach can fail given the right
sequence of 'seq's.
Start here:
seq ref on off load
1  10   A  5   0    5
2  20   B NA  NA   NA
3  30   C NA  NA   NA
4  40   D  0   2    3
5  50   B 10   2   11
6  60   A  0   6    5

You can take care of turning the NA's to zeroes or '-'s, I think.

HTH,

Chuck