-
-
Notifications
You must be signed in to change notification settings - Fork 402
Add practice exercise piecing-it-together
#1576
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: main
Are you sure you want to change the base?
Conversation
Thank you for contributing to Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:
Automated comment created by PR Commenter 🤖. |
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.
Woohoo, more exercises 🙂
Fill in missing jigsaw puzzle details from partial data | ||
""" | ||
|
||
defmodule JigsawPuzzle do |
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.
Nitpick: I'm not sure if I would have chosen a nested module for this exercise. I think I would have created a module called JigsawPuzzle
(not nested) with a function data
, and that's it 🤔
pieces: pos_integer(), | ||
rows: pos_integer(), | ||
columns: pos_integer(), | ||
format: format(), | ||
aspect_ratio: float(), | ||
border: pos_integer(), | ||
inside: pos_integer() |
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.
Should this type be extended somehow to signal that any of those values might be nil
when used as an input? If this was typescript, I would define the function as (input: Parial<JigsawPuzzle>): JigsawPuzzle
👻
"practices": [ | ||
"structs" | ||
], |
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.
Maybe like this? There's a lot of math:
"practices": [ | |
"structs" | |
], | |
"practices": [ | |
"structs", | |
"integers", | |
"floating-point-numbers" | |
], |
"structs", | ||
"errors", | ||
"multiple-clause-functions", | ||
"pattern-matching", | ||
"guards", | ||
"if", | ||
"case", | ||
"floating-point-numbers" |
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.
You have also used: enum, keyword-lists, maps, erlang-libraries. Which ones are really necessary for this exercise?
I'm assuming erlang-libraries are optional because Integer/Float.pow
can be used instead of :math.sqrt
. Is it common knowledge that pow(x, 0.5) == sqrt(x)
?
As for enum, maps, and keyword-lists, they all come from the fact that you've turned then input struct into a keyword list. Was that really necessary? Can the exercise be solved without that?
|> Map.from_struct()
|> Enum.filter(fn {_, value} -> value end)
|> Enum.sort_by(fn {key, _} -> key end)
@@ -0,0 +1,174 @@ | |||
defmodule PiecingItTogether do | |||
@doc """ | |||
TODO: add function description and replace types in @spec |
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.
👀
Did you "mostly" stuck to the test cases, or "fully" stuck to the test cases? I was trying to find anything in the tests that doesn't come from problem specs but couldn't 🤔 |
Fun little exercise! Great use of the quadratic formula 💯
The idea is to fill in partial information about a jigsaw puzzle.
There are tons of ways information might be missing or contradictory, but I mostly stuck to the test cases.