Conversation
vrom911
left a comment
There was a problem hiding this comment.
That's neat work ππΌ Congrats on finishing Chapter 3 π₯
| { bookTitle :: String | ||
| , bookAutor :: String | ||
| , bookPages :: Int | ||
| , bookPrice :: Int |
| Create a simple enumeration for the meal types (e.g. breakfast). The one who | ||
| comes up with the most number of names wins the challenge. Use your creativity! | ||
| -} | ||
| data Meal = Breakfast | FrΓΌhstΓΌck | Brunch | Lunch | Dinner | Supper | Snack | OnlyWater |
There was a problem hiding this comment.
π§ π¨ π§
These are new! Would need to add FrΓΌhstΓΌck into my schedule π
There was a problem hiding this comment.
It's the second German breakfast π₯³
| , cityHouses :: [House] | ||
| } | ||
|
|
||
| data Castle = None | OnlyCastle | CastleWithWalls |
There was a problem hiding this comment.
The task tells that the castle should have a name. In this case, it can be a String.
Sorry, if it wasn't clear before. π We improved this task wording in the latest version to clarify this moment.
Could you guess, what functions would need patching in case of the type modifications? π
There was a problem hiding this comment.
I had read: Optional castle with a name, sorry. I'll try
There was a problem hiding this comment.
No worries, it's our bad that the wording wasn't clear!
| buildWalls :: City -> City | ||
| buildWalls city = case cityCastle city of | ||
| OnlyCastle -> | ||
| if sum (map countPeople (cityHouses city)) >= 10 |
There was a problem hiding this comment.
Nice combination of the standard functions ππΌ
| let damage = calculatePlayerDamage (playerAttack player2) (playerStrength player2) | ||
| defense = calculatePlayerDefense (playerArmor player1) (playerDexterity player1) | ||
| newHealth = calculatePlayerHit damage defense (playerHealth player1) | ||
| in player1 { playerHealth = newHealth } |
There was a problem hiding this comment.
Nice work on newtypes! π Newtypes are one very important feature in Haskell π
| | otherwise = succ weekday | ||
|
|
||
| daysToParty :: Weekday -> Int | ||
| daysToParty weekday = fromEnum Fri - fromEnum weekday |
There was a problem hiding this comment.
This would show the shortest distance to Friday, however, time doesn't work like this.
For example. if it is Saturday, it would tell you that it is -1 day to Friday, however, it is 6 days to go π₯³
There was a problem hiding this comment.
I changed the regular order of days because of this, but I am aware that this is a cheat π°
There was a problem hiding this comment.
Yeah, this one way to do it, but I agree, that this looks like a cheat π
You can apply the knowledge that we know exactly that there are 7 days in a week. So we can just calculate everything by mod 7!
Let's look how it would work:
ghci> mod (5) 7
5
ghci> mod (-1) 7
6Looks like just what we need!
Solutions for Chapter 3
cc @vrom911 @chshersh