From 0649df959849ffe9ac6c6b78e267305bbd84cb53 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 14 Mar 2024 15:56:10 +0100 Subject: [PATCH] Solve first task --- Exercises/exercise-1/Code/A_Basics.hs | 2 +- Exercises/exercise-1/Code/A_BasicsTodo.hs | 33 ++++++++++++++--------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Exercises/exercise-1/Code/A_Basics.hs b/Exercises/exercise-1/Code/A_Basics.hs index 5a9dd15..20bc7e5 100644 --- a/Exercises/exercise-1/Code/A_Basics.hs +++ b/Exercises/exercise-1/Code/A_Basics.hs @@ -219,4 +219,4 @@ squares = [ x*x | x <- [1..10]] all odd square numbers between 1 and 100. -} oddSquares :: [Integer] -oddSquares = [ x | x <- squares, x `mod` 2 /= 0 ] \ No newline at end of file +oddSquares = [ x | x <- squares, x `mod` 2 /= 0 ] diff --git a/Exercises/exercise-1/Code/A_BasicsTodo.hs b/Exercises/exercise-1/Code/A_BasicsTodo.hs index d58f3d3..4601946 100644 --- a/Exercises/exercise-1/Code/A_BasicsTodo.hs +++ b/Exercises/exercise-1/Code/A_BasicsTodo.hs @@ -87,20 +87,23 @@ floatSevenByThree = 7 / 3 Check your solutions with the REPL. -x :: Integer -x = 2 ^ 3 +>>> x :: Integer = 2 ^ 3 -y :: Float -y = 2.0 ^ 3 +>>> y :: Float = 2.0 ^ 3 -a :: ? -a = x + 5 +>>> a :: Integer = x + 5 -b :: ? -b = y/2 +b :: Float +>>> b = y/2 +>>> :t b +b :: Float -c :: ? -c = y `div` 3 +c :: Error +>>> c = y `div` 3 +>>> :t c +No instance for (Integral Float) arising from a use of `div' +In the expression: y `div` 3 +In an equation for `c': c = y `div` 3 -} @@ -179,7 +182,7 @@ aListOfInts = [ 1, 2, 3 ] {- Exercise Fill out the type, check your solutions with the REPL. - friendGroups :: ? + friendGroups :: [[String]] friendGroups = [ ["Peter", "Anna", "Roman", "Laura"] , ["Anna","Reto"] @@ -215,11 +218,15 @@ lessThanPairs = [ (x,y) all square numbers between 1 and 100. -} squares :: [Integer] -squares = error "fixme" +squares = [ x^2 | x <- [1..(floor (sqrt 100))]] +-- >>> squares +-- [1,4,9,16,25,36,49,64,81,100] {- Exercise Use list comprehension to declare a list that contains all odd square numbers between 1 and 100. -} oddSquares :: [Integer] -oddSquares = error "fixme" +oddSquares = [ x^2 | x <- [1..(floor (sqrt 100))], odd (x^2)] +-- >>> oddSquares +-- [1,9,25,49,81]