-
-
Save distributedlife/7301907 to your computer and use it in GitHub Desktop.
snippets for improve this from november 2013 - p2 magazine
This file contains hidden or 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
| a = [[], [], [], []] | |
| width = 10 | |
| length = 4 | |
| stones = 2 # or 3 | |
| for i in range(length): | |
| for j in range(width): | |
| a[i].append(stones) | |
| if i == 1 and j == width - 2: | |
| a[i][j] = 1 | |
| if i == 1 and j == width - 1: | |
| a[i][j] = 0 | |
| if i == 2 and j == 0: | |
| a[i][j] = 0 | |
| if i == 2 and j == 1: | |
| a[i][j] = 1 | |
| if stones == 3: | |
| if i == 1 and j == width - 3: | |
| a[i][j] = 2 | |
| if i == 2 and j == 2: | |
| a[i][j] = 2 |
This file contains hidden or 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
| for i in range(length): | |
| for j in range(width): | |
| a[i].append(stones) |
This file contains hidden or 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 array(stones, length): | |
| return [stones]*length | |
| a = map(array, ([tincuva]*width, length)) |
This file contains hidden or 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
| a[1][width - 2] = 1 | |
| a[1][width - 1] = 0 | |
| a[2][0] = 0 | |
| a[2][1] = 1 | |
| if stones == 3: | |
| a[1][width - 3] = 2 | |
| a[2][2] = 2 |
This file contains hidden or 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
| a[1][-3] = 2 | |
| a[1][-2] = 1 | |
| a[1][-1] = 0 | |
| a[2][0] = 0 | |
| a[2][1] = 1 | |
| a[2][2] = 2 |
This file contains hidden or 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
| width = 10 | |
| length = 4 | |
| stones = 2 # or 3 |
This file contains hidden or 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
| board = [[], [], [], []] | |
| def set_board_up(length, breadth, tincuva): | |
| board = map(array, ([tincuva]*breadth, length)) | |
| board[1][-3] = 2 | |
| board[1][-2] = 1 | |
| board[1][-1] = 0 | |
| board[2][0] = 0 | |
| board[2][1] = 1 | |
| board[2][2] = 2 | |
| return board |
This file contains hidden or 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
| board[1][-1], board[2][0] = 0, 0 | |
| board[1][-2], board[2][1] = 1, 1 | |
| board[1][-3], board[2][2] = 2, 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment