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.159 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.158 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.157 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.156 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.155 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.154 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.153 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.152 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.151 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.150 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.149 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.148 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.147 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.146 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.145 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.144 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.143 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.142 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.141 tracks/c/exercises/allergies/src/example.c
trackler-2.2.1.140 tracks/c/exercises/allergies/src/example.c