Skip to content

Latest commit

 

History

History
23 lines (12 loc) · 1.02 KB

File metadata and controls

23 lines (12 loc) · 1.02 KB

Split the treasure

A crew of treasure hunters have acquired a chest of valuable gems. However they are so progressive they will only take the treasure if it can be split equally between them, otherwise they will just bury it again.

Each gem are represented by an integer which represents its value (in your choice of currency) and the treasure chest can be represented by a list of all the values.

E.g. [4, 4, 4] represents three gems each of value 4

Write a program that says whether the treasure can be split or not and how the treasure needs to be split

Example chests

[4,4,4] can be split between three treasure seekers with each one receive one gem

[27,7,20] can only be split between two treasure seekers

[6,3,2,4,1] can be split between two treasure seekers (8 each, [6, 2], [3,4,1]) but not between three or four

[3,2,7,7,14,5,3,4,9,2] can be split between four treasure seekers.

Bonus question

Given four treasure seekers and a chest with the following gems: [3,3,3,3,2,2,2,2,2,2,2,2]. Can the treasure be split?