Music is one of the things that unites us all. Let's see if we can tap in to that connection with a quick program. Given an input file that contains song lyrics for a song, find the most common set of lyrics aka the chorus. A set of lyrics is consecutive lines where those exact consecutive lines appear elsewhere in the song. If no chorus can be identified print out a funny message. If there is a tie feel free to print out either set.
This program can be a bit challenging to optimize. A naive solution is perfectly fine. The comments are always open to discussions and theories on how to solve the problem. No code required.
Comments:
Keemz - 10 years, 8 months ago
A very naive solution:
reply permalink
gulliver - 10 years, 8 months ago
So we want the longest set of consecutive lines that is repeated? As opposed to finding the set of consecutive lines that is repeated the most in the song (regardless of the length of the set)?
reply permalink
Max Burstein - 10 years, 8 months ago
No, you are correct. Sorry if the wording on that is a bit weird. You want the set of consecutive lines that is repeated the most in the song (regardless of the length of the set).
reply permalink
gulliver - 10 years, 8 months ago
Cool problem! Here's my attempt - hoping I understood it correctly :)
reply permalink
Adam - 10 years, 8 months ago
Here's my attempt at a Haskell version. It can probably be done a lot better...
reply permalink
Erik - 10 years, 8 months ago
Hi, first time posting. Love this website by the way. I've solved a number of them, but this is the first where I felt I had a decent approach.
A run-time test shows 10 000 iterations at 2.17s on my i5-3210M.
reply permalink
Max Burstein - 10 years, 8 months ago
Hey Erik! Thanks for the kind words. Glad you decided to post.
reply permalink
Kocsen - 10 years, 8 months ago
Python solution. I essentially split lyrics by groupings (blank line) and keep track of their count in a dictionary. The highest count is the chorus!
Worked with Happy by Williams, and a couple Bruno Mars Songs.
reply permalink