The six main cast members of the American sitcom Friends all agreed that they would be paid the same salary throughout the run of the series (after season 2, at least). But that doesn't mean that they all had the same amount of air time or that they all interacted on screen with each other the same amount.
In this challenge, you'll write a program that could help determine which Friends friends were really the best.
Consider watching an episode or scene of Friends and noting down exactly who is on screen during each camera shot and for how long.
We'll abbreviate each character's name:
Then for every camera shot (or every time a character enters/exits the shot), we'll list who was on screen. For example:
504 CRS 200 J 345 MP 980 2000 CJMPRS
This is saying that:
- For 504ms, Chandler, Rachel, and Ross were on screen.
- Then for 200ms, Joey was.
- Then for 345ms, Monica and Phoebe were.
- Then for 980ms, none of the 6 main characters were on screen.
- Then for 2 seconds, all of them were.
(This is not from an actual clip, I made it up.)
Note that the following would be equivalent:
504 CRS 1 J 199 J 345 MP 980 2000 CJMPRS
To analyze which combinations of characters had the most screen time, we look at all 64 possible subsets of the 6 characters and total up the screen time they had. If everyone in a subset appears on screen during a camera shot, even if there are more characters than just the ones in the subset, the time for that camera shot is added to that subset's total screen time.
There's an exception for the empty subset - only the scenes with none of the 6 main characters are counted.
So the analysis of the example above would be:
980 2504 C 2200 J 2345 M 2345 P 2504 R 2504 S 2000 CJ 2000 CM 2000 CP 2504 CR 2504 CS 2000 JM 2000 JP 2000 JR 2000 JS 2345 MP 2000 MR 2000 MS 2000 PR 2000 PS 2504 RS 2000 CJM 2000 CJP 2000 CJR 2000 CJS 2000 CMP 2000 CMR 2000 CMS 2000 CPR 2000 CPS 2504 CRS 2000 JMP 2000 JMR 2000 JMS 2000 JPR 2000 JPS 2000 JRS 2000 MPR 2000 MPS 2000 MRS 2000 PRS 2000 CJMP 2000 CJMR 2000 CJMS 2000 CJPR 2000 CJPS 2000 CJRS 2000 CMPR 2000 CMPS 2000 CMRS 2000 CPRS 2000 JMPR 2000 JMPS 2000 JMRS 2000 JPRS 2000 MPRS 2000 CJMPR 2000 CJMPS 2000 CJMRS 2000 CJPRS 2000 CMPRS 2000 JMPRS 2000 CJMPRS
We can see that
J (just Joey) had 2200ms of screen time because he had 200 by himself and 2000 with everyone.
Write a program that takes in a string or text file such as
504 CRS 200 J 345 MP 980 2000 CJMPRS
where each line has the form
[time in ms] [characters on screen], and outputs the total amount of time that each of the 64 subsets of the 6 characters spent on the screen, where each line has the form
[total time in ms for subset] [characters in subset] (just as above).
The input can be taken as a string to stdin, the command line, or a function, or it can be the name of a text file that contains the data.
- The milliseconds numbers will always be positive integers.
- The character letters will always be in the order
- You can optionally assume there is a trailing space when there are no characters in the scene (e.g.
- You can optionally assume there is a trailing newline.
- The input will have at least 1 line and may have arbitrarily many.
The output should be printed or returned or written to another text file as a 64 line string.
- The lines may be in any order.
- The character letters do not need to be in the
- Subsets with 0ms total time do need to be listed.
- There may optionally be a trailing space after the empty subset total.
- There may optionally be a trailing newline.
(This problem can of course be generalized to more characters, but we'll stick with the 6
CJMPRS Friends characters.)
The shortest code in bytes wins.
Note that I actually enjoy Friends and don't think some characters are more important than the others. The statistics would be interesting though. ;)