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
def evolve_cell(alive, neighbours): | |
if alive: | |
return neighbours in [2, 3] | |
return neighbours == 3 | |
def count_neighbours(alive_cells, position): | |
r, c = position | |
neighbours = [(r - 1, c - 1), (r - 1, c + 0), (r - 1, c + 1), | |
(r + 0, c - 1), (r + 0, c + 1), | |
(r + 1, c - 1), (r + 1, c + 0), (r + 1, c + 1)] |
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
my_dict = {i: i ** 2 for i in range(1, 11)} | |
-> {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} | |
my_dict[7] | |
-> 49 |
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
{ | |
birthday: '18-12', | |
name: 'Brad Pitt', | |
movies: ['Fight Club', 'Inglourious Basterds'] | |
} |
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
apps=( | |
vim | |
git | |
tree | |
php5 | |
) | |
# Loop over apps and install each one with default 'yes' flag |
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
<?php | |
$thing = $_GET['thing']; | |
$md5 = md5($thing); | |
$col1 = substr($md5, 0, 6); | |
$col2 = substr($md5, 6, 6); | |
$col3 = substr($md5, 12, 6); |
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
2000 || | |
2001 ||||||||| | |
2002 |||||||||| | |
2003 ||||||||| | |
2004 |||||||||||||| | |
2005 ||||||||||| | |
2006 |||||||| | |
2007 |||||||||| | |
2008 |||||||||||||| | |
2009 ||||||||||||||||||| |
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
<?php | |
// PHP 5.3 | |
$arr = array(); | |
$arr2 = array('a','b','c'); | |
$arr3 = array('a' => 2, 'b' => 4, 'c' => 8); | |
$arr4 = array(array('abc','def'), array(2,4,8), 16); | |
// PHP 5.4 | |
$arr = []; |
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
if x > 0: | |
var += 1 |
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
#1 reverse a string | |
assert 'Hello'[::-1] == 'olleH' | |
#2 reverse a sentence | |
assert ' '.join('bob likes dogs'.split(' ')[::-1]) == 'dogs likes bob' | |
#3 find the minimum in a list | |
assert min([10, 8, 6, 7, 3, 4]) == 3 | |
#4 find the maximum in a list |
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
class Grid: | |
def __init__(self, n): | |
self.n = n | |
self.size = pow(n, 2) | |
self.filled_in = set() | |
self.next = 1 | |
self.grid = [] | |
for i in range(n): | |
self.grid.append(['0'] * n) |
OlderNewer