Skip to content

Instantly share code, notes, and snippets.

@jkutner
Created December 6, 2010 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkutner/729760 to your computer and use it in GitHub Desktop.
Save jkutner/729760 to your computer and use it in GitHub Desktop.
def score(dukes, duchies)
duchies*3 + dukes*duchies
end
def play(dukes, duchies)
dukes_in_deck = 0
duchies_in_deck = 0
while (dukes > 0 and duchies > 0)
if score(dukes_in_deck+1, duchies_in_deck) >= score(dukes_in_deck, duchies_in_deck+1)
dukes_in_deck += 1
dukes -= 1
puts "duke -> #{score(dukes_in_deck, duchies_in_deck)}"
else
duchies_in_deck += 1
duchies -= 1
puts "duchy -> #{score(dukes_in_deck, duchies_in_deck)}"
end
end
end
play(8,8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment