Skip to content

Instantly share code, notes, and snippets.

View Bekt's full-sized avatar
👨‍🍳
making things happen

Kanat Bekt Bekt

👨‍🍳
making things happen
View GitHub Profile
@Bekt
Bekt / pegs.py
Created November 24, 2018 07:41
Quick and dirty solution for the triangle pegs game!
"""
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.
"""
@Bekt
Bekt / deploy.bash
Last active March 13, 2016 04:00
Download the latest App Engine SDK
#!/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/
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
@Bekt
Bekt / mock_import.txt
Created August 11, 2014 04:37
Importing mock library in Python App Engine
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.
@Bekt
Bekt / sudoku_verifier.py
Created July 29, 2014 02:47
Given a 2d array, check if it is a valid sudoku solution.
#!/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
@Bekt
Bekt / longest_combination.py
Last active August 29, 2015 14:03
Find the longest word made of other words in a list.
#!/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
@Bekt
Bekt / bal_delim.py
Created June 18, 2014 22:50
Balanced Delimiters Problem
"""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:
@Bekt
Bekt / git101
Last active August 29, 2015 14:02
Git 101
# 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
@Bekt
Bekt / b.py
Created April 14, 2014 18:14
CodeJam 2014 - Problem B
#!/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
@Bekt
Bekt / a.py
Created April 14, 2014 18:11
CodeJam 2014 - Problem A
#!/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)]