Skip to content

Instantly share code, notes, and snippets.

var binarySearch = Assessment.binarySearch = function(array, target){
var point = Math.floor(array.length / 2);
if( array[point] === target)
return target;
else if ( target > array[array.length -1] || target < array[0])
return -1;
else if( array[point] > target )
return binarySearch(array.splice(0, point - 1), target);
else if( array[point] < target )
return binarySearch(array.splice(point + 1, array.length - 1), target);
@AmaxJ
AmaxJ / gist:270069aef9e7b95e2924
Created March 3, 2015 16:54
dictionary inception
def inception(dictionary):
if isinstance(dictionary, dict):
new_dict = {key:value for key, value in dictionary.items()}
dictionary['self'] = new_dict
return dictionary
import sys
line = raw_input()
temp = [int(x) for x in line.split()]
row, column = temp
def rowValue(row):
if row > 2 and row % 2 == 1:
return ((row - 1)/2) * 10
elif row > 2 and row % 2 == 0:
@AmaxJ
AmaxJ / gist:a9dfdb2028455979fa5d
Created February 19, 2015 16:37
directory structure
-Libraries and webpages have unique directory structures.
Library:
<library name>
<library name>
-modules
__init__.py
#The main __init__.py imports all the things that the library requires.
#ex: https://github.com/kennethreitz/requests/blob/master/requests/__init__.py
@AmaxJ
AmaxJ / gist:11df41b065a1e937ab38
Created February 6, 2015 02:11
Installing packages in python
If pip isn’t installed install pip by going to the command line and typing:
>>>sudo easy_install pip
#sudo stands for super user d.
Once pip is installed you can install packages by typing:
>>>sudo pip install <package name>
@AmaxJ
AmaxJ / gist:849c766926fd08433196
Created January 16, 2015 02:50
Game damage engine
from random import randrange
class Player:
def __init__(self, name):
self.health = 100
self.name = name
self.dam = 0
def low_damage (self):
def isPrime(num):
prime = True
for x in range(2, num):
if num % x == 0:
prime = False
return prime
def nextPrime(num):
current = num + 1
while isPrime(current) != True:
@AmaxJ
AmaxJ / gist:5719a927dbfa937d2a51
Created January 15, 2015 22:33
primechecker
def isPrime(num):
prime = True
for x in range(2, num):
if num % x == 0:
prime = False
return prime
@AmaxJ
AmaxJ / main.py
Last active November 23, 2016 15:24
Abacus Program
#Abacus script
#Enter a value and have it printed out in abacus form
from numFinder import *
from rep import *
# checks if value is between 1 and 1 billion.
def valid_Num(num):
if num <= 1000000000 and num >= 0:
return True
else:
@AmaxJ
AmaxJ / gist:82cf68b8b2280e109a2f
Created November 15, 2014 18:02
Character search script
# a script that searches a 1st string for all the characters present in the 2nd string, and returns the 2nd string
# if each character is present in the 1st. Returns 'give me soemthing that's not useless next time.' if not all
#characters are found
def fix_machine(search, target):
n = len(target) - 1
while n > -1:
search.find(target[n])
n = n - 1