Algorhythms
1 Installation
2 Quick Start
3 Math Functions
3.1 Combinatorics
factorial
3.2 Number Theory
prime?
gcd-v1
lcm-v1
3.3 Arithmetic
square
cube
abs-v1
4 Data Structures
4.1 Higher-Order Functions
filter-v1
reduce-v1
foldr-v1
flatten-v1
flatmap
4.2 Sorting Algorithms
bubble-sort
insertion-sort
quick-sort
selection-sort
5 Encoding
encode-to-morse
decode-from-morse
6 Utilities
memoize
lazy
7 License
9.2

Algorhythms🔗ℹ

Anurag Muthyam

 (require algorhythms) package: algorhythms

A Racket library of algorithms and data structures.

    1 Installation

    2 Quick Start

    3 Math Functions

      3.1 Combinatorics

      3.2 Number Theory

      3.3 Arithmetic

    4 Data Structures

      4.1 Higher-Order Functions

      4.2 Sorting Algorithms

    5 Encoding

    6 Utilities

    7 License

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.

procedure

(gcd-v1 a b)  integer?

  a : integer?
  b : integer?
Returns the greatest common divisor of a and b.

procedure

(lcm-v1 a b)  integer?

  a : integer?
  b : integer?
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.

procedure

(abs-v1 n)  number?

  n : number?
Returns the absolute value of n.

4 Data Structures🔗ℹ

4.1 Higher-Order Functions🔗ℹ

procedure

(filter-v1 pred lst)  list?

  pred : procedure?
  lst : list?
Returns a list containing only elements of lst for which pred returns true.

procedure

(reduce-v1 fn init lst)  any/c

  fn : procedure?
  init : any/c
  lst : list?
Reduces lst to a single value by applying fn cumulatively.

procedure

(foldr-v1 fn init lst)  any/c

  fn : procedure?
  init : any/c
  lst : list?
Right-fold over lst with fn and initial value init.

procedure

(flatten-v1 lst)  list?

  lst : list?
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🔗ℹ

procedure

(bubble-sort lst)  list?

  lst : list?
Sorts lst using the bubble sort algorithm.

procedure

(insertion-sort lst)  list?

  lst : list?
Sorts lst using the insertion sort algorithm.

procedure

(quick-sort lst)  list?

  lst : list?
Sorts lst using the quicksort algorithm.

procedure

(selection-sort lst)  list?

  lst : list?
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🔗ℹ

procedure

(memoize fn)  procedure?

  fn : procedure?
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)))))))

procedure

(lazy thunk)  procedure?

  thunk : procedure?
Creates a lazy evaluation wrapper around thunk.

7 License🔗ℹ

BSD-3-Clause License

Copyright (c) 2024, Anurag Muthyam