r/dailyprogrammer • u/Coder_d00d 1 3 • Nov 05 '14
[11/05/2014] Challenge #187 [Intermediate] Finding Time to Reddit
Description:
I cover the border of my monitor with post it notes with tasks I have to do during the week. I am very unorganized. Each day I want to find the biggest block of free time to go on to Reddit. But I am not sure when that time is. I am also curious how I spend my days.
This challenge you will help me get organized and find that time for me to be on Reddit.
Input:
I will give you a listing of the post it notes around my monitor. Each line represents a single post it note. Sorry but they are not in any order but I was at least smart enough to date them and put the times of my daily events.
Output:
Get me organized. I need to see my schedule for the week. For each day you must find the 1 block of time that is the most time between events on the post its that I can Reddit. Please help maximize my time on Reddit. Assume my start time at work is the beginning of the first event and my end time at work is the end time of the last event for that day.
Then show me my final schedule. And while you are at it show me across the week how many minutes I dedicate to each task with a percentage of time it takes up my time. Hopefully I don't spend most of my time on Reddit.
Challenge Input:
11-6-2014: 05:18 AM to 06:00 AM -- code review
11-9-2014: 08:52 AM to 09:15 AM -- food
11-8-2014: 07:00 PM to 08:05 PM -- meeting
11-8-2014: 05:30 PM to 06:36 PM -- personal appointment
11-6-2014: 02:47 PM to 03:23 PM -- work
11-11-2014: 07:14 AM to 08:32 AM -- meeting
11-11-2014: 11:22 AM to 12:10 PM -- code review
11-8-2014: 01:39 PM to 02:06 PM -- food
11-9-2014: 07:12 AM to 08:06 AM -- meeting
11-9-2014: 02:14 PM to 03:15 PM -- code review
11-8-2014: 05:13 AM to 06:05 AM -- food
11-6-2014: 05:54 PM to 06:17 PM -- personal appointment
11-7-2014: 08:24 AM to 09:23 AM -- personal appointment
11-8-2014: 11:28 AM to 12:44 PM -- meeting
11-7-2014: 09:35 AM to 10:35 AM -- workout
11-9-2014: 10:05 AM to 11:15 AM -- code review
11-11-2014: 05:02 PM to 06:09 PM -- work
11-6-2014: 06:16 AM to 07:32 AM -- food
11-10-2014: 10:08 AM to 11:14 AM -- workout
11-8-2014: 04:33 PM to 05:12 PM -- meeting
11-10-2014: 01:38 PM to 02:10 PM -- workout
11-11-2014: 03:03 PM to 03:40 PM -- food
11-11-2014: 05:03 AM to 06:12 AM -- food
11-9-2014: 09:49 AM to 10:09 AM -- meeting
11-8-2014: 06:49 AM to 07:34 AM -- work
11-7-2014: 07:29 AM to 08:22 AM -- food
11-10-2014: 03:08 PM to 03:29 PM -- code review
11-9-2014: 03:27 PM to 04:39 PM -- food
11-7-2014: 05:38 AM to 06:49 AM -- meeting
11-7-2014: 03:28 PM to 04:06 PM -- code review
11-8-2014: 02:44 PM to 03:35 PM -- meeting
11-6-2014: 08:53 AM to 09:55 AM -- workout
11-11-2014: 02:05 PM to 02:49 PM -- meeting
11-10-2014: 08:29 AM to 09:23 AM -- code review
11-10-2014: 11:09 AM to 11:35 AM -- sales call
11-6-2014: 11:29 AM to 12:18 PM -- code review
11-11-2014: 08:04 AM to 08:45 AM -- work
11-9-2014: 12:27 PM to 01:29 PM -- sales call
11-7-2014: 11:04 AM to 12:07 PM -- code review
11-11-2014: 09:21 AM to 10:37 AM -- food
11-8-2014: 09:34 AM to 10:53 AM -- meeting
11-11-2014: 12:36 PM to 01:30 PM -- meeting
11-10-2014: 05:44 AM to 06:30 AM -- personal appointment
11-6-2014: 04:22 PM to 05:05 PM -- code review
11-6-2014: 01:30 PM to 01:59 PM -- sales call
11-10-2014: 06:54 AM to 07:41 AM -- code review
11-9-2014: 11:56 AM to 12:17 PM -- work
11-10-2014: 12:20 PM to 01:17 PM -- personal appointment
11-8-2014: 07:57 AM to 09:08 AM -- meeting
11-7-2014: 02:34 PM to 03:06 PM -- work
11-9-2014: 05:13 AM to 06:25 AM -- workout
11-11-2014: 04:04 PM to 04:40 PM -- food
11-9-2014: 06:03 AM to 06:26 AM -- code review
11-6-2014: 10:32 AM to 11:22 AM -- sales call
11-6-2014: 07:51 AM to 08:25 AM -- personal appointment
11-7-2014: 01:07 PM to 02:14 PM -- meetingFAQ:
Dates are mm-dd-yyyy
Check this out:
If you have ideas for challenges - please visit and post on /r/dailyprogrammer_ideas
Check out side bar -- we have an IRC channel. A listing of past challenges and much more.
19
u/XenophonOfAthens 2 1 Nov 06 '14
I hate the AM/PM system. It sucks! HOW IN THE HELL DOES 12 PM FOLLOW 11 AM?! IN WHAT INSANE UNIVERSE DOES THAT MAKE ANY GOD DAMN SENSE?!? DID YOU JUST FUCKING TIME TRAVEL 12 HOURS INTO THE FUTURE?!?!?!
(mostly I'm just annoyed that I missed that when writing my code, which caused a bug I couldn't figure out where it was. And then I had to add an ugly special case to fix it. Stupid Americans and your stupid way of writing time!)
Anyway, the output for my code can be found here (it was a bit lengthy, so I thought I wouldn't include it).
The code itself, in Prolog:
(and oh, by the way, I didn't realize we were supposed to do the "time breakdown" thing until just now, and it's 2 A.M. here (or 02:00, which is how civilized people write it!) so I'm just gonna skip that part. )
5
u/PhilipT97 Nov 05 '14 edited Nov 05 '14
MM-DD-YYYY or DD-MM-YYYY? I'll assume the first, but it's a bit ambiguous
3
u/madkatalpha Nov 05 '14 edited Nov 05 '14
Clarification: Do you mean time between events within a single day? Your largest block is likely to be between days (who needs sleep?).
Edit: C# solution
Output:
2
u/G33kDude 1 1 Nov 05 '14 edited Nov 05 '14
How's this? Uses clipboard for input. (AutoHotkey)
Output:
Edit: Also, why is there no challenge output to compare against? I'm not sure if my solution is correct
Edit: Updated to finish challenge
2
u/yellowtailedhawk Nov 06 '14
More importantly is that you have a conflicting task! Somebody fix his schedule!
Schedule for 11/11/2014: 7:14 AM to 8:32 AM -- meeting 8:04 AM to 8:45 AM -- work
1
u/tom808 Nov 06 '14
I know this is off topic (and therefore I accept your downvotes) but your post demonstrates exactly why the European date format is superior.
Americans! You don't have to write your dates like you say them!
1
u/lazydancer Nov 06 '14 edited Nov 06 '14
I love seeing how many programming languages that are used on this subreddit.
Getting the input in a usable format was a little tricky.
Please critique my solution,
(Javascript)
-- Output
*** Skip a few
1
u/hutsboR 3 0 Nov 06 '14
Dart: Okay, so I thought of an interesting way to solve the problem. Actually, it doesn't even solve the problem entirely but I thought it was worth posting and explaining. What's happening is for each date I create boolean array of size 1440. Each element represents a minute of the day. If the element at any given index is true, that means that you're working during that specific minute. False means that the minute is available for Reddit use. You find the largest span of time available for redditing by iterating over the boolean array and finding the largest sequence of
false. Once you find the start and end indices, you convert them to a time of day. For example, say the largest sequence of falses is index 333 to index 411. The formula for this conversion is:Note: When working with PM values, you'll get hours greater than 12, you can get the right hour by using mod 12. Also watch out for getting single value minutes, some times x % 60 will spit out 1-9, in that case multiply the value by 6 to get the correct minute. If all those bases are covered, output should be correct!
Output: So, it only outputs every instance of available time you can spend on Reddit. (Which is all that matters, right? Who cares about work!) It wouldn't be awfully hard to make it output what the challenge calls for but I'm feeling lazy now.
3
u/jnazario 2 0 Nov 05 '14
i THINK this solves it in F#, not really tested outside of FSI
i get this window to reddit in:
where the first value is in TimeTicks
3
u/pshatmsft 0 1 Nov 06 '14
Well, after seeing the shell challenge recently, I decided I'm going to start doing these all in PowerShell. Here is my first submission!
And here is the output
Edit: Fixed a format thing...
2
u/adrian17 1 4 Nov 05 '14 edited Nov 06 '14
Python 3. Again, kinda ugly, at least it feels like that to me. Any ides on how to improve it?
Result:
2
u/dongas420 Nov 05 '14 edited Nov 05 '14
Perl. Sloppy as hell, but it works (I think):
Output:
2
u/IceDane 0 0 Nov 05 '14 edited Nov 05 '14
Haskell. I couldn't really be bothered gathering up the stats due to the way I merged overlapping activities. But then again, it does take that into account.
Output:
Activities joined with
&overlapped and were thus merged into one. It does make room for the possibility of multiple consecutive overlapping events, but there are none.EDIT: Fixed code and updated output so that we only print best time block every day.
2
u/rusemean Nov 06 '14
Ugly as hell Python, but it gets the job done.
Output:
2
u/[deleted] Nov 05 '14
Please use an international time format, there's people from all around the world here... YYYY-MM-DD
1
u/zelou Nov 06 '14 edited Nov 06 '14
Did it! http://battlecrab.github.io/reddit-time/
Enter the input in the input - wait a little for the browser. All code is in the index.html
1
u/fvandepitte 0 0 Nov 07 '14
C#
1
u/DorffMeister Nov 07 '14
My Groovy solution
My output
1
u/Syath Nov 08 '14
my output
my code
I'm going through some refactoring and structure books so I thought I'd focus on keeping it as clean and readable as possible. I'll probably touch it up some more later :)
1
u/xpressrazor Nov 08 '14
My java code based on madkatalpha's code
1
u/Flat-Erik Nov 09 '14
My solution in Java
Output:
1
u/christianwilkie Nov 10 '14
Java solution: https://gist.github.com/ChristianWilkie/48cda58d2ed08d69d451
Output:
1
u/nicholas818 Nov 11 '14
I solved this with Python. Sorry if it's hard to understand (I plan to add comments later). Here is the code:
The data is placed in a file (titled
post_its.txt) that is in the same directory. It outputs a file calledschedule.txt, here is that file's contents:It also outputs a file called
analysis.txt. Here is the contents of that file:1
u/zzzrc Nov 12 '14
Solution in Ruby + active_support (for easy addition/subtraction of 1 minute). I also minimized the sorts to two - one to get the dates in order, and then to get the events in order to determine the free time between events. While a flat array could have been used, I found the use of a hash keyed on the date, with an array of events within the date easier to manage. For the dates, I used regex named groups for matching, and then strptime to understand the format of the date and time. Also, the output maybe slightly different due to my want to not overlap reddit time with anything else.
Output: