-
Notifications
You must be signed in to change notification settings - Fork 0
feat: solutions chapter 3 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
vrom911
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's neat work 👌🏼 Congrats on finishing Chapter 3 🥇
| { bookTitle :: String | ||
| , bookAutor :: String | ||
| , bookPages :: Int | ||
| , bookPrice :: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤑 💰
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧀 🍨 🧊
These are new! Would need to add Frühstück into my schedule 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the second German breakfast 🥳
| , cityHouses :: [House] | ||
| } | ||
|
|
||
| data Castle = None | OnlyCastle | CastleWithWalls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had read: Optional castle with a name, sorry. I'll try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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