In this challenge, your task is to make write a program with less than 300 characters that takes a short paragraph or a few sentences that a candidate has said and output who said it.
Input: Can be taken as a parameter to a function, input to a program etc. It will be a short paragraph, properly punctuated.
Output: The candidate that you think it is. This could be one of
Ben Carson (1)
Ted Cruz (2)
John Kasich (3)
Marco Rubio (4)
Donald Trump (5)
Hillary Clinton (6)
Bernie Sanders (7)
I've left off the names of people who have dropped out as of March 1st. You may output the name itself, or, more conveniently, the number that corresponds to the name.
Scoring: Your score is the percentage of test cases you get right. Highest score wins. Ties (or perfect scores) are broken by code length as in a code golf.
The test cases can be pulled from:
http://www.presidency.ucsb.edu/debates.php
Click on each debate, both Democrat and Republican that has happened so far (before March 1st). Every paragraph is a test case, unless the "paragraph" is less than 20 characters long.
Here is code that pulls out the test cases from a particular page:
var t = $(".tools").parentNode.querySelectorAll("p");
var categ = {}, cur = 0;
for (var i = 0; i < t.length; ++i) {
var p = t[i], str = p.innerText;
if (p.querySelector("b")) {
cur = p.querySelector("b").innerText.replace(':', '');
str = str.replace(/^.*?:\s/, '');
}
str = str.replace(/\[applause\]/g, '')
if (str.length < 20) continue;
if (categ[cur] == null) categ[cur] = [];
categ[cur].push(str);
}
You can then do categ.SANDERS
to get a list of all the paragraphs that Senator Sanders has said.
You can discard anything that isn't said by the candidates listed above (e.g. categ.BUSH
or categ.CHRISTIE
).
Here is the file with all the test cases: https://drive.google.com/file/d/0BxMn8--P71I-bDZBS2VZMDdmQ28/view?usp=sharing
The file is organized by candidate
CANDIDATE CANDIDATE_LAST_NAME
(empty line)
Series of statements. Each paragraph is separated by (NEW PARAGRAPH)-
(empty line)
CANDIDATE NEXT_CANDIDATE_LAST_NAME
(empty line)
etc.
An example partial submission would be:
if (/ win | wall | great | beautiful/.test(p)) return 5;
if (/ percent | top one | rigged /.test(p)) return 7;
// etc. for all candidates
or
var words = p.split(' ');
// majority of words have less than 5 characters
if (words.length - words.filter(a => a.length < 5).length < 4) evidence[5]++;
// at the end
return /* index with the most evidence */
Here is a place where you can test javascript solutions: https://jsfiddle.net/prankol57/abfuhxrh/
The code uses the parameter p
to represent the phrase to classify. Example code that scores around 20% (guessing would get around 11%):
if (/ rigged | top | percent | Wall Street /.test(p)) return 'Sanders';
return 'Trump';
Exactly what I'm asking: Write a program/function in less than 300 characters that takes as input a phrase that a candidate has said and returns as output which candidate said it. Your score is the percentage of test cases you get right. Highest score wins.
Yes, I know that a lot of lines have [laughter]
or [cheering]
in them. These will not be removed. At worst, they are extra information you can ignore; at best, they are extra information you can use (e.g. I made this up, but maybe people laughter is evidence that Marco Rubio is speaking). The test cases are as they appear in the text file.