Skip to content

Instantly share code, notes, and snippets.

View sgtonkin's full-sized avatar

Sebastian Tonkin sgtonkin

View GitHub Profile
/* Write a function that computes Hamming
distance (# of characters that differ between
two strings.
example:
abcd
abdd
--X- = 1
*/
@sgtonkin
sgtonkin / gist:e55098cd07b8d0ed2577
Created April 15, 2015 21:46
Hamming distance problem
/* Write a function that computes Hamming
distance (# of characters that differ between
two strings.
example:
abcd
abdd
--X- = 1
*/
@sgtonkin
sgtonkin / gist:7ce78aa0a0e99632d10e
Created April 1, 2015 21:52
Hamming distance of two integers converted to binary
/* Write a function that computes Hamming
distance (# of characters that differ between
two strings) except instead of strings it
takes 2 integers that it converts to binary.
example: 5 is 101, 3 is 011 so the Hamming distance is 2.
// Input is going to be two positive integers
// Output is going to be the total number of characters
@sgtonkin
sgtonkin / gist:f711427dd231ff49d977
Last active August 29, 2015 14:17
Reverse linked list in place (solution)
/* Write a function that accepts a singly linked list and returns a
* reversed version of the original linked list "in place" (i.e. without
* creating a second linked list in memory).
* A -> B -> C
* C -> B -> A
* var nodeA = Node('A');
* var nodeB = nodeA.next = Node('B');
* var nodeC = nodeB.next = Node('C');
@sgtonkin
sgtonkin / gist:7ba53b8df93d6156787f
Created March 24, 2015 18:30
Reverse linked list in place
/* Write a function that accepts a singly linked list and returns a
* reversed version of the original linked list "in place" (i.e. without
* creating a second linked list in memory).
* A -> B -> C
* C -> B -> A
* var nodeA = Node('A');
* var nodeB = nodeA.next = Node('B');
* var nodeC = nodeB.next = Node('C');