Skip to content

completed first assignment#536

Open
preyawnshoe wants to merge 7 commits intokowainik:mainfrom
preyawnshoe:progress
Open

completed first assignment#536
preyawnshoe wants to merge 7 commits intokowainik:mainfrom
preyawnshoe:progress

Conversation

@preyawnshoe
Copy link
Copy Markdown

@preyawnshoe preyawnshoe commented Oct 6, 2022

Solutions for Chapter 1

cc @vrom911 @chshersh

@preyawnshoe preyawnshoe requested a review from vrom911 as a code owner October 6, 2022 09:17
@vrom911 vrom911 added chapter1 hacktoberfest-accepted https://hacktoberfest.digitalocean.com/ labels Oct 6, 2022
Copy link
Copy Markdown
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job! šŸ‘šŸ¼

Comment thread src/Chapter1.hs Outdated
Comment thread src/Chapter1.hs Outdated
Comment thread src/Chapter1.hs Outdated
-- DON'T FORGET TO SPECIFY THE TYPE IN HERE
lastDigit n = error "lastDigit: Not implemented!"
lastDigit :: Int->Int
lastDigit n = mod n 10
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your implementation is almost correct šŸ†—
Unfortunately, it returns negative numbers on negative inputs because of how mod works. Sometimes corner cases can be tricky to spot and fix...

Comment thread src/Chapter1.hs Outdated
Comment on lines +647 to +648
let last = mod n 10
x = div n 10
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a wonderful solution! šŸ‘šŸ¼ You correctly noticed that it is the div and mod, cool šŸ˜Ž

One hint to make your solution even shorter: you can see that you use both:

mod m 10
div m 10

The standard library has the divMod function, that actually combines inside both div and mod. And this is exactly what you use!.

So you could write it this way:

(x, y) = divMod m 10

You can see how we could pattern match on the pair šŸ™‚

preyawnshoe and others added 4 commits October 6, 2022 21:46
Co-authored-by: Veronika Romashkina <vrom911@gmail.com>
Co-authored-by: Veronika Romashkina <vrom911@gmail.com>
@preyawnshoe
Copy link
Copy Markdown
Author

Thank you so much for the valuable feedback I have made the necessary changes as per your suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chapter1 hacktoberfest-accepted https://hacktoberfest.digitalocean.com/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⚔