diff --git a/wk1/Assignment 1 - Kaloyan Stoykov and Dimitar Byalkov.docx b/wk1/Assignment 1 - Kaloyan Stoykov and Dimitar Byalkov.docx new file mode 100644 index 0000000..1e1ce27 Binary files /dev/null and b/wk1/Assignment 1 - Kaloyan Stoykov and Dimitar Byalkov.docx differ diff --git a/wk1/caesar1.png b/wk1/caesar1.png new file mode 100644 index 0000000..a69ea7f Binary files /dev/null and b/wk1/caesar1.png differ diff --git a/wk1/elm.json b/wk1/elm.json new file mode 100644 index 0000000..ce2a08d --- /dev/null +++ b/wk1/elm.json @@ -0,0 +1,24 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/wk1/pythagoras1.png b/wk1/pythagoras1.png new file mode 100644 index 0000000..b93456d Binary files /dev/null and b/wk1/pythagoras1.png differ diff --git a/wk1/src/Caesar1.elm b/wk1/src/Caesar1.elm new file mode 100644 index 0000000..d336388 --- /dev/null +++ b/wk1/src/Caesar1.elm @@ -0,0 +1,48 @@ +module Caesar1 exposing (..) +{- + Caesar cipher function + Dimitar Byalkov and Kaloyan Stoykov +-} + +encode: Int -> Char -> Char +encode offset character = + -- 65 A 90 Z + if Char.toCode(character) > 64 && Char.toCode(character) < 91 then + Char.fromCode(65 + modBy 26 (Char.toCode(character) - 65 + offset - 26)) + -- 97 a 122 z + else if Char.toCode(character) > 96 && Char.toCode(character) < 123 then + Char.fromCode(97 + modBy 26 (Char.toCode(character) - 97 + offset - 26)) + else Char.fromCode(32) + +decode: Int -> Char -> Char +decode offset character = + encode (0 - offset) character + +-- Tests + +testEncodeUpperSmallOffsetA: Bool +testEncodeUpperSmallOffsetA = (encode 5 'A' == 'F') + +testEncodeUpperBigOffsetF: Bool +testEncodeUpperBigOffsetF = (encode 348 'F' == 'P') + +testEncodeLowerSmallOffsetQ: Bool +testEncodeLowerSmallOffsetQ = (encode 9 'q' == 'z') + +testEncodeLowerBigOffsetG: Bool +testEncodeLowerBigOffsetG = (encode 215 'g' == 'n') + +testDecodeUpperSmallOffsetA: Bool +testDecodeUpperSmallOffsetA = (decode 5 'F' == 'A') + +testDecodeUpperBigOffsetF: Bool +testDecodeUpperBigOffsetF = (decode 348 'P' == 'F') + +testDecodeLowerSmallOffsetQ: Bool +testDecodeLowerSmallOffsetQ = (decode 9 'z' == 'q') + +testDecodeLowerBigOffsetG: Bool +testDecodeLowerBigOffsetG = (decode 215 'n' == 'g') + +allTests: List Bool +allTests = [testEncodeUpperSmallOffsetA, testEncodeUpperBigOffsetF, testEncodeLowerSmallOffsetQ, testEncodeLowerBigOffsetG, testDecodeUpperSmallOffsetA, testDecodeUpperBigOffsetF, testDecodeLowerSmallOffsetQ, testDecodeLowerBigOffsetG] \ No newline at end of file diff --git a/wk1/src/Pythagoras1.elm b/wk1/src/Pythagoras1.elm new file mode 100644 index 0000000..b569161 --- /dev/null +++ b/wk1/src/Pythagoras1.elm @@ -0,0 +1,93 @@ +module Pythagoras1 exposing (..) +{- + Pythagoraen triples + Dimitar Byalkov and Kaloyan Stoykov +-} + +sqr: Int -> Int +sqr n = + n * n + +isTriple: Int -> Int -> Int -> Bool +isTriple a b c = + if a <= 0 || b <= 0 || c <= 0 then + False + else if (sqr a + sqr b) /= sqr c then + False + else True + +leg1 : Int -> Int -> Int +leg1 x y = + sqr x - sqr y + +leg2 : Int -> Int -> Int +leg2 x y = + 2 * y * x + +hyp : Int -> Int -> Int +hyp x y = + sqr x + sqr y + +pythTriple : (Int, Int) -> (Int, Int, Int) +pythTriple inputTuple = + if Tuple.first inputTuple < 0 || Tuple.second inputTuple < 0 then + (0, 0, 0) + else + (leg1 (Tuple.first inputTuple) (Tuple.second inputTuple), leg2 (Tuple.first inputTuple) (Tuple.second inputTuple), hyp (Tuple.first inputTuple) (Tuple.second inputTuple)) + +isTripleTuple : (Int, Int, Int) -> Bool +isTripleTuple (a, b, c) = + isTriple a b c + +-- Tests + +testSqr: Bool +testSqr = (sqr 2 == 4) + +testSqrNegaviteNumber: Bool +testSqrNegaviteNumber = (sqr -1 == 1) + +testIsTripleZeros: Bool +testIsTripleZeros = (isTriple 0 0 0 == False) + +testIsTripleNotEqual: Bool +testIsTripleNotEqual = (isTriple 6 5 4 == False) + +testIsTripleNotEqual2: Bool +testIsTripleNotEqual2 = (isTriple 4 6 5 == False) + +testIsTripleEqual: Bool +testIsTripleEqual =(isTriple 3 4 5 == True) + +testLeg1: Bool +testLeg1 = (leg1 5 6 == -11) + +testLeg1B: Bool +testLeg1B = (leg1 7 3 == 40) + +testLeg2: Bool +testLeg2 = (leg2 3 9 == 54) + +testLeg2B: Bool +testLeg2B = (leg2 2 7 == 28) + +testHyp: Bool +testHyp = (hyp 5 6 == 61) + +testHypB: Bool +testHypB = (hyp 7 3 == 58) + +testInvalidPythTriple: Bool +testInvalidPythTriple = (pythTriple (-5, -9) == (0, 0, 0)) + +testPythTriple: Bool +testPythTriple = (pythTriple (4, 5) == (-9, 40, 41)) + +testPythTripleB: Bool +testPythTripleB = (pythTriple (7, 3) == (40, 42, 58)) + +testisTripleTuple: Bool +testisTripleTuple = (isTripleTuple (3, 4, 5) == True) + +allPythTests: List Bool +allPythTests = [testSqr, testSqrNegaviteNumber, testIsTripleZeros, testIsTripleNotEqual, testIsTripleNotEqual2, testIsTripleEqual, testLeg1, testLeg1B, testLeg2, testLeg2B, testHyp, testHypB, testInvalidPythTriple, testPythTriple, testPythTripleB, testisTripleTuple]