diff --git a/exercises/block1/2-bob/README.md b/exercises/block1/2-bob/README.md index bf5d23f..3699d18 100644 --- a/exercises/block1/2-bob/README.md +++ b/exercises/block1/2-bob/README.md @@ -13,7 +13,7 @@ Bob gibt nur eine von fünf möglichen Antworten: - **"Klar."** Das ist seine Antwort, wenn man ihm eine Frage stellt, z. B. „Wie geht es dir?“. Fragen erkennt man daran, dass sie mit einem Fragezeichen enden. - **"Whoa, entspann dich!"** Das sagt er, wenn man IHN ANSCHREIT. Schreien erkennt man daran, dass ALLE BUCHSTABEN GROßGESCHRIEBEN SIND. -- **"Chill mal, ich weiß, was ich tue!"** So antwortet er, wenn man ihn anschreit und gleichzeitig eine Frage stellt. +- **"Chill mal, ich bin da schon dran!"** So antwortet er, wenn man ihn anschreit und gleichzeitig eine Frage stellt. - **"Na gut. Dann eben nicht!"** Das ist seine Reaktion auf Stille. Stille bedeutet, dass nichts gesagt wird oder nur Leerzeichen vorhanden sind. - **"Whatever."** Das ist seine Antwort auf alles andere. diff --git a/exercises/block1/2-bob/bob.hs b/exercises/block1/2-bob/bob.hs index 883130b..7f17315 100644 --- a/exercises/block1/2-bob/bob.hs +++ b/exercises/block1/2-bob/bob.hs @@ -1,40 +1,28 @@ import System.IO -import Data.Char ( isSpace, isAlpha, isUpper ) - - -isYelling :: [Char] -> Bool -isYelling stmt = any isAlpha stmt && all isUpper (filter isAlpha stmt) - -isQuestion :: [Char] -> Bool -isQuestion stmt = last (filter (not . isSpace) stmt) == '?' responseFor :: String -> String responseFor prompt -- implement here - | all isSpace prompt = "Na gut. Dann eben nicht!" - | isQuestion prompt && isYelling prompt = "Chill mal, ich weiß, was ich tue!" - | isQuestion prompt = "Klar." - | isYelling prompt = "Whoa, entspann dich!" - | otherwise = "Whatever." main :: IO () main = do inputContent <- readFile "example-input" outputContent <- readFile "example-output" - let prompt = map read (lines inputContent) :: [String] - expectedResults = map read (lines outputContent) :: [String] - actualResults = map responseFor prompt + let prompts = lines inputContent + expectedResults = lines outputContent + actualResults = map responseFor prompts + results = zip3 prompts expectedResults actualResults - let errors = [ (i, prompt, expected, actual) - | (i, (prompt, expected, actual)) <- zip3 [1..] prompts expectedResults actualResults - , expected /= actual ] + let incorrectResults = filter (\(_, expected, actual) -> expected /= actual) results - if null errors - then putStrLn "All tests passed!" + if null incorrectResults + then putStrLn "All tests passed successfully!" else do - putStrLn "Errors detected:" - mapM_ (\(i, prompt, expected, actual) -> - putStrLn $ "Error in prompt " ++ show i ++ ": \"" ++ prompt ++ "\"\nExpected: \"" ++ expected ++ "\"\nGot: \"" ++ actual ++ "\"\n") errors + putStrLn "The following tests failed:" + mapM_ (\(prompt, expected, actual) -> + putStrLn $ "Prompt: " ++ show prompt ++ + "\nExpected: " ++ show expected ++ + "\nActual: " ++ show actual ++ "\n") incorrectResults -- let results = map (show . responseFor) (lines inputContent) -- writeFile "example-output" (unlines results) diff --git a/exercises/block1/2-bob/example-output b/exercises/block1/2-bob/example-output index d2cbe66..005b12b 100644 --- a/exercises/block1/2-bob/example-output +++ b/exercises/block1/2-bob/example-output @@ -1,5 +1,5 @@ Klar. -Chill mal, ich wei\223, was ich tue! +Chill mal, ich bin da schon dran! Klar. Na gut. Dann eben nicht! Klar. diff --git a/exercises/block1/3-darts/README.md b/exercises/block1/3-darts/README.md new file mode 100644 index 0000000..0c327f9 --- /dev/null +++ b/exercises/block1/3-darts/README.md @@ -0,0 +1,19 @@ +# Optionale Bonusaufgabe: Factorial +## Anweisungen + +Schreibe eine Funktion, die die verdienten Punkte bei einem einzelnen Wurf im Dartspiel zurückgibt. + +Darts ist ein Spiel, bei dem die Spieler Darts auf ein Ziel werfen. + +In dieser speziellen Variante des Spiels vergibt das Ziel je nach Trefferbereich 4 verschiedene Punktzahlen: + +Unser Dart-Scoreboard mit Werten von einem kompletten Fehlschuss bis zum Bullseye: + +- Wenn der Dart außerhalb des Ziels landet, verdient der Spieler keine Punkte (0 Punkte). +- Wenn der Dart im äußeren Kreis des Ziels landet, verdient der Spieler 1 Punkt. +- Wenn der Dart im mittleren Kreis des Ziels landet, verdient der Spieler 5 Punkte. +- Wenn der Dart im inneren Kreis des Ziels landet, verdient der Spieler 10 Punkte. + +Der äußere Kreis hat einen Radius von 10 Einheiten (dies entspricht dem gesamten Radius des Ziels), der mittlere Kreis einen Radius von 5 Einheiten und der innere Kreis einen Radius von 1. Natürlich sind sie alle um denselben Mittelpunkt zentriert — das heißt, die Kreise sind konzentrisch und durch die Koordinaten (0, 0) definiert. + +Schreibe eine Funktion, die für einen gegebenen Punkt im Ziel (definiert durch seine kartesischen Koordinaten x und y, wobei x und y reale Zahlen sind) die richtige Anzahl der Punkte zurückgibt, die durch einen Dartwurf an diesem Punkt verdient werden. diff --git a/exercises/block1/3-darts/darts.hs b/exercises/block1/3-darts/darts.hs new file mode 100644 index 0000000..90b5736 --- /dev/null +++ b/exercises/block1/3-darts/darts.hs @@ -0,0 +1,29 @@ +import System.IO + +score :: Float -> Float -> Int +score x y -- implement here + +main :: IO () +main = do + input <- readFile "example-input" + expectedOutput <- readFile "example-output" + + let results = map (\line -> + let [xStr, yStr] = words line + x = read xStr :: Float + y = read yStr :: Float + in score x y) (lines input) + + let expectedResults = map read (lines expectedOutput) :: [Int] + + let comparisons = zip results expectedResults + errors = filter (uncurry (/=)) comparisons + + -- Print results + if null errors + then putStrLn "Success: All calculated scores match the expected results." + else mapM_ (\(calculated, expected) -> + putStrLn $ "Error: Calculated " ++ show calculated ++ " but expected " ++ show expected) + errors + + -- writeFile "example-output" (unlines results) diff --git a/exercises/block1/3-darts/example-input b/exercises/block1/3-darts/example-input new file mode 100644 index 0000000..6c12706 --- /dev/null +++ b/exercises/block1/3-darts/example-input @@ -0,0 +1,10 @@ +1.0 2.0 +3.5 4.5 +-1.2 3.8 +0.0 0.0 +-5.5 -6.5 +7.1 8.2 +9.9 -10.1 +-3.3 2.2 +4.4 -4.4 +5.5 5.5 \ No newline at end of file diff --git a/exercises/block1/3-darts/example-output b/exercises/block1/3-darts/example-output new file mode 100644 index 0000000..14e5b42 --- /dev/null +++ b/exercises/block1/3-darts/example-output @@ -0,0 +1,10 @@ +5 +1 +5 +10 +1 +0 +0 +5 +1 +1 diff --git a/solutions/block1/.gitkeep b/solutions/block1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/solutions/block2/.gitkeep b/solutions/block2/.gitkeep new file mode 100644 index 0000000..e69de29