Skip to content

Instantly share code, notes, and snippets.

@winny-

winny-/p.rkt Secret

Created April 2, 2019 17:25
Show Gist options
  • Save winny-/a5fa271a0e066165c73ed6673a96340b to your computer and use it in GitHub Desktop.
Save winny-/a5fa271a0e066165c73ed6673a96340b to your computer and use it in GitHub Desktop.
#lang racket
(define keys '(1 2 3))
(define items '(4 5 6))
(define expected (hash 1 4
2 5
3 6))
(define (solution-1 x y)
(for/hash ([k x]
[v y])
(values k v)))
(define (solution-2 x y)
(apply hash (foldr (λ (a b acc)
(cons a (cons b acc)))
'() keys items)))
(module+ test
(require rackunit)
(check-equal? (solution-1 keys items) expected)
(check-equal? (solution-2 keys items) expected))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment