Solve first task

This commit is contained in:
Manuel Thalmann 2024-03-14 15:56:10 +01:00
parent 3bb0b1ead0
commit 0649df9598
2 changed files with 21 additions and 14 deletions

View file

@ -87,20 +87,23 @@ floatSevenByThree = 7 / 3
Check your solutions with the REPL. Check your solutions with the REPL.
x :: Integer >>> x :: Integer = 2 ^ 3
x = 2 ^ 3
y :: Float >>> y :: Float = 2.0 ^ 3
y = 2.0 ^ 3
a :: ? >>> a :: Integer = x + 5
a = x + 5
b :: ? b :: Float
b = y/2 >>> b = y/2
>>> :t b
b :: Float
c :: ? c :: Error
c = y `div` 3 >>> 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 {- Exercise
Fill out the type, check your solutions with the REPL. Fill out the type, check your solutions with the REPL.
friendGroups :: ? friendGroups :: [[String]]
friendGroups = friendGroups =
[ ["Peter", "Anna", "Roman", "Laura"] [ ["Peter", "Anna", "Roman", "Laura"]
, ["Anna","Reto"] , ["Anna","Reto"]
@ -215,11 +218,15 @@ lessThanPairs = [ (x,y)
all square numbers between 1 and 100. all square numbers between 1 and 100.
-} -}
squares :: [Integer] 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 {- Exercise
Use list comprehension to declare a list that contains Use list comprehension to declare a list that contains
all odd square numbers between 1 and 100. all odd square numbers between 1 and 100.
-} -}
oddSquares :: [Integer] oddSquares :: [Integer]
oddSquares = error "fixme" oddSquares = [ x^2 | x <- [1..(floor (sqrt 100))], odd (x^2)]
-- >>> oddSquares
-- [1,9,25,49,81]