Skip to content

Instantly share code, notes, and snippets.

@arikrak
Created February 11, 2013 16:34
Show Gist options
  • Save arikrak/4755592 to your computer and use it in GitHub Desktop.
Save arikrak/4755592 to your computer and use it in GitHub Desktop.
# Matthew Jee's (mcjee) solution to the Mancala challenge on the HackerRank Back-to-School Hackathon
def printNextMove(player, player1Mancala, player1Marbles, player2Mancala, player2Marbles)
if player == 1
mymarbles = player1Marbles
opmarbles = player2Marbles
else
mymarbles = player2Marbles
opmarbles = player1Marbles
end
overflows = []
scores = []
nets = []
mymarbles.each_index do |x|
n = mymarbles[x]
overflows[x] = [n-6+x, 0].max #works for n < 14
scores[x] = (n+x+7) / 13
extra = 0
landpos = x+mymarbles[x]%13
if landpos < 6
if mymarbles[landpos] == 0
extra += opmarbles[5-landpos]*0.25
end
end
nets[x] = scores[x]-(overflows[x]*0.3)**2+extra;
end
#print nets
max = -9999
maxindex = 0
mymarbles.each_index do |x|
if nets[x] >= max && mymarbles[x] > 0
max = nets[x]
maxindex = x
end
end
puts maxindex+1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment