Talk:Sorting algorithms/Stooge sort: Difference between revisions

problem with lisp code
No edit summary
(problem with lisp code)
Line 1:
Im having a bit of an issue with syntax apparently. I have the latest code here:
I was wondering if any of you can help me. I have implemented a few sorting algorithms in other languages but doing something as simple as the stooge sort seems to be confusing me. I am going this implementation in NewLisp for practice. I like the language so far but i seem to hit a snag in this latest code:
<lang NewLISPNewlisp>
 
(define (stoogesort L left right)(if (> ( L left ) ( L right )) (swap ( L left) ( L right )))
(ifdefine (>=stoogesort (+L left 1) right) L)
(println "list : " L " left: " left " right: " right " calc: " (- right (/ (- right (+ left 1))3)))
;;(round (/ right 3))
(stoogesortif (> ( L left ) (- L right )) (roundswap (/L rightleft) 3)))) (L right)
(stoogesortif (L< (+- left (round (/ right) 3))1) right)(print "hello")
(stoogesort(L left (- right (round/ (/- right 3(+ left 1))3)))L)
(stoogesort (L (+ left (round/ (/- right 3(+ left 1))3)) right))
(stoogesort (L left (- right (round/ (/- right (+ left 1))3))))) ))))))L)
 
 
 
 
 
(stoogesort (list 7 3 2 3 4 0 0 0 0 0) 0 9)
</lang>
 
(stoogesort (list 7 3 2 3 4 0 0 0 0 0) 0 95)
*******************
I get the following as output:
>
<lang NewLISP>
(lambda (L left right)
(if (> (L left) (L right))
(swap (L left) (L right)))
(if (>= (+ left 1) right)
L)
(stoogesort (L left (- right (round (/ right 3)))))
(stoogesort (L (+ left (round (/ right 3))) right))
(stoogesort (L left (- right (round (/ right 3))))) L)
 
ERR: illegal parameter type in function > : left
called from user defined function stoogesort
called from user defined function stoogesort
</lang>
It seems to never get to the recursive step. I'm wondering why as I did some other tests to see whats going on. I feel extremely dumb right now with such an algorithm....
--Michael Chrisco