6 kyu
Floating-point Approximation (II)
32 of 1,113g964
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Nim: same issue as in half of other Nim katas - tests are green even if you fail (doesn't count as completion, but very confusing).
I've hit the same bug in my own Nim translations, it can be solved by having only one check per test.
Groovy: initial solution is missing import:
import java.util.function.DoubleUnaryOperator;
PowerShell. What is a mistake: Expected: {0 0.99 0.14 -0.98 -0.28 0.93 0.41 -0.88 -0.54 0.8 0.65 -0.72} But was: {0 0.99 0.14 -0.98 -0.28 0.93 0.41 -0.88 -0.54 0.8 0.65 -0.72} ?
I dont understand, what am I approximating? I just use f and push the values until it fits.
Update to Nim 1.6.
If after merging it turns out that 1.6 did not get active, or that 1.0 did not get inactive, let me know. It's a known bug, and there's a known fix for this.
Approved
python new test framework is required. updated in this fork
Approved
Is this even solvable in Perl? Whatever precision I'm trying to use, I cannot get the exact results as expected. -0.98999 expects -0.99 and similar. Am I missing something obvious?
I think:-) Your last line works with "floor" instead of "int". BigFloat is not needed.
Thanks. That's what I initially thought, but I went totally different direction :(
This comment has been hidden.
It's not a kata error. The initial solution stub shows:
It's part of the kata to complete this initial solution.
Node 14 should be enabled (Refer this and this for more info)
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
done for python.
Ruby 3.0 enabled in this fork
Missing sample and fixed tests whereby
l
is not zero andf
is a log function across most languagesCan you be more precise, I don't understand what you want.
This comment has been hidden.
Have you fixed the C version here?
Yes.
I've forked the Rust translation in order to update it to Rust 1.49 and updated
rand::Rng::gen_range
to its new signature that takes astd::ops::Range
.Approved, thanks!
Hi, buddy! I hope, I haven't miss something in my solution. I use JS in my way, and catch the next problem: from the first to the third test my way works pretty clear, without any errors, but in random test every second "out" is wrong, and have such type
Expected: '[0.69, 1.18, 1.51, 1.76, 1.96, 2.13, 2.27, 2.39, 2.5, 2.6, 2.69, 2.78, 2.85, 2.92]',
instead got: '[0.69, 1.18, 0.94, 1.34, 1.63, 1.86, 2.04, 2.19, 2.33, 2.44, 2.55, 2.64, 2.73, 2.92]'.
What can I do with it? Thanks a lot in advance!
I looked at your code and there is a flaw in it. Moreover it is unnecessarily complicated.
The author almost has written out the answer.
Language: Scala
Random test result:
l: 7.5 u: 18.0 n: 15 Actual: 2.01, 2.1, 2.18, 2.26, 2.33, 2.39, 2.45, 2.51, 2.57, 2.62, 2.67, 2.72, 2.76, 2.8, 2.85 Expect: 2.01, 2.1, 2.18, 2.26, 2.33, 2.39, 2.45, 2.51, 2.57, 2.62, 2.67, 2.72, 2.76, 2.8, 2.85 -
What that "-" means?
It is a question, not an issue. Morever report exactly between 3 backticks (3 before, 3 after) the console log so that people can see exactly what you got. Look at the function "testing": you will see at the end `println("-")' hence the "-". Did you pass the kata?
I found the problem: it's flooring vs rounding when dealing with numbers like 10,19999... or 7,9999... Instructions tell about "flooring" and not "rounding", but still these tests fail:
Is it a part of the task?
This comment has been hidden.
This comment has been hidden.
Language: Scala
I forgot to add the lower bound to the argument of f and still passed the tests. Looking at the test cases the lower bound is always fixed to 0.
Yes but I don't think that the value of the lower bound changes the "difficulty" of the kata. If you think so I can add the "log" function the lower bound of which can't be 0... Please tell me if you think that would be useful.
I don't think it changes the difficulty of the kata. Maybe I'm beeing too nit-picky but I would want only a correct implementation to pass the task. I would have expected the lower bound to be tested with random values as well.
Modified, thanks for your time!
This comment has been hidden.
The description is the same for all languages. With float numbers the problems are always the same, in paticular operations order. It would have been necessary to appreciate each element of arrays within a given approximation. Nevertheless more than 160 guys passed the kata with the same fixed tests in all languages. The solution cannot be clear from a description unless to give it... Edit: please, when you post a solution or even bits of solution, mark your post as "spoiler".
@g964: while we are on topic, can you tell me how to round
d
here? I've tried your suggested rounding method:and I pass all the tests but not the random tests with the first version.
It would be easier if you had told me the language you are using:-) The description says:
so it seems normal that what you call the first version has problem.
All I can say is that fixed tests and random tests use exactly the same rounding which is the one given in the solution. Fixed tests are the same in all languages
OP solved it, closing
Quite good!
Thanks for your post!
The instructions start out calling the lower limit m, then switch to calling it l.
See the description, hopefully it will please you.
For functions returning doubles, I think the best practice is to test approximate correctness (with code like "abs(expected - actual) < epsilon") rather than relying on rounding or truncation, which can cause problems unless you specify exactly how the rounding is to be done (and the function code follows your instructions to the letter). Note, for example, that "floor(x * 100.0) * 0.01" and "floor(x * 100.0) / 100.0" give different results for some values of x.
Two issues for only one kata:-) I use a
asserFuzzyEqual
test when there is only one number to return (see my other katas) with great precision but here it is an array and it will take more time to test than to run the solution. Moreover I give exactly and explicitely the function to use.JS random tests: you're starting the interval at
l+l
instead ofl
.Fixed it for you. Hope you don't mind.
I don't mind but I was modifying solution and tests and I am afraid that your solution is invalidated now:-)
AGAIN ?!? :P
I had already done that myself!
Think we both invalidated in the same way. I fixed that already.
Don't modify the kata anymore:-) Your solution if you want. Thanks a lot anyway!
In both Ruby and Python my solution doesn't pass every second random test. I'm not sure if I missed something but it passed all the basic tests and half of the random tests...
The second random test is (Ruby, Python) with
log
. Do you have some output from the random tests? Fixed tests and half random ones are with id, sin, cos.l = 2.0, u = 17.0, n = 16 My points: [2.0, 2.9375, 3.875, 4.8125, 5.75, 6.6875, 7.625, 8.5625, 9.5, 10.4375, 11.375, 12.3125, 13.25, 14.1875, 15.125, 16.0625] Tests points: [4.0, 4.9375, 5.875, 6.8125, 7.75, 8.6875, 9.625, 10.5625, 11.5, 12.4375, 13.375, 14.3125, 15.25, 16.1875, 17.125, 18.0625] -- off by 2.
I see my error, I will try to correct if CW accepts to re-publish. Thanks once more!
Edit: I corrected the Python version. Does it work?
Should the numbers be floored or truncated? For negative numbers the results are different.
You are right. floored, in the description:
I will modify the description. What about the import (see below) ?
In Python:
NameError: name 'sin' is not defined
But if you import it? Should I import all needed in the tests?
You should import what you use.
OK, I will modify.
You should import math library