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
""" | |
11/24/2018 | |
Dumb backtracking-based solver for the Cracker Barrel Triangle Peg game. | |
http://recmath.org/pegsolitaire/CBTips.html | |
This solution is generic to any N-row triangle. | |
Doesn't assume any heuristic and also very memory intensive. | |
""" |
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
#!/usr/bin/env bash | |
# Blog post: http://bekt.github.io/p/gae-sdk/ | |
API_CHECK=https://appengine.google.com/api/updatecheck | |
SDK_VERSION=$(curl -s $API_CHECK | awk -F '\"' '/release/ {print $2}') | |
# Remove the dots. | |
SDK_VERSION_S=${SDK_VERSION//./} | |
SDK_URL=https://storage.googleapis.com/appengine-sdks/ |
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
Jobs,Steve,3/3/1993,Steve Ballmer | |
Ballmer,Steve,2/2/1992,Bill Gates | |
Gates,Bill,1/1/1990, | |
Wozniak,Steve,4/4/1994,Steve Jobs | |
Bekt,Kanat,5/5/2005,Bill Gates |
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
mock (unittest.mock in Python 3.3+) is a great mocking library for Python. Including this library in a Python Google App Engine project can be somewhat tricky. Follow these instructions: | |
1. Download the latest tarball: https://pypi.python.org/pypi/mock | |
2. Extract it in your root project directory. Rename the folder to mock/ | |
3. Add a __init__.py file in the mock/ directory with the content: | |
from mock import * | |
You can now simply import mock in your Python App Engine project. |
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
#!/usr/bin/env python3 | |
def is_valid(board, n): | |
if not sanity_check(board, n): | |
return False | |
# Check horizontally and vertically. | |
for i in range(n): | |
if (not check_sub_board(board, n, 0, n, i, i + 1) | |
or not check_sub_board(board, n, i, i + 1, 0, n)): | |
return False |
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
#!/usr/bin/env python3 | |
# Find the longest word that is made of other words in a list. | |
def canSplit(word, words, isFirst, missed): | |
if not isFirst and word in words: | |
return True | |
for i in range(len(word)): | |
left, right = word[:i], word[i:] | |
if (left in words and right not in missed |
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
"""Balanced Delimiters: https://www.hackerrank.com/contests/programming-interview-questions/challenges/balanced-delimiters""" | |
def isBalanced(delims): | |
stack = [] | |
matches = {')': '(', '}': '{', ']': '['} | |
for d in delims: | |
if d in ')]}': | |
if (not stack or stack.pop() != matches[d]): | |
return False | |
else: |
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
# This is a Git cheat-sheet for beginners. | |
# 1. Initial clone | |
git clone <package name> | |
# 2. Checkout a new branch | |
git checkout -b <feature> | |
# 3. Make changes | |
echo "Hack hack hack" >> newfile.txt |
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
#!/usr/bin/env python3 | |
'''Problem B: Cookie Clicker Alpha https://code.google.com/codejam/contest/2974486/dashboard#s=p1''' | |
def solve(c, f, x): | |
rate, total = 2.0, 0 | |
m = x / rate | |
while m <= x: | |
total += (c / rate) | |
rate += f |
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
#!/usr/bin/env python3 | |
''' Problem A: Magic Trick https://code.google.com/codejam/contest/2974486/dashboard#s=p0 ''' | |
def get_int(): | |
return int(input()) | |
def solve(): | |
choice1 = get_int() - 1 | |
arr1 = [set(input().split()) for x in range(4)] |
NewerOlder