Skip to content

sowasred2012/Game-of-Thrones-Kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game of Thrones

There are 5 books in the A Song of Ice and Fire book series (so far):

  1. A Game of Thrones
  2. A Clash of Kings
  3. A Storm of Swords
  4. A Feast for Crows
  5. A Dance with Dragons

Each one costs £8 but, since everyone is obsessed with the TV show and the publisher wants to pump those new fans for cash, they're offering the following discounts:

  • 5% off when you buy two DIFFERENT books
  • 10% off when you buy three DIFFERENT books
  • 20% off when you buy four DIFFERENT books
  • 25% off when you buy five DIFFERENT books (so, all the books in the series)

For example, if you buy four books, and only three of them are different (maybe you're buying the duplicate for a mate or as a doorstop), you'd get a 10% discount on the three, and then you'd have to pay £8 additionally for the duplicate.

Given these rules, how much would this basket cost?

  • 2 copies of the first book
  • 2 copies of the second book
  • 2 copies of the third book
  • 1 copy of the fourth book
  • 1 copy of the fifth book

(the answer is £51.20)

I spent ages trying to figure out why the answer wasn't £51.60, but the solution is to figure out what the best combination of discounts is for the customer, what I did originally was look at it like this:

  • Discount 1: Books 1, 2, 3, 4, 5
  • Discount 2: Books 1, 2, 3

Which is wrong, as you can also look at it as two different collections of 4 different books i.e:

  • Discount 1: Books 1, 2, 3, 4
  • Discount 2: Books 1, 2, 3, 5

About

Figuring out the best possible price discount for a customer given certain rules.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages