33
6
The scenario
You live in a country that is having a presidential election. Each voter gets one vote, and therefore there is a firmly-entrenched two-party system. (Third parties exist, but get hardly any votes).
The latest opinion poll shows the race in a dead heat:
- 49%: Alberto Arbusto
- 49%: Jorge Sangre
- 2%: various minor candidates
The program requirements
You have been hired by the government to write part of the vote counting software. You will be given, on standard input, an unordered list of one precinct’s votes, one per line, like this:
Alberto Arbusto
Jorge Sangre
Jorge Sangre
Alberto Arbusto
Jorge Sangre
Alberto Arbusto
Alberto Arbusto
Jorge Sangre
Juan Perez
Jorge Sangre
Alberto Arbusto
Alberto Arbusto
…
and, after it has read all the votes, outputs a summary of how many votes each candidate got, sorted in descending order by number of votes, like this:
492 Jorge Sangre
484 Alberto Arbusto
18 Juan Perez
6 Mickey Mouse
The underhanded part
You're a partisan hack who wants to steal the election for one of the two main candidates (you can choose which one). So, your program must deliberately print incorrect vote counts, with a systematic bias towards your favorite candidate.
Of course, you must do this is such a way that a person looking at your code or its output would likely not recognize the incorrect behavior.
1
I'm voting to close this question as off-topic because underhanded challenges are no longer on-topic on this site. http://meta.codegolf.stackexchange.com/a/8326/20469
– cat – 2016-04-18T12:40:54.6872How about let the person running the program choose who he/she wants to bias to? This 1: makes the challenge less broad (a good thing), 2: makes the answers more interesting (IMO) – Justin – 2014-06-20T04:52:54.540
1
...you can choose which one...
Can I choose the one whose name is the first? – user80551 – 2014-06-20T05:24:14.563@user80551: You mean the first in the file? Yeah, I suppose that could work, with a concerted effort to tell members of your party "Make sure you're the first in line at the voting booth." – dan04 – 2014-06-20T05:49:58.383
@dan04 I think user80551 really talks about the one ACTUALLY winning xD – Marcos Besteiro López – 2014-06-20T07:12:01.090
2By "biased" you mean that the candidate we prefer must be elected, or thar the program will simply output and higher number of votes for him than the one actually contained in the input file? – None – 2014-06-20T09:06:39.897
3It might be difficult to justify a long program in Bash, given that a non-underhanded program to count votes in this format would literally just be
sort|uniq -c
... – None – 2014-06-20T09:40:58.663not quite actually, probably
sort|uniq -c|sort -gr
– None – 2014-06-20T09:48:36.5971@Alessandro: It simply needs to output a higher number of votes for him (and/or a lower number of votes for his opponent) than what's actually in the input. The election is assumed to be close enough that a small error could swing it. – dan04 – 2014-06-20T13:59:56.657
Can you put a file of names so that we're working with the same data? – Kyle Kanos – 2014-06-20T14:17:56.087
does the sum of the counted votes must match the real number of total votes? – bolov – 2014-06-21T18:12:50.887
@bolov: It doesn't need to match exactly, but it should be close enough to not be obviously wrong. – dan04 – 2014-06-21T19:36:38.833