The following data contains the (approximate) population of each UTC timezone in the world (source):
UTC;Population (in thousands)
-11;57
-10;1853
-9.5;8
-9;639
-8;66121
-7;41542
-6;272974
-5;332101
-4.5;31923
-4;77707
-3.5;499
-3;248013
-2;4855
-1;3285
0;285534
+1;857443
+2;609921
+3;496279
+3.5;81889
+4;129089
+4.5;31042
+5;305642
+5.5;1458945
+6;199668
+6.5;50112
+7;439650
+8;1679526
+9;220112
+9.5;1814
+10;29482
+11;5267
+11.5;2
+12;6112
+13;308
+14;11
(for the sake of simplicity, I'm removing +X.75
UTC times from the list)
Assuming that every person in the world wakes up at 8AM and goes to sleep at midnight (in their local time), how many people are simultaneously awake in the world at a given UTC time?
For example, suppose the given time is 2PM UTC. These are the timezones where the local time at 2PM UTC is between 8AM inclusive and midnight exclusive:
-6 08:00 272974
-5 09:00 332101
-4.5 09:30 31923
-4 10:00 77707
-3.5 10:30 499
-3 11:00 248013
-2 12:00 4855
-1 13:00 3285
+0 14:00 285534
+1 15:00 857443
+2 16:00 609921
+3 17:00 496279
+3.5 17:30 81889
+4 18:00 129089
+4.5 18:30 31042
+5 19:00 305642
+5.5 19:30 1458945
+6 20:00 199668
+6.5 20:30 50112
+7 21:00 439650
+8 22:00 1679526
+9 23:00 220112
+9.5 23:30 1814
Now, just add the population of these timezones and output 7818023 (corresponding to ~7.8 billion people).
Input
An UTC time. You may accept two natural numbers h and m, where 0 ≤ h ≤ 23 and m ∈ {0, 30}.
Standard I/O applies, so you can accept them as lists, strings, etc. You can even accept m as a boolean value, where 0 means HH:00
and 1 means HH:30
.
There are two ways of solving this question: hardcoding the output (since there are only 48 possible inputs) or hardcoding the population data and solving by time arithmetic. However, to make this challenge more interesting, you are allowed to accept the population data as an additional input, so you don't need to hardcode it (thus saving you some bytes) and focusing only on the time arithmetic. So you can read it as additional lines from STDIN or an additional function argument.
Output
How many people are awake at the given time, in thousands.
Test cases
00:00 -> 3024211
00:30 -> 3024211
01:00 -> 3460576
01:30 -> 3510688
02:00 -> 3705501
02:30 -> 5164446
03:00 -> 5222075
03:30 -> 5252618
04:00 -> 5304000
04:30 -> 5353966
05:00 -> 5518144
05:30 -> 5518144
06:00 -> 5855091
06:30 -> 5855091
07:00 -> 6670992
07:30 -> 6670992
08:00 -> 6890405
08:30 -> 6890405
09:00 -> 6893051
09:30 -> 6893043
10:00 -> 6896034
10:30 -> 6896034
11:00 -> 7143682
11:30 -> 7144181
12:00 -> 7215776
12:30 -> 7247697
13:00 -> 7574531
13:30 -> 7574531
14:00 -> 7818023
14:30 -> 7816209
15:00 -> 7637639
15:30 -> 7637639
16:00 -> 6024234
16:30 -> 6024234
17:00 -> 5585223
17:30 -> 5535119
18:00 -> 5337315
18:30 -> 3878370
19:00 -> 3573093
19:30 -> 3542051
20:00 -> 3419074
20:30 -> 3337187
21:00 -> 2846175
21:30 -> 2846175
22:00 -> 2265736
22:30 -> 2267550
23:00 -> 1630219
23:30 -> 1630219
Try to make your code with the fewest bytes as possible.
[boolean m, h]
, same order as your tests). \$\endgroup\$