gpt-3.5-turbo-0314· OpenAI
Arena Human Preference 55K
Can you write a quicksort in scheme?
- User
Can you write a quicksort in scheme?
- Assistant
Yes, I can write a quicksort in Scheme. Here's an implementation:
(define (quicksort lst) (if (null? lst) '() (let ((pivot (car lst)) (rest (cdr lst))) (append (quicksort (filter (lambda (x) (< x pivot)) rest)) (list pivot) (quicksort (filter (lambda (x) (>= x pivot)) rest)))))) ; Example usage: (quicksort '(5 3 1 2 4)) ; Output: (1 2 3 4 5)The
quicksortfunction recursively partitions the input list into two parts: one with elements smaller than the pivot and another with elements greater than or equal to the pivot. It then concatenates the results of sorting the two parts along with the pivot element in the middle. Thefilterfunction is used to partition the list.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.