This challenge is inspired by xkcd:
Challenge:
You'll simulate the copying a large file (1 Gigabyte). The transfer rate will vary between 10 kB/second to 100 MB/second. Your task is to output the time remaining of the file transfer. The output should look like:
Time remaining: 03:12 (meaning it's 3 minutes and 12 seconds left)
Time remaining: 123:12 (meaning it's 2 hours, 3 minutes and 12 seconds left)
Time remaining: 02:03:12 (optional output, meaning the same as above)
Leading zeros need not be displayed for minutes and hours (optional), but must be shown for seconds. Showing the time remaining using only seconds is not OK.
The file transfer:
- The transfer rate will start at 10 MB/second.
- Every second, there will be a 30% chance that the transfer rate will change
- The new transfer rate should be picked randomly (uniform distribution) in the range
[10 kB/s, 100 MB/s]
, in steps of 10 kB/s.
Note: You don't need to actually copy a file.
You may choose to use: 1 GB = 1000 MB, 1 MB = 1000 kB, 1 kB = 1000 B
, or 1 GB = 1024 MB, 1 MB = 1024 kB, 1 kB = 1024 B
.
Output:
- You start at
01:40
, not01:39
. - You display the time after the transfer rate changes, but before anything is transferred at that rate
- The seconds should be displayed as integers, not decimals. It's optional to round up/down/closest.
- You should clear the screen every second, unless that's impossible in your language.
- The output should be constant:
Time remaining: 00:00
when the file transfer is over.
Example:
I have rounded up all decimal seconds. Assume the lines below are shown with 1 second in between, and the screen is cleared between each one:
Time remaining: 01:40 (Transfer rate: 10 MB/s)
Time remaining: 01:39 1 GB - 10 MB
Time remaining: 01:38 1 GB - 2*10 MB
Time remaining: 01:37 1 GB - 3*10 MB
Time remaining: 01:28:54 1 GB - 4*10 MB (TR: 180 kB/s)
Time remaining: 01:28:53 1 GB - 4*10 MB - 180 kB
Time remaining: 01:28:52 1 GB - 4*10 MB - 2*180 kB
Time remaining: 00:13 1 GB - 4*10 MB - 3*180 kB (TR: 75 MB/s)
Time remaining: 00:12 1 GB - 4*10 MB - 3*180 kB - 75 MB
Time remaining: 00:11 1 GB - 4*10 MB - 3*180 kB - 2*75 MB
Time remaining: 00:10 1 GB - 4*10 MB - 3*180 kB - 3*75 MB
Time remaining: 00:09 1 GB - 4*10 MB - 3*180 kB - 4*75 MB
Time remaining: 00:08 1 GB - 4*10 MB - 3*180 kB - 5*75 MB
Time remaining: 14:09:06 1 GB - 4*10 MB - 3*180 kB - 6*75 MB (TR: 10 kB/s)
Time remaining: 14:09:05 1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 10 kB
Time remaining: 00:06 1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 20 kB (TR: 88.110 MB/s)
Time remaining: 00:05
Time remaining: 00:04
Time remaining: 00:03
Time remaining: 00:02
Time remaining: 00:01
Time remaining: 00:00 <- Transfer is finished. Display this.
1:40
(or1:42
) not1:39
(or1:41
)"? \$\endgroup\$ – Jonathan Allan Feb 2 '17 at 20:571024
version, what are the step sizes we should be using? \$\endgroup\$ – Jonathan Allan Feb 2 '17 at 21:0000:00:10
for example? \$\endgroup\$ – AdmBorkBork Feb 2 '17 at 21:12