Created
October 24, 2012 20:17
-
-
Save daemonfire300/3948582 to your computer and use it in GitHub Desktop.
Haskell
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
-- ----------------. | |
-- Übungsblatt 1 -- | |
-- ----------------. | |
import Data.Char | |
import Test.QuickCheck | |
-- Aufgabe 3 | |
double x = x + x | |
doubleTwice' x = 2 * double x | |
doubleTwice x = double x + double x | |
-- Aufgabe 4 a) | |
umfang :: Float -> Float | |
umfang d = d * pi * 2 | |
-- Aufgabe 4 b) | |
schaltjahr :: Integer -> String | |
schaltjahr j | |
| x == True = "Es ist ein Schaltjahr" | |
| x == False = "Es ist kein Schaltjahr" | |
| otherwise = "Lawl lawl fehler" | |
where x = j `mod` 400 == 0 || (j `mod` 4 == 0 && j `mod` 100 /= 0) | |
-- Aufgabe 5 a) | |
isTriple :: Int -> Int -> Int -> Bool | |
isTriple a b c = (a * a + b * b) == (c * c) | |
-- Aufgabe 5 b) | |
abc :: Int -> Int -> [(Int, Int, Int)] | |
abc x y = [(x^2 - y^2, x, y), (2*x*y, x, y), (x^2 + y^2, x, y)] | |
axy :: Int -> Int -> Int | |
axy x y = x^2 - y^2 | |
bxy :: Int -> Int -> Int | |
bxy x y = 2*x*y | |
cxy :: Int -> Int -> Int | |
cxy x y = x^2 + y^2 | |
axy' :: Int -> Int -> (Int, Int, Int) | |
axy' x y | |
| x > y = (x^2 - y^2, x, y) | |
| x <= y = (y^2 - x^2, x, y) | |
bxy' :: Int -> Int -> (Int, Int, Int) | |
bxy' x y = (2*x*y, x, y) | |
cxy' :: Int -> Int -> (Int, Int, Int) | |
cxy' x y = (x^2 + y^2, x, y) | |
abc' :: Int -> Int -> (Int, Int, Int) | |
abc' x y | |
| x > y = (x^2 - y^2, 2*x*y, x^2 + y^2) | |
| x <= y = (y^2 - x^2, 2*x*y, x^2 + y^2) | |
testPyth :: (Int, Int, Int) -> Bool | |
testPyth (a, b, c) = isTriple a b c | |
testTriple :: (Int, Int, Int) -> Bool | |
testTriple (a, b, c) = testPyth (a, b, c) | |
-- testABC quickCheck (( \a -> \b -> testTriple (abc' a b) == True ) :: Int -> Int -> Bool) | |
-- testA | |
-- testB | |
-- testC | |
-- ----------------. | |
-- Übungsblatt 2 -- | |
-- ----------------. | |
-- import Prelude hiding ((&&),(||)) | |
-- Auf das hiding wird verzichtet, damit man später mit QuickCheck die and' und or' | |
-- gegen das tatsächlich "und" und "oder" laufen lassen kann. | |
-- Aufgabe 1 a) | |
xorIf :: Bool -> Bool -> Bool | |
xorIf a b = if( a == True && b == True) | |
then False | |
else | |
if( a == True || b == True) | |
then True | |
else | |
False | |
-- Aufgabe 1 b) | |
-- quickCheck (( \a -> \b -> and' a b == (a && b) ) :: Bool -> Bool -> Bool) | |
and' :: Bool -> Bool -> Bool | |
and' a b | |
| j == False = False | |
| j == b = True | |
| otherwise = False | |
where j = a == True | |
-- quickCheck (( \a -> \b -> or' a b == (a || b) ) :: Bool -> Bool -> Bool) | |
or' :: Bool -> Bool -> Bool | |
or' a b | |
| and' a b == True = True | |
| a == True = True | |
| b == True = True | |
| otherwise = False | |
-- Aufgabe 2 a) | |
toCap :: Char -> Char | |
toCap chr = toUpper chr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment