Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Automatic commit at Wed Oct 8 13:00:00 EDT 2014
Browse files Browse the repository at this point in the history
  • Loading branch information
jeapostrophe committed Oct 8, 2014
1 parent 87a76b4 commit b31482b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions isort-cost.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#lang racket
(require math/base
plot)

(define (isort-cost n is)
(cond
[(zero? n)
0]
[else
(if (first is)
(+ (sub1 n)
(isort-cost (sub1 n) (rest is)))
(+ 1
(isort-cost (sub1 n) (rest is))))]))

(define (average l)
(if (empty? l)
0
(/ (sum l) (length l))))

(define (list-with-m-trues-and-n-elements n m)
(build-list n (λ (x) (< x m))))

(define (perms-with-m-trues-and-n-elements n m)
(remove-duplicates (permutations (list-with-m-trues-and-n-elements n m))))

(module+ test
(remove-duplicates (permutations (list-with-m-trues-and-n-elements 5 3))))

(module+ main
(plot-new-window? #t)
(parameterize ([plot-title "Insertion Sort Cost"]
[plot-x-label "n"]
[plot-y-label "i"]
[plot-z-label "cost"])
(plot3d
(contour-intervals3d (λ (n i)
(argmax (λ (x) x)
(map (λ (p)
(isort-cost (floor n) p))
(perms-with-m-trues-and-n-elements (floor n) (floor (min n i))))))
0 8
0 8))
(plot3d
(contour-intervals3d (λ (n i)
(* n n))
0 8
0 8))))

0 comments on commit b31482b

Please sign in to comment.