Sha256: 4685b794498870f1e2c89ed34bbf024389eaa570111295170f5396993a52d1c0

Contents?: true

Size: 639 Bytes

Versions: 396

Compression:

Stored size: 639 Bytes

Contents

#lang racket

(provide allergic-to? list-allergies)

(define allergies
  #hash(("eggs"         . 1)
        ("peanuts"      . 2)
        ("shellfish"    . 4)
        ("strawberries" . 8)
        ("tomatoes"     . 16)
        ("chocolate"    . 32)
        ("pollen"       . 64)
        ("cats"         . 128)))

(define codes
  (for/hash ([(k v) (in-hash allergies)])
    (values v k)))

(define (has-bit? n m)
  (> (bitwise-and n m) 0))

(define (allergic-to? name code)
  (has-bit? (hash-ref allergies name 0) code))

(define (list-allergies n)
  (for/list ([(code name) (in-hash codes)]
             #:when (has-bit? code n))
    name))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.179 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.178 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.177 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.176 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.175 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.174 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.173 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.172 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.171 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.170 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.169 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.167 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.166 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.165 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.164 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.163 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.162 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.161 tracks/racket/exercises/allergies/example.rkt
trackler-2.2.1.160 tracks/racket/exercises/allergies/example.rkt