Skip to content

Instantly share code, notes, and snippets.

View les-peters's full-sized avatar

Les Peters les-peters

View GitHub Profile
@les-peters
les-peters / cassidoo-1111.py
Last active November 11, 2019 19:49
Cassidoo 2019-11-11 challenge
# 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])
@les-peters
les-peters / cassidoo-1118.py
Last active November 20, 2019 21:08
cassidoo-1118.py
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)
@les-peters
les-peters / cassidoo-1125.py
Created November 25, 2019 13:52
cassidoo-1125.py
# Implement the game rock, paper, scissors.
import random
from datetime import datetime
random.seed(datetime.now())
matrix = [
['TIE', 'LOSE', 'WIN'],
['WIN', 'TIE', 'LOSE'],
@les-peters
les-peters / binary-by-queue.py
Last active December 16, 2019 14:17
cassidoo-1216.py
# 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
@les-peters
les-peters / snake.py
Last active December 27, 2019 18:43
cassidoo-20191223
# 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
@les-peters
les-peters / filter.py
Created January 10, 2020 19:04
2020-01-07
# 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:
@les-peters
les-peters / palindrome-sum.py
Last active January 13, 2020 18:02
Cassidoo IQofW 2020-01-13
# 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:
@les-peters
les-peters / not-a-prime.py
Last active January 24, 2020 19:27
Cassidoo IQofW 2020-01-20
import math
primeFactors = []
def factorPrecheck(factor):
for primeFactor in primeFactors:
if factor % primeFactor == 0:
return False
return True
@les-peters
les-peters / evenWord.py
Created February 5, 2020 18:32
IQofW 2020-02-04
# 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
@les-peters
les-peters / isInTriangle.py
Created February 11, 2020 13:33
IQotW 2020-02-10
# 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