Skip to content

Instantly share code, notes, and snippets.

View scarecrow1123's full-sized avatar

ananda seelan scarecrow1123

View GitHub Profile
"""finds the shortest path that an ant could take to reach a point from another
constraint: the ant can move only to the right or up at any point
"""
grid_order = 4
grid = {}
index = {}
rev_index = {}
adj_list = {}
"""takes a list x and returns a list with odd integers or elements with even index"""
[i for idx,i in enumerate(x) if (type(i) is int) and (i%2 !=0 or idx%2==0)]
@scarecrow1123
scarecrow1123 / sort_set_bits.py
Created February 20, 2016 10:07
Sort a list based on the number of set bits in each digit
def count_set_bits(i):
return bin(i).count('1')
def sort_set_bits(lst):
"""sorts a list based on the number of set bits in each digit"""
return sorted(lst, key=count_set_bits)
@scarecrow1123
scarecrow1123 / complete_graph.py
Last active February 20, 2016 10:08
Make a complete graph - Python one liner
def make_complete_graph(num_nodes):
"""takes number of nodes and returns a dict that represents
a complete graph(no self loops) with num_nodes"""
return {x: set([(lambda y: y)(y) for y in xrange(num_nodes) if y!= x]) for x in xrange(num_nodes)}
#remove the y!=x condition for self loops
@scarecrow1123
scarecrow1123 / tmux.md
Created January 5, 2016 08:01 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a