Skip to content

Instantly share code, notes, and snippets.

def ArithGeo(arr):
diff = arr[1] - arr[0]
multiple = arr[1]/arr[0]
isarith = True
isgeom = True
for i in range(0,len(arr)-1):
d = arr[i+1] - arr[i]
if d!=diff:
isarith = False
m = arr[i+1] / arr[i]
1. When the input was new Array(1,2,3,4) your output was incorrect.
2. When the input was new Array(2,6,18,54) your output was incorrect.
3. When the input was new Array(1,2,3,4,5,10,20) your output was incorrect.
4. When the input was new Array(1,2,3,4,5,6,7,88,2) your output was incorrect.
5. When the input was new Array(100,200,400,800,1600) your output was incorrect.
6. When the input was new Array(10,110,210,310,410,511) your output was incorrect.
7. When the input was new Array(10,110,210,310,410) your output was incorrect.
8. When the input was new Array(5,10,20,40,80) your output was incorrect.
9. When the input was new Array(-3,-4,-5,-6,-7) your output was incorrect.
10. When the input was new Array(1,5,9) your output was incorrect.
<div style='float:left;'>
Basil Masri
</div>
<div style='float:right'>
XXXXXXX
</div>
<div style='clear:both'></div>
#define B_0000 0
#define B_0001 1
#define B_0010 2
#define B_0011 3
#define B_0100 4
#define B_0101 5
#define B_0110 6
#define B_0111 7
#define B_1000 8
#define B_1001 9
/* borrowed partially from: http://stackoverflow.com/a/7577517/277800 */
#define B_0000 0
#define B_0001 1
#define B_0010 2
#define B_0011 3
#define B_0100 4
#define B_0101 5
#define B_0110 6
#define B_0111 7
#define B_1000 8
// get the x coordinate for bit set on the board.
// b must have exactly 1 bit set or else the behavior is undefined.
uint getX() {
static uint x_precomputed[67] =
{
0, 7, 6, 0, 5, 0, 7, 0,
4, 3, 7, 4, 6, 4, 7, 1,
3, 0, 2, 5, 6, 1, 3, 3,
5, 1, 3, 4, 6, 3, 0, 0,
2, 7, 0, 1, 1, 1, 4, 5,
@cammckinnon
cammckinnon / gist:2369233
Created April 12, 2012 17:12
FizzBuzz (brainfuck)
Write fizz to memory using cells 0 to 5 inclusive
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<<
Write buzz to memory using cells 6 to 11 inclusive
>>>>>>
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<<
Cell 12 wil
@cammckinnon
cammckinnon / gist:2369288
Created April 12, 2012 17:19
FizzBuzz (C)
#include <stdio.h>
int main() {
int i = 1;
for (; i <= 100; i ++) {
if (i % 3 == 0)
printf("Fizz");
if (i % 5 == 0)
printf("Buzz");
if (i % 3 != 0 && i % 5 != 0)
@cammckinnon
cammckinnon / gist:2389359
Created April 15, 2012 02:14
English word patterns
# word pattern => list of corresponding english words
pattern_words = defaultdict(list)
def get_pattern(word):
"""Return the pattern for the given word."""
map = {}
letters = iter(string.lowercase)
pattern = ''
for char in word:
if char not in map:
@cammckinnon
cammckinnon / gist:2390022
Created April 15, 2012 04:28
backtracking
def find_mappings(cipher_words, mapping=defaultdict(lambda:None)):
"""Return a generator that iterates over mappings that
translate the words in cipher_words to english words."""
# no more cipher words to examine - return current mapping
if len(cipher_words) == 0:
yield mapping
return
# work with the first word