c icon indicating copy to clipboard operation
c copied to clipboard

The square root problem needs to be improved

Open Ashvith10 opened this issue 10 months ago • 4 comments

Here are a few ideas I have in my mind:

  • Explicitly mention to not use the in-built math library: Because that simply defeats the purpose of this question. Learners should be using either the Babylonian, Bakhshali, or any other methods out there. The two methods that I have in mind - the entire math library be disabled by removing the -lm flag, or that sqrt() be overridden, instead generating random value.

  • Square root of a natural number is not always a natural number: The test case for the exercises are a bit misleading, because it assumes that the parameter will always be a perfect square, which isn't always the the case. Take for example, 5, whose root is 2.2360679775. Therefore, the return type should be of type float or double, as opposed to uint16_t.

  • Raise the difficulty to hard (optional): Having to craft your own formula using seed estimate and a formula of their choice (Babylonian, Bakshali, etc) is a little bit daunting for beginners, and in my opinion, beyond the skills required for medium difficulty questions.

Ashvith10 avatar Apr 02 '24 06:04 Ashvith10

IIRC the intent of using uint16_t was to restrict the output to natural numbers so as to make the algorithm more simple.

The reasoning being that these are programming exercises rather than math exercises. In most real cases a programmer would simply use the library function.

We wanted something that would exercise the student, but not something that presents too high a barrier of entry.

Removing the -lm from the makefile is a good suggestion!

wolf99 avatar Apr 02 '24 11:04 wolf99

The description and test cases come from the upstream problem specifications repo. I agree that removing -lm is a good track-specific reminder that a library function shouldn't be used.

ryanplusplus avatar Apr 02 '24 12:04 ryanplusplus

@wolf99 and @ryanplusplus thank you for your response. Since the intent is to keep algorithms more simple, and solutions like brute-force are also equally acceptable, how about adding minor improvements to the description from the problem specification repository? If we let the learners know that the arguments will always be perfect squares, and therefore, they should not have to worry about the answer being non-integer rational numbers, this would lower the cognitive load for most students, who will jump on using complex techniques.

Ashvith10 avatar Apr 02 '24 19:04 Ashvith10

I'm confused:

from the problem specification repository

The description on this track already matches the one in the problem-specifications repository

What is it that should change in this track?

If it is the problem specification that you think should change, then this issue needs to be raised there.

wolf99 avatar Apr 02 '24 19:04 wolf99