Skip to content

Instantly share code, notes, and snippets.

View kanglicheng's full-sized avatar
🦜
LLMs ftw

Stephen Cheng kanglicheng

🦜
LLMs ftw
View GitHub Profile
@EntilZha
EntilZha / hashtable.py
Last active December 18, 2022 05:37
Hash Table (Open Address) implementation in Python practicing for interviews
from collections import namedtuple
TableEntry = namedtuple('Element', 'hash key value')
class HashTable(object):
DEFAULT_SIZE = 8
EMPTY_VALUE = TableEntry(None, None, None)
DELETED_VALUE = TableEntry(None, None, None)
LOAD_FACTOR = 2 / 3
MIN_FACTOR = 1 / 3
@jason-feng
jason-feng / tictactoe.py
Created September 17, 2015 14:54
A simple python command line tic tac toe game
import pprint
# Returns a row in a given column
def column(matrix, i):
return [row[i] for row in matrix]
# Checks if a given row or column has all of the same value
def check(list):
if len(set(list)) <= 1:
if list[0] != 0:
@shichao-an
shichao-an / companies.txt
Last active May 18, 2017 06:11
Popular companies for coding interviews (LeetCode)
Amazon
Microsoft
Facebook
Google
LinkedIn
Twitter
Apple
Zenefits
Uber
Airbnb
function numberOfAnagrams(S) {

  // S.length!/repeat!
  
  var total = factorial(S.length),
	repeat = 1,
      array = S.split('').sort();
  
  for (var i=1;i<array.length;i++) {
def is_square(integer):
root = math.sqrt(integer)
if int(root + 0.5) ** 2 == integer:
return True
else:
return False
@dlresende
dlresende / gist:60b4c0240ad020a323ad
Last active March 20, 2021 19:51
FooBarQix Kata

FooBarQix Kata

Write a program that prints numbers from 1 to 100, one number per line. For each printed number, use the following rules:

  1. if the number is divisible by 3 or contains 3, replace 3 by "Foo";
  2. if the number is divisible by 5 or contains 5, replace 5 by "Bar";
  3. if the number is devisible by 7 or contains 7, replace 7 by "Qix".

Example: 1

You will be given two text files, train.txt and test.txt. The former is a large corpus of data of open source
literature from Project Gutenberg and the latter is a small snippet from the same source which has been encoded
with a simple substitution cipher.
The substitution cipher is 1-to-1, every character in the alphabet will map to one character, possibly itself.
The same mapping will be used consistently throughout any encoding. Case does not matter here, so if A is encoded
by Z then a is encoded by z. Any characters other than A-Z/a-z will be left as is.
The goal of this assignment is to write a program which consumes train.txt and:
@joealba
joealba / gist:85e97de45f79bace40e3
Last active May 18, 2017 06:30
Roman numeral kata
Roman Numeral Converter -- TDD Practice
Using your language of choice, create a RomanNumeralConverter class with a decimal_to_roman method that takes one positive integer argument and returns that argument represented as a Roman numeral.
However, there's one hitch. You can't write any code until you have a failing test case. We've started you off with the first test in multiple languages. Now you must think about what test you would add next, then write the code to make the test pass. Work with your team to think about the additional tests that it would take to make you confident that -- if these tests all passed -- you'd have code that would work in a sufficient number of edge cases. (Covering up to a max value of 3000 is sufficient for this exercise.)
Sure, you could cheat and Google for one of the elegant solutions that are available. But the point of this exercise isn't to find that most elegant solution... It's to practice test-driven development and involve the non-coders in thinking up edge c
@timMorrill
timMorrill / selection.py
Created November 5, 2014 18:23
Selection Sort in Python
myList = [6,3,4,5,2,1,1, 20, 36, 50, 2]
def selection(theList):
for i in range(len(theList)):
min = i
for k in range(i+1, len(theList)):
if theList[k] < theList[min]:
tmp = theList[i]
theList[i] = theList[k]