12
\$\begingroup\$

Introduction

On BBC Radio 2, on Saturdays there's a show hosted by Tony Blackburn called Pick of the Pops. Here, Tony selects a random week from a random year (in the range 1960-1989), and plays the songs which were in the top 20 charts at the time.

Challenge

Given a list of songs played on one Pick of the Pops episode, you must determine the year which Tony has chosen.

Further Information

Input

The input will be given as a string (either by STDIN or function arguments), with each list item separated by a comma.

The input will sorted with the number one single first, carrying on in order until the list ends with the number 20 single.

On the actual show, Blackburn plays the charts for two different years. This will not be the case for your input, only the chart for your one year will be supplied.

If song usually has a comma in its name, then the comma will be omitted.

Output

Your output should simply be the year in the format YYYY (1989, 2365, 1901).

If for any reason, multiple years are found (say if the charts are form the first week of the year), then either select the first year or output both, comma separated.

Rules

You can read from either a file or the internet.

If you use the internet, you must only use pages on the website officialcharts.com.

Note: if you read from a Wikipedia page, the page must have been created before the 23rd of August 2015.

The charts will be from the national UK charts, not international or of any other country.

Your output must be in the range of 1960 - 1989.

Examples

Input

Ticket to Ride,Here Comes the Night,The Minute You're Gone,Concrete and Clay,Little Things,Catch the Wind,For Your Love,King of the Road,The Last Time,Pop Go the Workers,Bring It On Home to Me,Stop in the Name of Love,Times They Are A-Changin',You're Breakin' My Heart,I Can't Explain,I'll Be There,Everybody's Gonna Be Happy,It's Not Usual,A World of Our Own,True Love Ways

Output

1965

Winning

The person with the shortest program in bytes wins.

Note

At the moment, I'm still downloading all of the chart information, but you can use the following Python 2 code to retrieve the necessary information and create the file. (Requires the requests module)

import requests, re, datetime, time

date = datetime.date(1960,1,1)
prevyear=0
year = 1960

delay = # Set the delay yourself. So far 4 seconds still makes the download fail

while date.year != 1990:

    response = requests.get("http://www.officialcharts.com/charts/singles-chart/%d%02d%02d"%(date.year, date.month, date.day)).text
    time.sleep(delay)

    tags = re.findall("<a href=\"/search/singles/.+\">.+</a>", response)[:20]
    top20s = []

    for i in tags[:]:
        tag = re.sub("<a href=\"/search/singles/.+\">", "", i)
        tag = re.sub("</a>","",tag)
        top20s.append(tag)

    top20s = list(map(lambda x:x.replace(",",""), top20s))

    with open("songs.txt", "a") as f:
        if year != prevyear:
            string = str(year)+"\n"
        else:
            string = ""

        chart = ",".join(top20s)

        f.write(string+chart+"\n")


    prevyear = year
    date += datetime.timedelta(days=7)
    year = date.year
\$\endgroup\$
13
  • 18
    \$\begingroup\$ I'd suggest that you compile the information into one file, which would then be the only ressource everoyne can use. \$\endgroup\$
    – flawr
    Aug 24 '15 at 11:55
  • 2
    \$\begingroup\$ What to do about songs with commas in the title? Such as Walk, Don't Run by the Ventures (1960). \$\endgroup\$
    – Geobits
    Aug 24 '15 at 15:25
  • 1
    \$\begingroup\$ @Geobits The comma will be removed \$\endgroup\$
    – Beta Decay
    Aug 24 '15 at 15:26
  • 4
    \$\begingroup\$ The grammar in the title is like sandpaper against my brain. \$\endgroup\$
    – Alex A.
    Aug 24 '15 at 17:00
  • 1
    \$\begingroup\$ By the way, your username should be (for Greek accuracy) βήτα διάσπαση. \$\endgroup\$ Aug 9 '16 at 16:27
2
\$\begingroup\$

C# (277, 271, 223 compacted bytes)

After six years, this deserves an answer, so I'm going to make some assumptions:

  • The data is stored in the file: C:\songs.txt.
  • The songs for each week are stored on a new line in the following format:
    • yyyy:song,song,song,...

var @in = Console.ReadLine();
var d = File.ReadAllText(@"C:\songs.txt");
foreach (var w in d.Split('\n')) {
    var wd = w.Split(':');
    if (wd[1].Split(',').Any(a => @in.Split(',').ToList().Any(i => i.Equals(a)))) {
        Console.Write(wd[0]);
        break;
    }
}

Note: Compacted in this case means removing all line breaks and unnecessary whitespace. I'm retaining proper formatting for the sake of readability.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.