Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
50
Task/Sort-three-variables/TXR/sort-three-variables.txr
Normal file
50
Task/Sort-three-variables/TXR/sort-three-variables.txr
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
(defmacro sort-places (. places)
|
||||
(caseql (len places)
|
||||
((0 1) nil)
|
||||
(2 (with-gensyms (p0 p1)
|
||||
^(placelet ((p0 (read-once ,[places 0]))
|
||||
(p1 (read-once ,[places 1])))
|
||||
(if (greater p0 p1)
|
||||
(swap p0 p1)))))
|
||||
(3 (with-gensyms (p0 p1 p2)
|
||||
^(placelet ((p0 (read-once ,[places 0]))
|
||||
(p1 (read-once ,[places 1]))
|
||||
(p2 (read-once ,[places 2])))
|
||||
(if (greater p0 p1)
|
||||
(swap p0 p1))
|
||||
(if (greater p1 p2)
|
||||
(swap p1 p2))
|
||||
(if (greater p0 p1)
|
||||
(swap p0 p1)))))
|
||||
(t (let ((gens [mapcar (ret (gensym)) places]))
|
||||
(with-gensyms (vec)
|
||||
^(placelet ,(zip gens places)
|
||||
(let ((,vec (vec ,*gens)))
|
||||
(nsort ,vec)
|
||||
(set ,*(append-each ((g gens)
|
||||
(i 0))
|
||||
^(,g [,vec ,i]))))))))))
|
||||
|
||||
(prinl (sort-places))
|
||||
|
||||
(let ((x 1))
|
||||
(sort-places x)
|
||||
(prinl x))
|
||||
|
||||
(let ((x 2)
|
||||
(y 1))
|
||||
(sort-places x y)
|
||||
(prinl (list x y)))
|
||||
|
||||
(let ((a 3)
|
||||
(b 2)
|
||||
(c 1))
|
||||
(sort-places a b c)
|
||||
(prinl (list a b c)))
|
||||
|
||||
(let ((a 4)
|
||||
(b 3)
|
||||
(c 2)
|
||||
(d 1))
|
||||
(sort-places a b c d)
|
||||
(prinl (list a b c d)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue