Sha256: 4b74ce758710d8908fe21fdea83112a505f84713b24d9987fca22f0700771a3c

Contents?: true

Size: 660 Bytes

Versions: 133

Compression:

Stored size: 660 Bytes

Contents

#include "allergies.h"
#include <stdlib.h>

static const unsigned int scores[] = {
   1,
   2,
   4,
   8,
   16,
   32,
   64,
   128
};

bool is_allergic_to(allergen_t allergen, unsigned int score)
{
   return ((score & scores[allergen]) == scores[allergen]);
}

void get_allergens(unsigned int score, allergen_list_t * list)
{
   list->allergens = calloc(ALLERGEN_COUNT, sizeof(allergen_t));
   list->count = 0;

   for (allergen_t allergen = 0; allergen < ALLERGEN_COUNT; allergen++) {
      if (is_allergic_to(allergen, score)) {
         score -= scores[allergen];
         list->allergens[list->count] = allergen;
         list->count++;
      }
   }
}

Version data entries

133 entries across 133 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.77 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.76 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.75 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.74 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.73 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.72 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.71 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.70 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.69 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.68 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.67 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.66 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.65 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.64 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.63 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.62 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.61 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.60 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.59 tracks/c/exercises/allergies/src/example.c