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.180 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.179 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.178 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.177 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.176 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.175 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.174 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.173 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.172 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.171 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.170 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.169 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.167 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.166 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.165 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.164 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.163 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.162 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.161 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.160 tracks/c/exercises/allergies/src/example.c