Skip to content

Instantly share code, notes, and snippets.

View jjlumagbas's full-sized avatar

JJ Lumagbas jjlumagbas

View GitHub Profile
# Returns the larger value of either x or y, given x and y are numbers (Note: what value should be returned if they are equal?)
def max_of_2(x, y):
"""
Num, Num -> Num
Returns the larger of the two given numbers
// 1. Determine if two numbers, x and y, are relatively prime. Compute for T(n) of your solution.
// Two integers are relatively prime if they share no common positive factors (divisors) except 1.
// 2. Compute for T(n):
for (int i = 1; i <= n; i++) {
a = x - y + 7 * b;
for (int j = 1; j <= n; j++) {
x = a + b;
for (int k = j; k <= n; k++) {
import junit.framework.TestCase;
/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class LListTest extends TestCase {
import junit.framework.TestCase;
import java.util.*;
public class ArrayListTest extends TestCase {
private final int INITIAL_CAPACITY = 5;
public void testAddOne() {
List<String> l = new ArrayList<String>();
l.add("Deodorant");
public class BoatRide implements Chargeable {
private double baseFare;
private double distance;
public BoatRide(double baseFare, double distance) {
this.baseFare = baseFare;
this.distance = distance;
}
public double cost() {
import junit.framework.TestCase;
/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class AListTest extends TestCase {
public class AList {
private String[] items;
private int count;
public AList() {
items = new String[10];
count = 0;
}
public void add(String item) {
-- from Don Sanella
-- http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/
searchRec :: Eq a => [a] -> a -> [Int]
searchRec xs y = srch xs y 0
where
srch :: Eq a => [a] -> a -> Int -> [Int]
srch [] y i = []
srch (x:xs) y i
| x == y = i : srch xs y (i+1)
someFunction :: [a] -> [a]
someFunction (_:_:_:xs) = xs
someFunction _ = []
# The Kapehan coffee shop sells coffee
# beans at P850 per kilo plus the
# cost of shipping. Each order ships
# for P185 per kilo + P250 fixed cost
# per shipment for overhead.
# Write a function that calculates the
# cost of an order. 

# def order_cost(kilos):
# """