Skip to content

Instantly share code, notes, and snippets.

@erkin
Created July 21, 2019 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkin/7177dec72fdd0c76232f301cf3de9a49 to your computer and use it in GitHub Desktop.
Save erkin/7177dec72fdd0c76232f301cf3de9a49 to your computer and use it in GitHub Desktop.
#lang racket/base
(define-syntax-rule (assert expr)
(unless expr
(raise-user-error "Assertion failed: " (quote expr))))
(define (factorial n)
(if (zero? n)
1
(* n (factorial (sub1 n)))))
(define (permutations n k)
(if (< n k)
0
(/ (factorial n) (factorial (- n k)))))
(define (combinations n k)
(/ (permutations n k)
(factorial k)))
(assert (= (combinations 7 3) 35))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment