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
# Write a program that implements logic gs AND, OR, NOT, NAND, NOR, XOR, and XNOR. | |
# thanks to Ryan North ( https://www.howtoinventeverything.com/, Chapter 17 ) | |
def lG(g, *a): | |
v = (0, 1) | |
for i in a: | |
if i not in v: | |
return -1 | |
if g == 'NOT': | |
return (1 - a[0]) |
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 mySubstring(w, *a): | |
O = "" | |
C = [char for char in w] | |
for i in range(len(C)): | |
if len(a) == 1: | |
O += C[i] if i >= a[0] else '' | |
else: | |
O += C[i] if i >= a[0] and i < (a[0]+a[1]) else '' | |
print(O) | |
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
# Implement the game rock, paper, scissors. | |
import random | |
from datetime import datetime | |
random.seed(datetime.now()) | |
matrix = [ | |
['TIE', 'LOSE', 'WIN'], | |
['WIN', 'TIE', 'LOSE'], |
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
# Given a positive number N, generate binary numbers between 1 to N using a queue-type structure in linear time. | |
# Example: | |
# > binaryQueue(10) | |
# > 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000 | |
import math | |
def printBinary(queue): | |
foundOne = False |
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
# Make the game Snake. Be as creative (or not) as you want! | |
import curses | |
import signal | |
from curses import wrapper | |
import math | |
import random | |
screenWidth = 80 |
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
# Implement array.filter() by hand (or whatever your language of choice uses to do this functionality). | |
def filter(array, filterFunction): | |
newArray = [] | |
for item in array: | |
isFilterTrue, updatedItem = filterFunction(item) | |
if isFilterTrue: | |
if updatedItem: | |
newArray.append(updatedItem) | |
else: |
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
# cassidoo Interview Question of the Week: January 13, 2020 | |
# Given a number n, find the sum of all n-digit palindromes. | |
# Example: | |
# > nPalindromes(2) | |
# > 495 // 11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 | |
def nPalindromes(length): | |
sum = 0 | |
if length == 0: |
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
import math | |
primeFactors = [] | |
def factorPrecheck(factor): | |
for primeFactor in primeFactors: | |
if factor % primeFactor == 0: | |
return False | |
return True |
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
# Given that an "even word" is a word in which each character appears an even | |
# number of times, write a function that takes in a string and returns the minimum | |
# number of letters to be removed to make that string an even word. | |
# Example: | |
# evenWord('aaaa') | |
# > 0 | |
# evenWord('potato') | |
# > 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
# Given an array of points that represent the 3 vertices of a triangle, and a point K, return true if K is inside the triangle. | |
# Example: | |
# let triangle = [ [0,0], [0,3], [4,0] ] | |
# isInTriangle(triangle, [2,1]) | |
# > true | |
# isInTriangle(triangle, [3,2]) | |
# > false | |
import math |
OlderNewer