Skip to content

Instantly share code, notes, and snippets.

View jjlumagbas's full-sized avatar

JJ Lumagbas jjlumagbas

View GitHub Profile
@jjlumagbas
jjlumagbas / 11-exam-3.py
Created December 6, 2016 03:11
Exam solutions
def factorial(n):
"""
Int -> Int
Compute the factorial of n
"""
result = 1
for i in range(1, n + 1):
result = result * i
import java.util.List;
public class Graph {
public void addNode(String src) {
}
public void addEdge(String src, String dst) {
}
import java.util.LinkedList;
import java.util.List;
public class HashTable<V> {
private int capacity;
private List<V>[] buckets;
public HashTable(int capacity) {
this.capacity = capacity;
public class HeapSorter {
private int[] items;
private int heapSize;
private final int ROOT = 0;
public HeapSorter(int[] items) {
this.items = items;
this.heapSize = 0;
}
@jjlumagbas
jjlumagbas / lists.py
Created November 24, 2016 03:21
Using for i to iterate through a list
def display(lst):
for el in lst:
print(el)
# display(["Hi", "Hello", "Bye"])
def display2(lst):
for i in range(0, len(lst)):
@jjlumagbas
jjlumagbas / SplayTree.java
Last active November 22, 2016 01:25
Splay Tree
public class SplayTree {
private MyTreeNode root;
public SplayTree() {
this.root = null;
}
// convenience function for testing
public Integer root() {
@jjlumagbas
jjlumagbas / variables.py
Created November 21, 2016 07:06
Local and global scope, mutable lists
greets = ["hi", "hello", "bye"]
print(greets[0].upper())
def cap_list(lst):
pass # do this
cap_list(greets)
@jjlumagbas
jjlumagbas / maze-specs.md
Last active November 17, 2016 04:25
Maze MP

Square

  • char
  • visited
  • location (int row, col)

Maze

  • 2d array of Squares
@jjlumagbas
jjlumagbas / while.py
Created November 17, 2016 01:45
While-loops in Python
def foo(x, y):
current = x + y
while (current < 100):
current = current + x + y
print(current)
print("loop finished")
foo(10, 10)

Guessing games

How to hide user input

import getpass
age = getpass.getpass('Enter your age:')
print("Entered age is: " + age)