Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2fff16e198
Fetching contributors…

Cannot retrieve contributors at this time

96 lines (81 sloc) 1.873 kb
#lang racket
(define (poly-deg p)
(cdr (argmax cdr p)))
(define (addterms p n)
(λ (x acc)
(cons (+ (car x) (car acc)) (cdr acc)))
(cons 0 n)
(filter (λ (y) (equal? n (cdr y))) p)))
(define (poly-simp p)
(define deg (poly-deg p))
(filter (λ (x) (> (car x) 0))
(for/list ([pow (in-range deg -1 -1)])
(addterms p pow))))
(define (poly-mul p1 p2)
(for*/list ([x p1] [y p2])
(* (car x) (car y))
(+ (cdr x) (cdr y)))))
(define (mega-mul ps)
(foldl poly-mul (car ps) (cdr ps)))
(define (mkdie d)
(for/list ([i (in-range 1 (+ 1 d))])
(cons 1 i)))
(define (mkroll r)
(define n (car r))
(define d (cdr r))
(cons (mkdie d)
[(equal? n 1) empty]
[else (mkroll (cons (- n 1) d))])))
(define (push xs x)
(append xs (list x)))
(define (cool-round x y)
(define scalar (expt 10 y))
(/ (round (* x scalar)) scalar))
(define (args)
(define yarr
([yash '(() . 0)])
([arg yarr])
[(regexp-match #rx"d" arg)
(push (car yash)
(let ([y (regexp-split #rx"d" arg)])
(cons (string->number (car y)) (string->number (cadr y)))))
(cdr yash))]
(car yash)
(+ (cdr yash) (string->number arg)))])))
(define input (args))
(define rolls (car input))
(define addme (cdr input))
(define combinations
(λ (x sum) (+ sum (expt (cdr x) (car x))))
(define dist
(λ (x)
(cool-round (/ (car x) combinations) 5)
(cdr x)))
(λ (x) (cons (car x) (+ addme (cdr x))))
([ls '()])
([r rolls])
(append (mkroll r) ls))))))))
(for ([i dist])
(displayln (format "~a~a~a" (cdr i) #\tab (car i))))
Jump to Line
Something went wrong with that request. Please try again.