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
# 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 |
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
// 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++) { |
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 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 { | |
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 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"); |
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
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() { |
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 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 { | |
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
public class AList { | |
private String[] items; | |
private int count; | |
public AList() { | |
items = new String[10]; | |
count = 0; | |
} | |
public void add(String item) { |
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
-- 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) |
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
someFunction :: [a] -> [a] | |
someFunction (_:_:_:xs) = xs | |
someFunction _ = [] |
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
# 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): | |
# """ |