Skip to content

Instantly share code, notes, and snippets.

@samth
Last active December 10, 2015 09:48
Show Gist options
  • Select an option

  • Save samth/4416277 to your computer and use it in GitHub Desktop.

Select an option

Save samth/4416277 to your computer and use it in GitHub Desktop.
Stocking draws
#lang racket
(define people '(liz steve aj marti david ann pat annie mae helen jane carl
sam katie will lindsey
))
(define last-year '((sam aj) (katie will) (liz jane) (aj liz) (steve marti) (pat steve) (mae katie)
(ann annie) (helen mae) (carl helen) (jane david) (annie carl)
(will sam) (david pat) (marti ann)))
(define cousins '(mae helen jane carl annie will katie sam lindsey))
(define cousins-last-year '((helen katie) (carl mae) (will sam) (annie helen) (jane annie) (katie jane) (sam carl) (mae will)))
(define cousins-siblings (let ([l '((helen jane)
(helen carl)
(jane carl)
(sam mae)
(sam katie)
(mae katie)
(will annie)
(will lindsey)
(annie lindsey))])
(append l (map reverse l))))
(define (run people last-year)
(let loop ([from (shuffle people)] [to (shuffle people)] [so-far null])
(cond [(null? from) so-far]
[(eq? (first from) (first to))
(loop (shuffle from) (shuffle to) so-far)]
[(or (member (list (first from) (first to)) last-year))
(loop (shuffle from) (shuffle to) so-far)]
[(member (list (first to) (first from)) so-far)
(loop (shuffle from) (shuffle to) so-far)]
[else
(displayln (list (first from) (first to)))
(displayln (list from to))
(loop (rest from) (rest to) (cons (list (first from) (first to)) so-far))])))
;; stocking draw results
(define l
'((ann marti)
(helen annie)
(jane mae)
(carl david)
(aj helen)
(david ann)
(liz carl)
(annie pat)
(mae aj)
(marti steve)
(pat liz)
(steve jane)))
(define (stocking-print)
(for ([pr l])
(printf "~a has ~a's stocking\n"
(string-titlecase (symbol->string (first pr)))
(string-titlecase (symbol->string (second pr))))))
(define cousin-draw
'((mae carl)
(carl katie)
(jane sam)
(katie will)
(annie mae)
(will helen)
(helen annie)
(sam lindsey)
(lindsey jane)))
(define (cousin-print)
(for ([pr cousin-draw])
(printf "~a has ~a\n"
(string-titlecase (symbol->string (first pr)))
(string-titlecase (symbol->string (second pr))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment