Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/izder456/schemesorts

Sorth Algos in Chicken Scheme
https://github.com/izder456/schemesorts

Last synced: about 2 months ago
JSON representation

Sorth Algos in Chicken Scheme

Awesome Lists containing this project

README

        

#+TITLE: Scheme Sorting Algos

* Table of Contents :TOC:
- [[#license][LICENSE]]
- [[#algorithms][Algorithms]]
- [[#bubble-sort][Bubble sort]]
- [[#quick-sort][Quick Sort]]

** LICENSE

+ Seriously... /do what you want/

#+begin_src txt :tangle LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004 (MODIFIED)

Modified (M) 2023 Izzy Meyer
Copyright (C) 2023 Izzy Meyer

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
1. I am done w/ this.
2. If this software breaks, fix it yourself. ( i warned you )
3. I am not your mom, and will not handhold you.
#+end_src

* Algorithms

** Bubble sort

#+begin_src scheme :tangle bubble.scm
;; Bubble Up
(define (bubble-up L)
(if (null? (cdr L))
L
(if (< (car L) (cadr L))
(cons (car L) (bubble-up (cdr L)))
(cons (cadr L) (bubble-up (cons (car L) (cddr L)))))))

;; Bubble Sort Over _Len(gth) of L(ist)
(define (bubble-sort LS)
(define (bubble-sort_len L N)
(if (= N 1)
L
(bubble-sort_len (bubble-up L) (- N 1))))
(bubble-sort_len LS (length LS)))

(define (generate-numbers start end)
(do ((i start (+ i 1))
(result '() (cons i result)))
((> i end) result)))

(display (bubble-sort (generate-numbers 1 10000)))
#+end_src

** Quick Sort

#+begin_src scheme :tangle quick.scm
(import srfi-1)

(define (quicksort LS)
(cond
((or (null? LS) ; empty list is sorted
(null? (cdr LS))) ; single-element list is sorted
LS)
(else
(let ((pivot (car LS)) ; Select the first element as the pivot
(rest (cdr LS)))
(append
(quicksort ; Recursively sort the lower partition
(filter (lambda (x) (< x pivot)) rest)) ; Select the smaller values
(list pivot) ; Add the pivot in the middle
(quicksort ; Recursively sort the upper partition
(filter (lambda (x) (>= x pivot)) rest))))))) ; Select the larger and equal values

(define (generate-numbers start end)
(do ((i start (+ i 1))
(result '() (cons i result)))
((> i end) result)))

(display (quicksort (generate-numbers 1 10000)))
#+end_src