Skip to content

Commit 8bc4e26

Browse files
meatball133IsaacG
andauthored
Add comments for crystal analyzer 1.3 (#2357)
* Add comments for crystal analyzer 1.3 * Update analyzer-comments/crystal/darts/hypot.md Co-authored-by: Isaac Good <[email protected]> * Update analyzer-comments/crystal/darts/hypot.md Co-authored-by: Isaac Good <[email protected]> * Update analyzer-comments/crystal/weighing-machine/missing_method.md Co-authored-by: Isaac Good <[email protected]> --------- Co-authored-by: Isaac Good <[email protected]>
1 parent 7812c02 commit 8bc4e26

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Pow
2+
3+
Using `pow`, `sqrt` or `**` is totally valid and can be necessary in many situations.
4+
However when we want a distance in Cartesian space we can use the [`hypot` method][hypot] which returns the hypotenuse of a right angle triangle with sides x and y.
5+
6+
```crystal
7+
# Rather than:
8+
Math.sqrt(number ** 2 + another_number ** 2)
9+
10+
# Consider:
11+
Math.hypot(number, another_number)
12+
```
13+
14+
[hypot]: https://crystal-lang.org/api/Math.html#hypot%28value1%2Cvalue2%29-instance-method
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Uses the hypot method
2+
3+
Congratulations, your solution uses the hypot method!
4+
5+
Your solution uses an efficient way of calculating the distance from the center of a dartboard and that's worth taking a moment to celebrate.

analyzer-comments/crystal/sieve/do_not_use_div_rem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Like the instructions mention, the purpose of this exercise is to build a Sieve of Eratosthenes without the use of operations such as division or modulo division.
44
Please refer to the [Wikipedia link][wikipedia] for a description of the algorithm.
55

6-
Building the Sieve of Eratosthenes in an immutable language such as Crystal may feel a bit unnatural,
6+
Building the Sieve of Eratosthenes without operations such as division or modulo division can be tricky.
77
but it is a beautiful algorithm invented more than two millennia ago that is worth learning and implementing.
88

99
[wikipedia]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Missing %{method_name} method call
2+
3+
Like the instructions mention, the purpose of this exercise is to learn about getters and setters.
4+
Manually defining these methods is not inherently bad, but can lead to code which is more verbose and harder to maintain.

0 commit comments

Comments
 (0)