Compare commits
No commits in common. "4ecaa1a216a8e4e9fb81cae34d533d149a7b3504" and "8501f2f4736430cd66b331b42c18a08a714652bc" have entirely different histories.
4ecaa1a216
...
8501f2f473
@ -1,32 +0,0 @@
|
||||
iris = csvread("iris.csv");
|
||||
|
||||
[training, testing] = randomsplit(iris, 2/3)
|
||||
|
||||
p = 2
|
||||
cells = p^(columns(iris)-1)+1
|
||||
|
||||
minmax = ranges(iris);
|
||||
classes = minmax(2,1) - minmax(1,1) + 1;
|
||||
|
||||
votes = zeros(cells,classes);
|
||||
|
||||
for i=1:rows(training)
|
||||
label = training(i,1);
|
||||
hashval = hash(training(i,:), minmax, p);
|
||||
votes(hashval,label) += 1;
|
||||
endfor
|
||||
|
||||
classification = tally(votes)
|
||||
|
||||
correct = 0
|
||||
for i=1:rows(testing);
|
||||
hashval = hash(testing(i,:), minmax, p);
|
||||
class=classification(hashval);
|
||||
label = testing(i,1);
|
||||
if label == class
|
||||
correct += 1;
|
||||
endif
|
||||
endfor
|
||||
|
||||
display(correct/rows(testing))
|
||||
|
@ -1,151 +0,0 @@
|
||||
1,5.1,3.5,1.4,0.2
|
||||
1,4.9,3.0,1.4,0.2
|
||||
1,4.7,3.2,1.3,0.2
|
||||
1,4.6,3.1,1.5,0.2
|
||||
1,5.0,3.6,1.4,0.2
|
||||
1,5.4,3.9,1.7,0.4
|
||||
1,4.6,3.4,1.4,0.3
|
||||
1,5.0,3.4,1.5,0.2
|
||||
1,4.4,2.9,1.4,0.2
|
||||
1,4.9,3.1,1.5,0.1
|
||||
1,5.4,3.7,1.5,0.2
|
||||
1,4.8,3.4,1.6,0.2
|
||||
1,4.8,3.0,1.4,0.1
|
||||
1,4.3,3.0,1.1,0.1
|
||||
1,5.8,4.0,1.2,0.2
|
||||
1,5.7,4.4,1.5,0.4
|
||||
1,5.4,3.9,1.3,0.4
|
||||
1,5.1,3.5,1.4,0.3
|
||||
1,5.7,3.8,1.7,0.3
|
||||
1,5.1,3.8,1.5,0.3
|
||||
1,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.2,3.6,6.1,2.5
|
||||
3,6.5,3.2,5.1,2.0
|
||||
3,6.4,2.7,5.3,1.9
|
||||
3,6.8,3.0,5.5,2.1
|
||||
3,5.7,2.5,5.0,2.0
|
||||
3,5.8,2.8,5.1,2.4
|
||||
3,6.4,3.2,5.3,2.3
|
||||
3,6.5,3.0,5.5,1.8
|
||||
3,7.7,3.8,6.7,2.2
|
||||
3,7.7,2.6,6.9,2.3
|
||||
3,6.0,2.2,5.0,1.5
|
||||
3,6.9,3.2,5.7,2.3
|
||||
3,5.6,2.8,4.9,2.0
|
||||
3,7.7,2.8,6.7,2.0
|
||||
3,6.3,2.7,4.9,1.8
|
||||
3,6.7,3.3,5.7,2.1
|
||||
3,7.2,3.2,6.0,1.8
|
||||
3,6.2,2.8,4.8,1.8
|
||||
3,6.1,3.0,4.9,1.8
|
||||
3,6.4,2.8,5.6,2.1
|
||||
3,7.2,3.0,5.8,1.6
|
||||
3,7.4,2.8,6.1,1.9
|
||||
3,7.9,3.8,6.4,2.0
|
||||
3,6.4,2.8,5.6,2.2
|
||||
3,6.3,2.8,5.1,1.5
|
||||
3,6.1,2.6,5.6,1.4
|
||||
3,7.7,3.0,6.1,2.3
|
||||
3,6.3,3.4,5.6,2.4
|
||||
3,6.4,3.1,5.5,1.8
|
||||
3,6.0,3.0,4.8,1.8
|
||||
3,6.9,3.1,5.4,2.1
|
||||
3,6.7,3.1,5.6,2.4
|
||||
3,6.9,3.1,5.1,2.3
|
||||
3,5.8,2.7,5.1,1.9
|
||||
3,6.8,3.2,5.9,2.3
|
||||
3,6.7,3.3,5.7,2.5
|
||||
3,6.7,3.0,5.2,2.3
|
||||
3,6.3,2.5,5.0,1.9
|
||||
3,6.5,3.0,5.2,2.0
|
||||
3,6.2,3.4,5.4,2.3
|
||||
3,5.9,3.0,5.1,1.8
|
||||
|
|
@ -1 +0,0 @@
|
||||
# Created by Octave 7.3.0, Wed Dec 07 23:43:44 2022 GMT <unknown@Isaac-DesktopPC>
|
@ -1,22 +0,0 @@
|
||||
#lang racket
|
||||
(define (balance lst)
|
||||
(define (helper lst counter)
|
||||
(cond
|
||||
[(empty? lst) counter] ;;base case
|
||||
[(list? (first lst)) (helper (rest lst) counter)] ;;unwrap list
|
||||
[(eq? (first lst) 'debit) (helper (rest lst) (- counter last))] ;;if debit subtract the amount
|
||||
[(eq? (first lst) 'credit) (helper (rest lst) (+ counter last))] ;;if credit add the amount
|
||||
[else (helper (rest lst) counter)]
|
||||
)
|
||||
)
|
||||
(helper lst 0)
|
||||
)
|
||||
|
||||
;; Racket
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (balance (list (list 'credit 5))) 5)
|
||||
(check-equal? (balance (list '(debit 5))) -5)
|
||||
(check-equal? (balance '((debit 11) (credit 3))) -8)
|
||||
(check-equal? (balance '((debit 3) (credit 5))) 2)
|
||||
(check-equal? (balance '((debit 5) (credit 23) (debit 23) (credit 5))) 0))
|
@ -1,19 +0,0 @@
|
||||
def invert(lst):
|
||||
lst = list(lst) # Makes sure arugment is a list
|
||||
|
||||
#list_range = range(0, len(lst)) # Code I might have used if I used a dictionary comprehension
|
||||
|
||||
|
||||
ret_dict = dict() # Create empty dict
|
||||
counter = 0 # Create counter
|
||||
|
||||
for i in lst:
|
||||
ret_dict[i] = counter # Assign each element of list to
|
||||
# its postion in list
|
||||
|
||||
counter = counter + 1 # Increment counter
|
||||
|
||||
if (len(lst) > len(ret_dict)): # Check if the length of new dict is less than
|
||||
return None # input list, if so, there is duplicates so return none
|
||||
|
||||
return ret_dict # Return created dictionary
|
@ -1,13 +0,0 @@
|
||||
from invert import invert
|
||||
def test_empty():
|
||||
assert invert([]) == {}
|
||||
def test_simple():
|
||||
invert(["three","two","one"]) == {"three": 0, "two":1, "one":2}
|
||||
def test_duplicate():
|
||||
assert invert(["bob","bob"]) == None
|
||||
def test_numeric():
|
||||
assert invert(range(0,6)) == { 0:0, 1:1, 2:2, 3:3, 4:4, 5:5 }
|
||||
def test_invert():
|
||||
L=[-8,"pineapple",3]
|
||||
D=invert(L)
|
||||
assert [ L[D[j]] for j in L ] == L
|
@ -1,50 +0,0 @@
|
||||
class Expression {
|
||||
constructor(op, left, right) {
|
||||
this.op = op
|
||||
this.left = left
|
||||
this.right = right
|
||||
}
|
||||
|
||||
eval() {
|
||||
return evalExpression(this)
|
||||
}
|
||||
}
|
||||
|
||||
function evalExpression(expr) {
|
||||
let tempLeft
|
||||
let tempRight
|
||||
if (typeof(expr.left) === "object") { // Check if left type is another expression
|
||||
tempLeft = evalExpression(expr.left)
|
||||
}
|
||||
else {
|
||||
tempLeft = expr.left
|
||||
}
|
||||
if (typeof(expr.right) === "object") { // Check if right type is another expression
|
||||
tempRight = evalExpression(expr.right)
|
||||
}
|
||||
else {
|
||||
tempRight = expr.right
|
||||
}
|
||||
if (typeof(tempLeft) === "number" & typeof(tempRight) === "number") { // Make sure both inputs are number
|
||||
if (expr.op === "+") {
|
||||
return tempLeft + tempRight
|
||||
}
|
||||
else if(expr.op === "-") {
|
||||
return tempLeft - tempRight
|
||||
}
|
||||
else if(expr.op === "*") {
|
||||
return tempLeft * tempRight
|
||||
}
|
||||
else if(expr.op === "/") {
|
||||
return tempLeft / tempRight
|
||||
}
|
||||
else { // Case for when there is no valid provided operator
|
||||
return "Invalid operator syntax"
|
||||
}
|
||||
}
|
||||
else { //Case for when the left or right are not numbers
|
||||
return "Invalid number syntax"
|
||||
}
|
||||
}
|
||||
|
||||
exports.Expression = Expression;
|
@ -1,71 +0,0 @@
|
||||
Expression = require("../expression.js").Expression;
|
||||
|
||||
let six_plus_nine = new Expression('+', 6, 9);
|
||||
let six_times_nine = new Expression('*', 6, 9);
|
||||
let six_minus_nine = new Expression('-', 6, 9);
|
||||
let sixteen_div_eight = new Expression('/', 16, 8);
|
||||
let compound1 = new Expression('+', six_times_nine, six_plus_nine)
|
||||
let compound2 = new Expression('*', six_times_nine, compound1)
|
||||
let compound3 = new Expression('+', compound2, 3)
|
||||
|
||||
describe("constructor",
|
||||
function() {
|
||||
let one = new Expression("+",0,1);
|
||||
it("not null", () => expect(one).not.toBe(null));
|
||||
it("op", () => expect(one.op).toBe("+"));
|
||||
it("left", () => expect(one.left).toBe(0));
|
||||
it("right", () => expect(one.right).toBe(1));
|
||||
});
|
||||
|
||||
describe("simple",
|
||||
function() {
|
||||
it("+", () => expect(six_plus_nine.eval()).toBe(15));
|
||||
it("-", () => expect(six_minus_nine.eval()).toBe(-3));
|
||||
it("*", () => expect(six_times_nine.eval()).toBe(54));
|
||||
it("/", () => expect(sixteen_div_eight.eval()).toBe(2));
|
||||
});
|
||||
|
||||
describe("compound",
|
||||
function() {
|
||||
it("1", () => expect(compound1.eval()).toBe(69));
|
||||
it("2", () => expect(compound2.eval()).toBe(3726));
|
||||
it("3", () => expect(compound3.eval()).toBe(3729));
|
||||
});
|
||||
|
||||
describe("floating point", //Testing floating point
|
||||
function() {
|
||||
let addPointFive = new Expression("+", 0.5, 0.5)
|
||||
let timesPointFive = new Expression("*", 0.5, 10)
|
||||
let minusPointFive = new Expression("-", 10, 0.5)
|
||||
let dividePointFive = new Expression("/", 0.5, 0.1)
|
||||
|
||||
it("+", () => expect(addPointFive.eval()).toBe(1.0));
|
||||
it("*", () => expect(timesPointFive.eval()).toBe(5.0));
|
||||
it("-", () => expect(minusPointFive.eval()).toBe(9.5));
|
||||
it("/", () => expect(dividePointFive.eval()).toBe(5.0));
|
||||
});
|
||||
|
||||
|
||||
describe("bad input", //Testing bad inputs
|
||||
function() {
|
||||
let invalidStringLeft = new Expression("+", "five", 6)
|
||||
let invalidStringRight = new Expression("+", 5, "six")
|
||||
let invalidOperator = new Expression("^", 6, 9)
|
||||
|
||||
it("Invalid String on left side", () => expect(invalidStringLeft.eval()).toBe("Invalid number syntax"));
|
||||
it("Invalid String on right side", () => expect(invalidStringRight.eval()).toBe("Invalid number syntax"));
|
||||
it("invalid operator", () => expect(invalidOperator.eval()).toBe("Invalid operator syntax"));
|
||||
});
|
||||
|
||||
|
||||
describe("compound bad input", //Testing bad inputs in compound cases
|
||||
function() {
|
||||
let invalidNumber = new Expression("+", "five", 6)
|
||||
let invalidOperator = new Expression("^", 6, 9)
|
||||
|
||||
let semiValidCompound = new Expression("+", six_plus_nine, invalidNumber)
|
||||
let completlyBadCompound = new Expression("+", invalidNumber, invalidOperator)
|
||||
|
||||
it("semi-valid", () => expect(semiValidCompound.eval()).toBe("Invalid number syntax"));
|
||||
it("invalid", () => expect(completlyBadCompound.eval()).toBe("Invalid number syntax")); //Expected to be invalid number because it is the first error to be encountered
|
||||
});
|
@ -1,13 +0,0 @@
|
||||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"**/*[sS]pec.?(m)js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/**/*.?(m)js"
|
||||
],
|
||||
"env": {
|
||||
"stopSpecOnExpectationFailure": false,
|
||||
"random": true
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
;; Racket
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (balance (list (list 'credit 5))) 5)
|
||||
(check-equal? (balance (list '(debit 5))) -5)
|
||||
(check-equal? (balance '((debit 11) (credit 3))) -8)
|
||||
(check-equal? (balance '((debit 3) (credit 5))) 2)
|
||||
(check-equal? (balance '((debit 5) (credit 23) (debit 23) (credit 5))) 0))
|
||||
|
||||
# Python
|
||||
from invert import invert
|
||||
def test_empty():
|
||||
assert invert([]) == {}
|
||||
def test_simple():
|
||||
invert(["three","two","one"]) == {"three": 0, "two":1, "one":2}
|
||||
def test_duplicate():
|
||||
assert invert(["bob","bob"]) == None
|
||||
def test_numeric():
|
||||
assert invert(range(0,6)) == { 0:0, 1:1, 2:2, 3:3, 4:4, 5:5 }
|
||||
def test_invert():
|
||||
L=[-8,"pineapple",3]
|
||||
D=invert(L)
|
||||
assert [ L[D[j]] for j in L ] == L
|
||||
|
||||
// JavaScript
|
||||
Expression = require("../expression.js").Expression;
|
||||
|
||||
let six_plus_nine = new Expression('+', 6, 9);
|
||||
let six_times_nine = new Expression('*', 6, 9);
|
||||
let six_minus_nine = new Expression('-', 6, 9);
|
||||
let sixteen_div_eight = new Expression('/', 16, 8);
|
||||
let compound1 = new Expression('+', six_times_nine, six_plus_nine)
|
||||
let compound2 = new Expression('*', six_times_nine, compound1)
|
||||
let compound3 = new Expression('+', compound2, 3)
|
||||
|
||||
describe("constructor",
|
||||
function() {
|
||||
let one = new Expression("+",0,1);
|
||||
it("not null", () => expect(one).not.toBe(null));
|
||||
it("op", () => expect(one.op).toBe("+"));
|
||||
it("left", () => expect(one.left).toBe(0));
|
||||
it("right", () => expect(one.right).toBe(1));
|
||||
});
|
||||
|
||||
describe("simple",
|
||||
function() {
|
||||
it("+", () => expect(six_plus_nine.eval()).toBe(15));
|
||||
it("-", () => expect(six_minus_nine.eval()).toBe(-3));
|
||||
it("*", () => expect(six_times_nine.eval()).toBe(54));
|
||||
it("/", () => expect(sixteen_div_eight.eval()).toBe(2));
|
||||
});
|
||||
|
||||
describe("compound",
|
||||
function() {
|
||||
it("1", () => expect(compound1.eval()).toBe(69));
|
||||
it("2", () => expect(compound2.eval()).toBe(3726));
|
||||
it("3", () => expect(compound3.eval()).toBe(3729));
|
||||
});
|
||||
|
||||
|
||||
# Octave
|
||||
%!shared P1,P3
|
||||
%! P1=[7,5,-3];
|
||||
%! P3=[1,2,3;4,5,6;7,8,9];
|
||||
%
|
||||
%!assert(manypoly(P1,0),7,eps)
|
||||
%!assert(manypoly(P1,1),9,eps)
|
||||
%!assert(manypoly(P1,5),7+5*5-3*25,eps)
|
||||
%!assert(manypoly(P3,0),[1;4;7],eps)
|
||||
%!assert(manypoly(P3,1),[6;15;24],eps)
|
||||
%!assert(manypoly(P3,2),[1+2*2+3*4;4+5*2+6*4;7+8*2+9*4],eps)
|
@ -1,4 +0,0 @@
|
||||
def with_prefix(prefixes, words):
|
||||
for prefix in prefixes:
|
||||
lst = [word for word in words if word.startswith(prefix)]
|
||||
yield lst
|
@ -1,41 +0,0 @@
|
||||
from prefix import with_prefix
|
||||
|
||||
words=["apple","baby","abba"]
|
||||
a_words=["apple", "abba"]
|
||||
def test_simple():
|
||||
assert list(with_prefix(["a"],words)) == [a_words]
|
||||
def test_order():
|
||||
assert list(with_prefix(["b","a"],words)) == [["baby"], a_words]
|
||||
def test_multi():
|
||||
assert list(with_prefix(["bb","ab"],words)) == [[],["abba"]]
|
||||
|
||||
# Commented out because the solution I am submitting is not using regex
|
||||
#def test_regex1():
|
||||
# assert list(with_prefix(["[a-z]b"], words)) == [ ["abba"] ]
|
||||
#def test_regex2():
|
||||
# assert list(with_prefix([".*a$"], words)) == [ ["abba"] ]
|
||||
|
||||
def test_gen():
|
||||
gen = with_prefix(["b"],words)
|
||||
assert next(gen) == ["baby"]
|
||||
|
||||
|
||||
|
||||
|
||||
def test_gen2(): #Testing out of order prefixes, with generator syntax
|
||||
gen = with_prefix(["b", "a"], words)
|
||||
assert next(gen) == ["baby"]
|
||||
assert next(gen) == ["apple", "abba"]
|
||||
|
||||
def test_gen3(): #Testing out returning the same number of elements as words, out of order
|
||||
gen = with_prefix(["bab", "abb", "app"], words)
|
||||
assert next(gen) == ["baby"]
|
||||
assert next(gen) == ["abba"]
|
||||
assert next(gen) == ["apple"]
|
||||
|
||||
|
||||
words2 = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "z"]
|
||||
def test_gen4(): #Testing a long word and one letter word
|
||||
gen = with_prefix(["a", "z"], words2)
|
||||
assert next(gen) == ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
|
||||
assert next(gen) == ["z"]
|
@ -1,32 +0,0 @@
|
||||
def is_word(word):
|
||||
counter = 0
|
||||
for l in word:
|
||||
if (counter % 2) == 0: #zero is vowel, one is constanant
|
||||
if l == 'a' or l == 'e' or l == 'i' or l == 'o' or l == 'u':
|
||||
counter = counter + 1
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if l == 'b' or l == 'k' or l == 'p' or l == 't' or l == 'z':
|
||||
counter = counter + 1
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
def cycle(lst):
|
||||
while True:
|
||||
yield lst
|
||||
x = lst[0]
|
||||
lst = lst[1:]
|
||||
lst.append(x)
|
||||
|
||||
class Skippy:
|
||||
def __init__(self, lst, offset)
|
||||
self.lst = lst
|
||||
self.offset = offset
|
||||
self.counter = 0
|
||||
|
||||
def __next__(self)
|
||||
if self.counter > length(self.lst)
|
||||
self.counter = 0
|
||||
|
@ -1,37 +0,0 @@
|
||||
from practice_questions import is_word
|
||||
|
||||
def test_match():
|
||||
assert is_word("akataka") == True
|
||||
assert is_word("ububu") == True
|
||||
assert is_word("ikekezaza") == True
|
||||
|
||||
def test_extra():
|
||||
assert is_word("akatakaa") == False
|
||||
assert is_word("uububu") == False
|
||||
|
||||
def test_bad_letter():
|
||||
assert is_word("yakataka") == False
|
||||
assert is_word("akatakala") == False
|
||||
|
||||
def test_consonant_start():
|
||||
assert is_word("kakataka") == False
|
||||
assert is_word("bububu") == False
|
||||
|
||||
|
||||
from practice_questions import cycle
|
||||
def test_small():
|
||||
lst = [1,2,3]
|
||||
g = cycle(lst)
|
||||
assert next(g) == lst
|
||||
assert next(g) == [2,3,1]
|
||||
assert next(g) == [3,1,2]
|
||||
|
||||
def test_big():
|
||||
n = 5000
|
||||
lst = list(range(n))
|
||||
g = cycle(lst)
|
||||
for j in range(n):
|
||||
lst2 = next(g)
|
||||
assert lst2[0] == n-1
|
||||
lst3 = next(g)
|
||||
assert lst3==lst
|
Loading…
Reference in New Issue
Block a user