Perl: the Markov chain saw | |
PerlMonks |
Re: Challenge: A malicious electionby kyle (Abbot) |
on Jun 12, 2008 at 15:12 UTC ( [id://691679]=note: print w/replies, xml ) | Need Help?? |
Here's my feeble entry:
What's hard about this is that a correct solution is so simple. Here's one that works:
Vote counting and reporting take all of 15 lines with no golfing. Practically any deviation from a simple "stash in a hash" implementation is going to be suspicious. I think the best bet for really sneaking something in is to write a lot of bad code that mostly works. Another strategy might be to exploit a bug in some software that the machine uses (e.g., a MySQL bug) rather than have a bug in the machine itself. Anyway, it's an interesting "problem" but having skulked about the Monastery for a while, I can't imagine I'd get anything past the monks. Update: I should spoiler out an explanation. So, here's what my entry does "wrong": Keeping tallies as single element array references is a distraction. I thought I might write a bug based on using the wrong array reference, but I never did. The bug is in the validation loop. Because $candidate is set to a valid candidate on each iteration, it will be left with the last candidate's name if the user's input doesn't match any name. As such, the write-in branch is never reached, and all write-in or typo votes go to Eve. An earlier version left out the chomp so every vote went to Eve (because the dangling newline would thwart matching every candidate). I thought that was a more subtle bug, but it makes the election results too obviously wrong.
In Section
Meditations
|
|