9.2
Algorhythms
| (require algorhythms) | package: algorhythms |
A Racket library of algorithms and data structures.
1 Installation
Install from the Racket package catalog:
raco pkg install algorhythms |
Or from source:
git clone https://github.com/aryaghan-mutum/algorhythms.git |
cd algorhythms |
raco pkg install --link . |
2 Quick Start
(require algorhythms) (factorial 10) (encode-to-morse "SOS")
3 Math Functions
3.1 Combinatorics
procedure
(factorial n) → exact-nonnegative-integer?
n : exact-nonnegative-integer?
Returns the factorial of n.
(factorial 0) (factorial 5) (factorial 10)
3.2 Number Theory
procedure
(prime? n) → boolean?
n : exact-positive-integer?
Returns #t if n is prime, #f otherwise.
Returns the greatest common divisor of a and b.
Returns the least common multiple of a and b.
3.3 Arithmetic
procedure
(square n) → number?
n : number?
Returns the square of n.
procedure
(cube n) → number?
n : number?
Returns the cube of n.
Returns the absolute value of n.
4 Data Structures
4.1 Higher-Order Functions
Returns a list containing only elements of lst for which pred returns true.
Reduces lst to a single value by applying fn cumulatively.
Right-fold over lst with fn and initial value init.
Flattens a nested list structure into a single list.
procedure
(flatmap fn lst) → list?
fn : procedure? lst : list?
Maps fn over lst and flattens the result.
4.2 Sorting Algorithms
Sorts lst using the bubble sort algorithm.
Sorts lst using the insertion sort algorithm.
Sorts lst using the quicksort algorithm.
Sorts lst using the selection sort algorithm.
5 Encoding
procedure
(encode-to-morse str) → string?
str : string?
Encodes a string to Morse code.
(encode-to-morse "SOS") (encode-to-morse "HELLO")
procedure
(decode-from-morse morse) → string?
morse : string?
Decodes a Morse code string back to text.
6 Utilities
Returns a memoized version of fn that caches results.
(define fib-memo (memoize (lambda (n) (if (<= n 1) n (+ (fib-memo (- n 1)) (fib-memo (- n 2)))))))
Creates a lazy evaluation wrapper around thunk.
7 License
BSD-3-Clause License
Copyright (c) 2024, Anurag Muthyam