Tag Archives: functional programming

Greatest common denominator in Scheme.

Here I’ve implemented Euclid’s famous functions for calculating the greatest common denominator. I’ve also implemented a slight addition that allows us to calculate the integer coefficients x and y such that d = gcd(a, b) = ax + by. These algorithms were adapted from Thomas Cormen’s exercises on pages 859-860 of Introduction to Algorithms, 2nd [...]

Posted in Programming | Also tagged , , | Comments closed

Writing a simple PLT Racket program with a test case.

I’m considering deploying a small PLT Racket web server so I thought I should brush up on the most recent version of Scheme that I’m familiar with: PLT Racket. The following is a small sample program and the syntax for testing that function. #lang racket   (require test-engine/racket-tests)   (define (my-factorial x) (cond [(= x [...]

Posted in Programming | Also tagged , | Comments closed

Using reduce in Python.

Python has a built in operator called reduce. This is just another name for what a functional programmer would called a fold. They’re really useful, but you don’t know so until you actually need one. The easiest example to understand is listed below and is the same example provided on Python’s documentation. lon = [1, [...]

Posted in Programming | Also tagged , | Leave a comment