Created
December 9, 2014 06:27
-
-
Save briandk/4cad2dfd32e783e2055c to your computer and use it in GitHub Desktop.
Inspired by Wil Doane, this is a probably broken function that's designed to take a list of 0s and 1s (say, from a matrix of indicator values like "single", "employed", "ownsHome") and generate a unique integer to represent that binary string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (logicalToBinary listOfZeroesAndOnes powerOfTwo runningSum) | |
(if (= (cdr listOfZeroesAndOnes) `()); Not sure if this is right, but it should be "if you've exhausted the list, | |
; implemented as "if the remainder of the list equals an empty list" | |
; http://stackoverflow.com/questions/9115703/null-value-in-mit-scheme | |
runningSum) | |
(else return (logicalToBinary (cdr listOfZeroesAndOnes) | |
(+ powerOfTwo 1) | |
(+ runningSum (* runningSum powerOfTwo))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I might have made some errors in the incrementation process too, but I think you see what I'm getting at. Recurse the function by:
(cdr listOfZeroesAndOnes)
(+ powerOfTwo 1)
(* runningSum powerOfTwo)
(+ runningSum [result of previous computation])