Skip to content

Darts exercise hint for sqrt workaround doesn't seem to work #1430

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

Closed
boabdilperez opened this issue Feb 1, 2024 · 7 comments · Fixed by #1434
Closed

Darts exercise hint for sqrt workaround doesn't seem to work #1430

boabdilperez opened this issue Feb 1, 2024 · 7 comments · Fixed by #1434
Assignees

Comments

@boabdilperez
Copy link

I was just trying to solve the "Darts" exercise. The hints include the correct formula to get the distance from origin to any given coordinate on a plane, but the provided workaround for the lack of a native square root function in elixir doesn't seem to work. The spec for Integer.pow() is expecting integers for both the base and the exponent arguments. The spec for Float.pow() is explicitly expecting a float for the base, and a number for the exponent.

For the first test case of (-9, 9)

iex(3)> -9 * -9 + 9 * 9
162
iex(4)> Integer.pow(162, 0.5)
** (FunctionClauseError) no function clause matching in Integer.pow/2

    The following arguments were given to Integer.pow/2:

        # 1
        162

        # 2
        0.5

    Attempted function clauses (showing 1 out of 1):

        def pow(base, exponent) when is_integer(base) and is_integer(exponent)

    (elixir 1.16.0) lib/integer.ex:105: Integer.pow/2
    iex:4: (file)
iex(4)> Float.pow(162, 0.5)
** (FunctionClauseError) no function clause matching in Float.pow/2

    The following arguments were given to Float.pow/2:

        # 1
        162

        # 2
        0.5

    Attempted function clauses (showing 1 out of 1):

        def pow(base, exponent) when is_float(base) and is_number(exponent)

    (elixir 1.16.0) lib/float.ex:116: Float.pow/2
    iex:4: (file)
iex(4)>

Checking the example.ex in the repo, I see that neither Integer.pow or Float.pow were used there, but rather the erlang math library. I'm apologize if I am missing something else, as I'm not great at geometry OR elixir.

@jiegillet
Copy link
Contributor

jiegillet commented Feb 1, 2024

Hi @boabdilperez.
Those hints are common to all tracks, they are not Elixir specific, so they might not help as much with the lack of a proper sqrt function in Elixir, which I agree is a little frustrating.

As you noted yourself, Integer.pow() can't be used.
Float.pow() can be used, but you have to trick integers into becoming floats, like this Float.pow( 25 * 1.0, 0.5). It is a bit strange that there is no Integer.to_float() or something.
Finally, :math.sqrt works as well, Elixir is proudly built on top of Erlang, so Erlang functions are fair game.

@angelikatyborska
Copy link
Member

Those hints are common to all tracks, they are not Elixir specific

@jiegillet I can't find the hints in problem-specs, where did you take them from? Are they really global?

@jiegillet
Copy link
Contributor

Oh no, you're right, I got mislead by something, they are not global -_-
In that case, let's modify the file to mention what I said in the previous comment.

@jiegillet jiegillet self-assigned this Feb 2, 2024
@boabdilperez
Copy link
Author

I was ultimately able to figure it out, but a bit less organically than I think is the intent of these exercises. Modifying those hints will be a big help to anyone else who comes along, I think. Thanks for looking into this y'all!

@jiegillet
Copy link
Contributor

By the way, did you see the hints in the online editor or in offline mode? I can't find them at all.

@boabdilperez
Copy link
Author

boabdilperez commented Feb 2, 2024 via email

@jiegillet
Copy link
Contributor

I see, for me it's "Stuck? Ask ChatGPT". I tried it, asked me which model I wanted, then I could see the hints. When I reloaded I saw ChatGPT 3.5's suggestions (which were not helpful, but my code already had the square root part done).

I opened a PR, may I ask you to give it a review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants