6 kyu

Santa's Missing Gift List

79 of 464omegahm

Description:

Santa has misplaced his list of gift to all the children, he has however a condensed version lying around.

In this condensed verison, instead of a list of gifts for each child, each one has an integer.

He also have a list of gifts corresponding to each integer. His list is as follows:

GIFTS = {
    1 => 'Toy Soldier',
    2 => 'Wooden Train',
    4 => 'Hoop',
    8 => 'Chess Board',
   16 => 'Horse',
   32 => 'Teddy',
   64 => 'Lego',
  128 => 'Football',
  256 => 'Doll',
  512 => "Rubik's Cube"
}
GIFTS = {
  1: 'Toy Soldier',
  2: 'Wooden Train',
  4: 'Hoop',
  8: 'Chess Board',
  16: 'Horse',
  32: 'Teddy',
  64: 'Lego',
  128: 'Football',
  256: 'Doll',
  512: "Rubik's Cube"
}

This list is made available to you, as GIFTS.

The integer for each child is such that the child should get the highest toy lower than or equal to that integer, and then, if there's more left, also get the highest toy lower than the rest and so on. Know that Santa never gives the same gift twice.

For example, by Timmy's name is 160. This means that Timmy should get both a football and a teddy, because 128 + 32 = 160.

You should help Santa by decoding his own list and recreate the missing list for him. Santa's elf wants the list sorted alphabetically by the toys, so you should help them as well and list the toys in a sorted order.

Binary
Algorithms

More By Author:

Check out these other kata created by omegahm

Stats:

CreatedDec 7, 2015
PublishedDec 7, 2015
Warriors Trained818
Total Skips25
Total Code Submissions1664
Total Times Completed464
Ruby Completions79
Python Completions272
JavaScript Completions134
Total Stars23
% of votes with a positive feedback rating95% of 165
Total "Very Satisfied" Votes152
Total "Somewhat Satisfied" Votes11
Total "Not Satisfied" Votes2
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • omegahm Avatar
  • St3f4n Avatar
  • user5036852 Avatar
  • saudiGuy Avatar
Ad