Can someone tell me how i can make arrival time counting (17:00) minus 22 minutes?
Arrival Time Time On Bay Time Off Bay
17:00
So every time when I put something in, say "time" I will get "time minus 25 minutes" in arrival.
In Excel, you can do simple arithmetic on time values. The difference between two times is a (fractional) number of days. For example, 0.25 represents a time difference of 6 hours.
As such, you can add/subtract a (fractional) number of days to a time. Example:
cell A1 is a fixed time value 17:00
cell A2 is a formula =A1-0.25; this will evaluate to 11:00
To work with minutes, you will have to convert the amount of minutes to an amount of days; just divide the amount of minutes by 1440.
So a time difference of 25 minutes is represented by 25/1440. Example:
cell A1 is a fixed time value 17:00
cell A2 is a formula =A1-25/1440; this will evaluate to 16:35
Related
Lets say we have the following fares available :
1 trip
2 trips
10 trips
unlimited weekend (saturday to sunday, not 2 days)
1 day
3 days
unlimited week (monday to sunday, not 7 days)
unlimited month (1st to last day of month)
... with a price for every one of them.
The problem is : **How to determine what set of subscriptions to chose given a date of arrival and a date of departure ? **
Lets say we want the solution for n between 1 and 8, n being the number of time we take the metro daily (so we assume we take the metro the same number of time every day)
For example it would say something like :
n = 1
Arriving on Friday 19th and leaving Thursday 23th, the best is taking the 1 trip, then the weekend, then the 2 trips (didnt calculate but you see the point)
n = 2
...
I have found examples with only 1 day, 2 days, 7 days fares with dynamic programming, but it looks a lot harder when you considerate the days of the week.
Thanks :)
I like to view this kind of dynamic program as finding a shortest path in a directed acyclic graph.
Each node of the graph encodes
what the current day is (either during the travel period or the day after), and
how many trips remain on trip-limited passes (at most n + 9).
Each arc represents either
purchasing a specific pass at a specific time (the length of the arc is the cost of this pass), or
using trip-limited passes to cover the day's trips (the length of the arc is zero).
The time-limited passes advance the day to the first day they no longer work. The trip-limited passes increase the number of remaining trips. The zero-cost arcs advance the day by one while decreasing the number of remaining trips by n.
Given the shortest path, it is easy to decode it to a plan for purchasing passes.
(P.S. I don't know what the rules are on, e.g., purchasing a week pass on a Tuesday for the rest of the week. Even if this is not allowed, you're going to want to put arcs for the time-limited passes that could have been purchased on a previous day during the travel period.)
I want to find the best common time to change the other times the least (that the sum of the differences is the lowest possible).
On input, I have the array of times.
On output, there should be the new, common time.
Note that the times can be not ordered and be absolutely different (e.g. 02:00, 02:30 and 03:30)
Example 1
Input: ["01:00", "02:00", "03:00", "04:00", "05:00"]
Output should be 03:00, because it's the best to change 01:00 to 03:00 (2 hours of change), 02:00 to 03:00 (1 hour of change), keep 03:00 the same, 04:00 to 03:00 (1 hour), and 05:00 to 03:00 (2 hours).
Example 2
Input: ["12:00", "13:00", "14:00"]
Output should be 13:00 - change 12:00 to 13:00 (1 hour) and 14:00 to 13:00 (1 hour)
Example 3 (tricky)
Input: ["23:00", "01:00", "02:00"]
Output should be 01:00 - change 23:00 to 01:00 (2 hours) and 02:00 to 01:00 (1 hour) (the tricky thing is 23:00 - the best time is not 13:00)
I tried functions that make the average of times, e.g. https://stackoverflow.com/a/52839039/19022995, but unfortunately it doesn't work
I would be really grateful for tips how to do this
Thank you in advance
Lemma: an optimal answer coincides with one of the given times.
To prove it, consider a solution that doesn't coincide with any of the given times. Try to move it a bit forward and then a bit backward. In at least one of the cases, the total difference does not increase. So, continue moving in that direction until you hit one of the given times.
What is left now is to write a function that computes the difference, taking wraparound from 23:59 to 00:00 into account.
After that, try every given time as a candidate answer, calculate the total difference for each, and pick the best one as the final answer.
In pseudocode:
time (h, m) = h * 60 + m
diff (t1, t2) = min (abs (t1 - t2), 60 * 24 - abs (t1 - t2))
t[0..n) = given times
total (x) = sum {diff (x, t[i])} for i in [0..n)
answer = arg min {total (t[i])} for i in [0..n)
One approach is to look for the smallest "window" containing all the times. To do this, sort the times (naively) and, consider each time as being the "first". For instance, in your third example, considering 1:00 as the first time would lead to a 22 hour window (because that makes the "last" time 23:00); considering 2:00 as the first time would lead to a 23 hour window; but considering 23:00 as the first time would lead to a 3 hour window. From there, simply calculate relative to that first time, calculating differences mod 24.
If I am given the total number of occurrences of an event over the last hour, and I can get this data at arbitrary times ( but at least once an hour ), how can I work out the total number of occurrences over a 24 hour period?
Obviously, you can't. For example -- if the first two observations overlap then it would be impossible to determine the number of kills during the overlap. If there is a time gap between the first two observations then there is no way to determine what happened during the gap. You could try to set up a system of equations -- but the resulting system will be underdetermined (but it could give you both a min and a max, which might be relevant).
Why not adopt a statistical approach? Let X = kills over a 1 hour period. This is a random variable. Estimate its expected value by sampling it at randomly chosen times and multiply your estimate by 24.
Suppose you need to schedule meetings for a CEO. There must be as many meetings (count, not duration) scheduled as possible.
The workday has a start time and end time.
There are certain blocks of time unavailable (lunch, etc.)
The input is a list of times. The durations are either 30, 60, or 90 mins.
My approach
Represent the day as a boolean array. The index is the time. Each array index represents 30 minutes. So day[0] represents 9am and day[1] represents 9:30am. day[1] = true means 9:30 is open and closed if false.
Have a counter variable to keep track of the current earliest free time. For each time, iterate through the list of meetings and see if current free time + meeting duration is open. Runtime is O(N*N).
Flaw
However, my method does not result in the highest possible number of meetings squeezed into a day. For example, I have a 120 minute free block, and potential meetings of 90, 60, and 60 minutes. My algorithm first iterates to the 90 minute meeting and schedules it, but there is a 30 minute free block wasted. Better would be to fit both 60 minute meetings in there instead.
Another idea
Get all combinations of potential meetings with a total duration of no more than 90 minutes, and keep track of the the maximum number of meetings. I believe this would have to be done via permutation and O(N*N!) for each free block. So the total runtime of this is O(N * N * N!).
I would appreciate any feedback and alternative solutions. Thanks!
I've got a new algorithm for you, that could be relatively simple to implement. First fit all the 90 min meetings, if some are left over, they would not fit. Now go through the 60 min meetings and place those. If you have some left over, find 90 min meeting with a 30 min window (there could not be 60 min window or the meeting would have fit) and replace it with 2 of the 60 min meetings. If there are still 60 min meetings left over, replace 2 consecutive 90 min meetings with 3 of 60 min. If there are still 60 min meetings left over, replace any 90 min meeting with 60 min meeting. Then go and place 30 min meetings to empty slots. If there are any left over, replace 90 min meetings with 3x 30 min. If there are more left over, replace 60 min meetings.
From what I know from the Knapsack problem is that there should be a polynomial solution and this seems to fit, so if this works, ... also if n is the number of free slots in schedule, this is capped at 6*n^2. It is independent of the number of meetings waiting to be scheduled.
I am trying to convert a timestamp in the format "yyyy-mm-dd" to an integer fiscal week. Currently, my algorithm is 4(k-1) + floor(d/7)+1 where k is the integer month and d is the integer day of the month. Saturday starts the new fiscal week.
This has some flaws and is incorrect. For instance consider Saturday, January 28th 2012:
My algorithm computes 5(which is correct).
Next consider, Friday February 3rd:
My algorithm computes 5(which is correct).
Now consider Saturday February 4th.
My algorithm computes 5(this is incorrect).
It appears my algorithm will always fail in between months and thus accumulate an increasing error.
How can I compute the correct fiscal week?
Compute the number of days elapsed before the beginning of the current month, add it to dd and then divide by 7. Finally, add 1 to the resulting number.
So for Feb 4th, the answer would be (31 + 4)/7 + 1 = 6.