Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active October 11, 2018 22:49
Show Gist options
  • Save harrisonmalone/36ba07dc216f3d26c7d1015b3c8dc5e8 to your computer and use it in GitHub Desktop.
Save harrisonmalone/36ba07dc216f3d26c7d1015b3c8dc5e8 to your computer and use it in GitHub Desktop.

Allergies challenge

An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).

The list of items (and their value) that were tested are:

  • eggs (1)
  • peanuts (2)
  • shellfish (4)
  • strawberries (8)
  • tomatoes (16)
  • chocolate (32)
  • pollen (64)
  • cats (128)

So if Tom is allergic to peanuts and chocolate, he gets a score of 34.

Write a program that, given a person's score can tell them:

a) whether or not they're allergic to a given item, and

b) the full list of allergies

Allergies tom = new Allergies(34);
tom.allergic_to('chocolate');
=> true
tom.allergic_to('cats');
=> false
tom.list();
=> ['peanuts', 'chocolate']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment