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