My boss needs to know how long it takes to add together two integers. But, I don't like to work weekends, and I think its fair that my code doesn't either. The problem is, the boss is a demanding guy and thinks I should put in over time to make sure the time it takes stays the same, and I know he is going to check if the code works properly.
Can you write me a short program that:
- Accepts two integers, and returns the correct result of addition and times how long the it takes to perform the addition - this time should be plausible and based on the runtime of the code. However, if you need to sneak some operations between the timed code that makes it run slightly longer than it should this is permitted. You cannot however just output a fake time.
- Doesn't work on weekends in the codes local-time (it can't just return a wrong result, the code needs to break, error, or otherwise fail to execute)
- Isn't immediately obvious as to why it doesn't work on weekends
I know the first criterion is kind of weird, but I wanted to make sure people could import date/time libraries if needed, without raising suspicion for criteria 3. However, I'm sure there are some smart folk, so -10 characters to anyone who can do this, without using calendar functions from standard date libraries
Regarding 'standard date/time libraries'
Examples of standard datetime libraries include pythons datetime
, javascript date
object library, java.util.Date
and the like. Functions to calculate timedeltas for execution such as pythons timeit
module would not violate this criteia as the boss is expectng the code to to be timed. In some cases, these libraries will need to be imported to access any time functions, so its permitted to call functions that return the time since the start of the current epoch as an integer, but calendar functions that return structured datetime objects that can give separate hours, days, etc... are not allowed.
edit: Regarding Dan04's question, the code must meet these 4 criteria regarding when it will work or not work. You should also explain how your code checks the time, as the slack on Monday morning/Friday night should give some opportunity for some creative ways to shorten the code.
- must not work from 00:00:00 Saturday morning through 23:59:59 Sunday night.
- must always work from 06:00:00 Monday morning through 19:59:59 Friday evening
- can either work or not work from 00:00:00 Monday morning through 5:59:59 Monday morning
- can either work or not work from 20:00:00 Friday evening through 23:59:59 Friday night morning
edit2: By immediately obvious it must meet the following 3 criteria:
- Must not call a function that called
DayOfWeek
(or similar), without using it to calculate the time of the function. - Must not use Saturday or Sunday or their abbreviations in English.
- Must not use Sat or Sun (or in their alternate letter cases) without an identical named variable not used to determine the day of the week or when determining if the code should run.