bjonnh
12/13/2020, 5:29 AMMarcin Wisniowski
12/13/2020, 6:00 AMbjonnh
12/13/2020, 6:20 AMbjonnh
12/13/2020, 6:20 AMbjonnh
12/13/2020, 6:20 AMilya.gorbunov
12/13/2020, 6:24 AMbjonnh
12/13/2020, 6:28 AMbjonnh
12/13/2020, 6:29 AMbjonnh
12/13/2020, 6:30 AMbjonnh
12/13/2020, 6:33 AMbjonnh
12/13/2020, 6:33 AMilya.gorbunov
12/13/2020, 6:50 AMx
in the system of equations
x mod Nk = Rk mod Nk
. Here Nk is the number of a bus and Rk is the negated offset in minutes of that bus departure.
The important constraint though, is that all Nk must be co-prime. Perhaps your solution is free from that constraint.bjonnh
12/13/2020, 6:53 AMbjonnh
12/13/2020, 6:53 AMilya.gorbunov
12/13/2020, 7:00 AM2,x,4
input with CRT, while your approach gives an answer.Kroppeb
12/13/2020, 7:27 AMKroppeb
12/13/2020, 7:27 AMKroppeb
12/13/2020, 7:28 AMandyb
12/13/2020, 11:01 AMNir
12/13/2020, 3:19 PMNir
12/13/2020, 3:19 PMandyb
12/13/2020, 3:22 PMNir
12/13/2020, 3:30 PMNir
12/13/2020, 3:31 PMandyb
12/13/2020, 3:33 PMNir
12/13/2020, 3:37 PMNir
12/13/2020, 3:38 PMfun combine(p: Pair<Long, Long>, q: Pair<Long, Long>): Pair<Long, Long> {
var current = p.first
while (departureDelay(current, q.second) != (q.first % q.second)) {
current += p.second
}
return current to p.second * q.second
}
Nir
12/13/2020, 3:38 PMNir
12/13/2020, 3:38 PMNir
12/13/2020, 3:40 PMfun departureDelay(time: Long, bus: Long) = ceil(time.toDouble() / bus).toLong() * bus - time
this function is pretty lazy. Inside combine I should really do modular math but this is easierNir
12/13/2020, 3:42 PMNir
12/13/2020, 3:42 PMandyb
12/13/2020, 5:26 PM3,x,x,5,x,7,x,....
Then convert this to busId + offset pairs like
(3,0), (5,3), (7,5), ....
If we combine the first 2 pairs then we know that each possible solution must be 15 (i.e. 3*5) apart but we don't know the offset,(say x) so list could be reduced to :
(15,x), (7,5), ....
If there was a formula to determine x we could solve just by running a reduce() function across the list of pairs and the solution would be the 'x' in the final value. We could also use divide-and-conquer to solve if the number of pairs was large.Kroppeb
12/13/2020, 5:49 PMandyb
12/13/2020, 5:52 PM