If I have two candidates and five voters, and the results of tendency to vote are:
[
[:John, :Clinton, -27],
[:John, :Bush, -8],
[:Raphael, :Clinton, -12],
[:Raphael, :Bush, -40],
[:Damon, :Clinton, 71],
[:Damon, :Bush, 4],
[:Elysee, :Clinton, 13],
[:Elysee, :Bush, -36],
[:Griffin, :Clinton, -1],
[:Griffin, :Bush, 11]
]
How do I look at each voter, and count the largest Tendency number as a vote for that candidate and store it in a variable for the final tally of votes per candidate?
Hello! And thanks so much for the responses. Not only am I new to programming, I'm also new to Stackoverflow so forgive me if I'm not editing properly.
Apologies.
Reading what you guys put, I don't even know what to do with them, so I'll put the code I came up with and try to explain better what am trying to achieve. Bear with me.
If I have:
def stump_speech
voter_list = {
John: "Progressive",
Raphael: "Conservative",
Damon: "Libertarian",
Elysee: "Independent",
Griffin: "Massachussetts Democrat"
}
end
and comparing it to:
candidate_list = {}
candidate_list = {
Clinton: "Democrat",
Bush: "Republican",
}
and what runs it is:
voter_list.each { |voter_name, politics|
candidate_list.each { |candidate_name, party|
if
politics == "Progressive" && party == "Republican"
voting_prob = rand(0..100) - 25
decision
elsif
politics == "Progressive" && party == "Democrat"
voting_prob = rand(0..100) - 75
decision
elsif
politics == "Conservative" && party == "Republican"
voting_prob = rand(0..100) - 75
decision
elsif
politics == "Conservative" && party == "Democrat"
voting_prob = rand(0..100) - 25
decision
elsif
politics == "Independent" && party == "Republican"
voting_prob = rand(0..100) - 50
decision
elsif
politics == "Independent" && party == "Democrat"
voting_prob = rand(0..100) - 50
decision
elsif
politics == "Libertarian" && party == "Republican"
voting_prob = rand(0..100) - 90
decision
elsif
politics == "Libertarian" && party == "Democrat"
voting_prob = rand(0..100) - 10
decision
elsif
politics == "Massachussetts Democrat" && party == "Republican"
voting_prob = rand(0..100) - 10
decision
elsif
politics == "Massachussetts Democrat" && party == "Democrat"
voting_prob = rand(0..100) - 90
decision
else
end
}
}
And it outputs the array above earlier posted, how do I grab the numbers, John's, example, so that it will count as a vote for Bush, and Raphael's for Clinton, etc., and throw those into an array I could play with for the final tally in determining the winner?
In the simplest way you can manage, please? Thanks so much! I'm ten days into this and even grasping concepts isn't easy yet - hoping not to get discouraged.