Skip to content

Instantly share code, notes, and snippets.

View effective-light's full-sized avatar
🎯
Focusing

Effective Light effective-light

🎯
Focusing
View GitHub Profile
@effective-light
effective-light / hippos-starter.c
Last active October 5, 2018 19:17
Simple monitor implementation
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#define N 50
#define M 1000
int marbles = M;
int scores[N];
@effective-light
effective-light / LocalAreaNetwork.java
Last active June 20, 2017 07:11
Answers to CSC207H1Y Quiz 1 V1
package network;
public class LocalAreaNetwork extends Network
{
public static String whatAmI = "I am a LAN";
public static int numCreated;
public int numNodes;
public char firstLetter = 'L';
public class ParseTest
{
public static void main(String[] args)
{
if ( args.length == 1 )
System.out.println( ParseTest.parseInt( args[0] ) );
else
System.out.println( "Please supply an argument!" );
}
def calc_exp(b: int, n: int) -> int:
"""
>>> calc_exp(10, 1)
21
>>> calc_exp(3, 4)
960
"""
def _calc_exp(p: int) -> int:
if p == 1:
from stack import Stack
def size(stk: Stack) -> int:
""" Return the number of items on Stack stk, *without* modifying stk.
(It’s OK if the contents of stk are modified during the execution of this
function, as long as everything is restored before the function returns.)
>>> st = Stack()
>>> st.push(3); st.push(2); st.push(1)
public class Prime
{
public boolean isPrime(int n)
{
if ( n <= 1 )
return false;
for ( int i = 2; i < n; i++ )
{
@effective-light
effective-light / practice.py
Last active June 19, 2017 21:04
148 exam practice
class BTNode:
def __init__(self, value=None, left=None, right=None):
self.value, self.left, self.right = value, left, right
def count_leaves(root: 'BTNode') -> int:
""" Return the number of leaves in the tree rooted at root.
>>> count_leaves(None)
0
>>> count_leaves(BTNode(0, None, None))
@effective-light
effective-light / sorting.py
Last active June 19, 2017 21:05
Sorting Algorithms
def selection_sort(lst):
for i in range(len(lst) - 1):
min_index = i
for j in range(i + 1, len(lst)):
if lst[j] < lst[min_index]:
min_index = j
lst[i], lst[min_index] = lst[min_index], lst[i]
def pow_r(x, n):
if n == 0:
return 1
return multiply(x, pow_r(x, n - 1))
def multiply(f1, f2):
def _multiply(a, b):
if b == 1:
def bob_cipher(phrase: str, key: str) -> str:
"""
>>> bob_cipher("ANT", "BOB")
B25O25B18
"""
new_s = ""
for key_char, phrase_char in zip(key, phrase):