7 kyu
Geometric sequence - sum of all elements
776 of 1,392baaart
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.
Python, probably others:
Resolved for Python (also updated test framework).
Currently only JS has this issue.
(Be aware that simply using
assert.approximately
with an absolute tolerance of1e-9
will invalidate many legit solutions, closed form or iterative)This comment has been hidden.
How is nobody else mentioning this problem? This just drove me crazy for 10 minutes
Fixed in this fork
This comment has been hidden.
Precision has been fixed by someone already.
I have added negivative value to random tests.
You didn't actually resolve this btw.
I don't get why the author is accepting translation while the kata is still in beta. It'll just make the kata takes a longer time to get approved.
This comment has been hidden.
This comment has been hidden.
Fixed.
This comment has been hidden.
Fixed.
This comment has been hidden.
Fixed; added input constraints in description (
n
cannot be 0)This comment has been hidden.
There are some rounding issues with large numbers. If you submit a bunch of times it can pass/fail at random.
Fixed for Python.
I think I have fixed Javascript and Ruby, added more random tests as well.
The description is quite poorly worded. This might be an improvement:
A geometric sequence is one in which the (i+1)th term is found by multiplying the (i)th term by a fixed non-zero number, r.
For example, for r = 3: s = 2, 6, 18, 54, ... is a geometric sequence.
Your task is to write a function geometric_sequence_sum(a, r, n) that will return the SUM of the first n elements of a geometric sequence with the given constant r and first element a.
For example: geometric_sequence_sum(2, 3, 5) should return: 242 = 2 + 6 + 18 + 54 + 162
Fixed.
it's better to add one more test case, where r = 1, but a is not 1
That was not clear what I have to do with the r constant.
Closing as less informative than the issue by @nerdgasm above.
needs more test cases
Bumped random test amount to
50
.I probably did not use the right way to solve, but i don't understand how to solve the second test. The other tests worked fine without the if and else statements.
The problem statement should be written a bit clearer
fixed.
You should state result should be for large numbers!!
fixed
random tests need more precision
Dupe issue.
Same problem here. Random test fails for very large numbers. Expected value is less accurate than returned value. Had to submit a couple of times.
Dupe issue.
I got a test failing with 'Expected NaN but got 12' and then submit again and it passed. Weird, any issue here?
random test fails when number too big (sorry for no example)
Dupe issue.
It's random tests could be bypassed by simply hitting sumbit over again, making them pointless
Dupe issue.
One random test failed, it expected number with less accuracy than returned number
Dupe issue.
Yup!-) Rounding problems, one needs to submit many times. Put some "fuzz" in the tests or round or truncate to a few decimal places.
Duplicate.
You need to use a little "fuzz" when you check the correct answer. My calculation didn't match yours in about the 9th or 10th decimal place, so I had to re-submit three or four times before my solution was accepted (I'm working in JavaScript which doesn't have infinite precision Integers). Or, you need to limit the random test cases to a size that will fit within an int.
Yup. You can find an example implementation here. Just make sure to change the thresholds to something lower, according to CIS' comment
1e-8
should be fine.Use
Test.describe
Instead ofConsole.log
, An extract from CW Docs -Here
foo
represent the group of tests, mostly Basic Tests/Random Tests.See also sec. Group your tests of the conjured codex.
It seems to be good. Go ahead!