Talk:Sorting algorithms/Stooge sort: Difference between revisions

From Rosetta Code
Content added Content deleted
(problem with lisp code)
No edit summary
Line 3: Line 3:


(define (stoogesort L left right)
(define (stoogesort L left right)
(println "list : " L " left: " left " right: " right " calc: " (- right (/ (- right (+ left 1))3)))
(println "list : " L " left: " left " right: " right " calc: " (- right (/ (- right (+ left 1))3)))
(if (> ( L left ) ( L right )) (swap (L left) (L right)
(if (> ( L left ) ( L right ))
(if (< (- left right) 1) (print "hello")
(swap (L left) (L right)
(stoogesort(L left (- right (/ (- right (+ left 1))3))
(if (< (- left right) 1) (print "hello")
(stoogesort
(stoogesort(L (+ left (/ (- right (+ left 1))3)) right
(stoogesort(L left (- right (/ (- right (+ left 1))3)))))))))))L)
(L left (- right (/ (- right (+ left 1))3))
(stoogesort
(L (+ left (/ (- right (+ left 1))3)) right
(stoogesort(L left (- right (/ (- right (+ left 1))3)))))))))))
L)




Line 20: Line 24:
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....
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
--Michael Chrisco

:I do not know enough about Newlisp to be very helpful, but I formatted your code to better represent matching parenthesis. (I am stuck on: How does L work in the function position of a list when composing arguments for nested stoogesorts? Also, what modifies the L which you return from your defined function?) --[[User:Rdm|Rdm]] 15:19, 5 August 2010 (UTC)

Revision as of 15:19, 5 August 2010

Im having a bit of an issue with syntax apparently. I have the latest code here: <lang Newlisp>

(define (stoogesort L left right)

 (println "list : " L " left: " left " right: " right " calc: " (- right (/ (- right (+ left 1))3)))
 (if (> ( L left ) ( L right )) 
   (swap  (L left)  (L right) 
     (if (< (- left right) 1) (print "hello")
       (stoogesort
         (L left (- right (/ (- right (+ left 1))3))
           (stoogesort
             (L (+ left (/ (- right (+ left 1))3)) right
               (stoogesort(L left (- right (/ (- right (+ left 1))3)))))))))))
 L)




(stoogesort (list 7 3 2 3 4 0) 0 5)

</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

I do not know enough about Newlisp to be very helpful, but I formatted your code to better represent matching parenthesis. (I am stuck on: How does L work in the function position of a list when composing arguments for nested stoogesorts? Also, what modifies the L which you return from your defined function?) --Rdm 15:19, 5 August 2010 (UTC)