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 14: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 b31482b commit 27da209
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions isort-cost.rkt
Expand Up @@ -2,16 +2,18 @@
(require math/base
plot)

(define (insert-cost n inverted?)
(if inverted?
n
1))

(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))))]))
(+ (insert-cost (sub1 n) (first is))
(isort-cost (sub1 n) (rest is)))]))

(define (average l)
(if (empty? l)
Expand All @@ -24,9 +26,6 @@
(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"]
Expand Down

0 comments on commit 27da209

Please sign in to comment.