Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,18 @@
;; recursive version (adapted from Racket)
(lib 'list) ;; list-delete
(define (sel-sort xs (x0))
(cond
[(null? xs) null]
[else (set! x0 (apply min xs))
(cons x0 (sel-sort (list-delete xs x0)))]))
(sel-sort (shuffle (iota 13)))
→ (0 1 2 3 4 5 6 7 8 9 10 11 12)
;; straightforward and more efficient implementation using list-swap!
(define (sel-sort list)
(maplist (lambda( L)
(first (list-swap! L (first L) (apply min L )))) list))
(sel-sort (shuffle (iota 13)))
→ (0 1 2 3 4 5 6 7 8 9 10 11 12)

View file

@ -0,0 +1,13 @@
;; sort an array in place
(define (sel-sort a (amin) (imin))
(define ilast (1- (vector-length a)))
(for [(i ilast)]
(set! amin [a (setv! imin i)]) ;; imin := i , amin := a[imin]
(for [(j (in-range (1+ i) (1+ ilast)))]
(when (< [a j] amin) (set! amin [a (setv! imin j)])))
(vector-swap! a i imin))
a )
(define a #(9 8 2 6 3 5 4))
(sel-sort a)
→ #( 2 3 4 5 6 8 9)