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.58 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.57 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.56 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.55 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.54 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.53 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.52 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.51 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.50 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.49 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.48 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.47 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.46 tracks/c/exercises/allergies/src/example.c