Skip to content
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

New practice exercise square-root #797

Merged
merged 5 commits into from
Jul 3, 2021

Conversation

jiegillet
Copy link
Contributor

I did this one in 20 minutes (after thinking researching the algorithm), pretty good feeling :)

@github-actions
Copy link
Contributor

Thank you for contributing to exercism/elixir 💜 🎉. This is an automated PR comment 🤖 for the maintainers of this repository that helps with the PR review process. You can safely ignore it and wait for a maintainer to review your changes.

Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:

  • General steps

    • 🏆 Does this PR need to receive a label with a reputation modifier (reputation/contributed_code/{minor,major})? (A medium reputation amount is awarded by default, see docs)
  • Any exercise changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <exercise>/.meta/config.json (see docs)?
    • 🔬 Do the analyzer and the analyzer comments exist for this exercise? Do they need to be changed?
    • 📜 Does the design file (<exercise>/.meta/design.md) need to be updated to document new implementation decisions?
  • Practice exercise changed

    • 🌲 Do prerequisites, practices, and difficulty in config.json need to be updated?
    • 🧑‍🏫 Are the changes in accordance with the community-wide problem specifiations?
  • Practice exercise tests changed

    • ⚪️ Are all tests except the first one skipped?
    • 📜 Does <exercise>/.meta/tests.toml need updating?

Automated comment created by PR Commenter 🤖.


Given a natural radicand, return its square root.

Note that the term "radicand" refers to the number for which the root is to be determined. That is, it is the number under the root symbol.
Copy link

@papey papey Jun 29, 2021

Choose a reason for hiding this comment

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

We may have to add that this is a simplified exercise where only perfect squares are tested.

This way, we may avoid questions where the student asks what happens if function takes, for example, 3.

We may also add an anylizer ensuring that :math.sqrt(x) is not used. Note that maybe just a hint is ok here, what do you think @angelikatyborska ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we definitely need to tell students not to use :math.sqrt(). I would recommend:

  1. Adding an instructions.append.md file to tell students that they need to implement an algorithm on their own and not use :math.sqrt() or Float.pow
  2. Adding an issue to the analyzer repo so that somebody works on it at some point, an issue similar to Write a basic leap analysis elixir-analyzer#42 for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may have to add that this is a simplified exercise where only perfect squares are tested.

That will be apparent looking at the tests, I think. It's not uncommon for tests to have more information than the description :)


Given a natural radicand, return its square root.

Note that the term "radicand" refers to the number for which the root is to be determined. That is, it is the number under the root symbol.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we definitely need to tell students not to use :math.sqrt(). I would recommend:

  1. Adding an instructions.append.md file to tell students that they need to implement an algorithm on their own and not use :math.sqrt() or Float.pow
  2. Adding an issue to the analyzer repo so that somebody works on it at some point, an issue similar to Write a basic leap analysis elixir-analyzer#42 for example

# @tag :pending
test "root of 1" do
radicand = 1
output = SquareRoot.square_root(radicand)
Copy link
Contributor

Choose a reason for hiding this comment

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

"square root square root" :D sounds a bit silly. Maybe we can deviate from problem specs in this case and do, let's say SquareRoot.calculate?

Copy link
Contributor

Choose a reason for hiding this comment

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

☝🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might look better in the tests, but it will look weird in the lib file. How about sqrt?

Copy link
Contributor

Choose a reason for hiding this comment

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

My problem with SquareRoot.square_root and SquareRoot.sqrt is that in both cases both the module and the function name are exactly the same noun, shortened or not. I don't really know why, but it feels more correct to me if function name is either an action that gets executed on the "subject" indicated by the module name, or if the function name is a noun that's a specialization of the module name. I wonder if there's an article about this 🤔 I would like to know where my feeling comes from, maybe it's completely unjustified?

Here's more proposals. They all look ok to me 🤷

defmodule SquareRoot do
  @doc """
  Calculate the integer square root of a positive integer
  """
  @spec calculate(radicand :: pos_integer) :: pos_integer
  def calculate(radicand) do
  end
end
defmodule Root do
  @doc """
  Calculate the integer square root of a positive integer
  """
  @spec square(radicand :: pos_integer) :: pos_integer
  def square(radicand) do
  end
end
defmodule Math do
  @doc """
  Calculate the integer square root of a positive integer
  """
  @spec sqrt(radicand :: pos_integer) :: pos_integer
  def sqrt(radicand) do
  end
end
defmodule Calculator do
  @doc """
  Calculate the integer square root of a positive integer
  """
  @spec sqrt(radicand :: pos_integer) :: pos_integer
  def sqrt(radicand) do
  end
end
defmodule PosInteger do
  @doc """
  Calculate the integer square root of a positive integer
  """
  @spec sqrt(radicand :: pos_integer) :: pos_integer
  def sqrt(radicand) do
  end
end

},
"blurb": "Given a natural radicand, return its square root.",
"source": "wolf99",
"source_url": "https://github.com/exercism/problem-specifications/pull/1582"
Copy link
Contributor

Choose a reason for hiding this comment

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

How meta 😂 I suspect this isn't really a "good" value for source URL but meh 🤷 we're just copying problem specifications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha I didn't notice that!

Copy link
Contributor

@angelikatyborska angelikatyborska left a comment

Choose a reason for hiding this comment

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

🥳

@angelikatyborska angelikatyborska added the x:size/large Large amount of work label Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/large Large amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants