6 kyu
Averaging in an Infinite Array
17 of 74At1029
Loading description...
Mathematics
Algorithms
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.
Dummy issue to prevent approval for now:
JS can use arbitrary precision integers; some rethinking may yet be in order ( see below ).
Author: when you think kata is ready for approval, please resolve this issue.
Is it okay now?
It is if you think it is.
Approving now.
( JavaScript specific )
One can return
BigInt
, or anything that will.toString()
to full precision. But you don't really need to specify that, I think.But why don't you give the user
BigInt
s instead ofNumber
s as inputs? (a
, notn
! )Python, if I understand correctly, and Haskell do this; JavaScript now can as well. ( JS historically did not have arbitrary precision integers, so we may not yet be used to this, but it does now. let's use them! )
.
why did you change the output format of python too? JS was causing troubles, not python... x/
There is no point to ask for a string in python while it handles integers with arbitrary precision.
btw: the description isn't up to date:
(Where range of n is -200<n<200)
edit : and use that to resolve monadius suggestion:
find_a(j[:], i)
Done. though i'm not sure where to use find_a(j[:],i)? Do i use it as the function?
it was supposed to be here:
test.assert_equals(find_a(j, i), k)
. But since you compute now the expected result before the actual one and that you work on a copy of the input in your reference solution, that's not needed anymore.Python: please add a note that the input argument
array
should not be modified. Even better, either allow modifications (by computing the expected answer before callingfind_a
) or add tests which verify thatarray
is not modified.( JavaScript is vulnerable to input modification as well. )
handled for python. What about JS?
Sorry i'm still quite unfamiliar, but how would input modification affect?
the problem is that arrays (in JS) or lists (in python) are passed by reference. Meaning that if you send the same mutable object to several functions, any of them will see the modifications done by the previous calls:
that's an open door to cheating (for cw's purpose), but that's mostly an opened door to struggles, trying to understand "what the hell is going on?!?", for the users (since they do not see the code of the tests, so they may have a hard time figuring out that their own code is silently causing weird bugs).
Haskell translation
.
( JS, possibly others )
Those are not random tests. They are the same every time.
Please do not close this issue until you have outside confirmation the issue is actually solved. You have been told this before.
I've checked that they're not the same every time?
When I fork my newest solution, I get this:
Something weird seems to be going on. I can't yet explain it reading the tests; I agree it shouldn't happen, but it does.
@At1029: it is easy to fix JS tests. Either change:
to
or copy all these variables inside
it
.errr... Feels like you forgot to add a
slice
or anything somewhere, didn't you...? x)solution
does not modify its arguments so it is not necessary to create a copy ofarr
.Changing var to let fixed it.
Yep, that worked.
I had noticed you were using
var
instead oflet
, but it seemed outlandish that would cause this. Bad, bad JavaScript ..Does
var
have any advantages overlet
? I wouldn't know; I quit usingvar
whenlet
was invented ( andconst
always had block scope ).Please don't run a thousand random tests. My browser chokes on rendering that for irritatingly long. A hundred should be enough.
Do not rely on random tests for edge cases. If you need edge case coverage, use fixed tests.
( JS, possibly others )
Those are not random tests. They are the same every time.
They should not the same every time. i've reduced to 100 random cases.
I fully agree they should not. But did you actually check they aren't?
I did check, and for me, they are not. You can fork my solution and check for yourself.
trying to just return
0n
in JS, I get the following:(using node 10) => Any idea?
seems that chai doesn't know what to do with BigInts. Maybe return the results as strings in JS? Or you'll need to find something more appropriate than
assert.deepEqual
.EDIT: Seems actually that's only the assertion message that is causing troubles. If you can build your own for each test (with expected and actual, ofc), that may solve the problem too.
Changed the answers to string notation.
'kay
Could still have asked for a
BigInt
and stringified it yourself. That way, solvers can work inBigInt
the whole time ( passa
in as array of bigint;n
as aNumber
of course ).Use appropriate datatypes! Stringifying things is very rarely the solution, and when it's necessary to work around testing framework limitations, do not bother the user with it.
so, need to go with the assertion message, I guess? Can you confirm that's what is needed here? (I know shit to chai... And actually, I know almost shit to JS... x) )
assert.strictEqual( findA([0n,0n,0n,0n],0).toString(), "0" )
should work ( haven't actually tested ).Might include
assert( findA([0n,0n,0n,0n],0) instanceof BigInt, "message" )
, but can only pass all tests by returningBigInt
s anyway. Don't go borrowing trouble.( duplicate message )
Thanks for the suggestion, now answers will be returned as BigInt.
advise: don't resolve the issues too quickly: as you saw, last time you created more issues than anything.
Added REASONABLE tests. and range of n
52 isn't reasonnable. -10 isn't either (even if it's "almost" reasonnable) ;)
reminder:
EDIT :
0<=n<3
Is it fine now? I tried importing BigInt library in js but can't.
almost good. Sample tests are ok, but in the random tests,
i = randint(-1000, 1000)
should be:i = randint(-1000, 1000) if randint(0,20) else randint(-15,20)
. With 1000 tests, you'll be "sure" that boundaries will be correctly tested in almost every batch of tests.about JS, you need to use Node 10, afaik.
Done
JS and BigInts too? (I cannot see JS's tests)
sounds so, but there might be a problem. Closing here.
No you don't. Test edge cases with fixed tests and keep your random generator random.
Random tests are great for finding edge cases though. ( For this kata, edge cases are predictable. But they may not always be. )
yes you do. Without constraints, here, there had very little chances to be tested in the random tests. ;)
Which is why you test edge cases with fixed tests.
I'm willing to be wrong here, but you'll have to make me see the light. Isn't it better to be sure your edge cases are covered?
there is a fixed test about that too. ;) Might be good to have more, yes, but that was already hard to get it. x)
If you keep insisting, maybe you'll have them from the author. ;)
hi,
Some problems in there (talking about python, but I guess that will be the same in JS):
Description:
(Where n is a positive integer and n>4)
=> wrong:n>3
Answers need not be reformatted
=> what?? => nope => nothing to do here.... and consider memory sizes
this is absolutely wrong, according to the current passing solutions. => needs either to be removed or to push way further the values ofn
. Problem being: considering how fast the numbers are growing, can you even reach the point where memory will cause troubles before the time out limit? (I guess, but...)A[0],A[1],A[2],A[3]
in the description of the input. I'd suggest to useA[i],A[i+1],A[i+2],A[i+3]
instead, and same for B.about the tests:
n
(something like a call with[2,4,6,7],7
/ note: I didn't check if this input is valid or whatever)cheers
I've improved my code to include all cases of integer n. Only javascript formats the integers to scientific notation automatically, while python leaves it exact in decimal, so that's why answers need not be formatted. I've included a hint for B seq, and i've also included negative indexes so i'll just leave the A input as it is. Also, included one more sample test.
Python: Instructions are ambiguous. What is
array
and where is the second rowB
?A and B is not given. You're supposed to find the values within them.
This is not really a case of "description unclear" (and definitely not
ambiguous
which would mean there are more than 1 interpretations), more of you're not reading and understanding the description, which is more of a question than an issue.I completely overlooked that line. So
array
isA[0:3] + [n]
......Why not
findA([A[0],A[1],A[2],A[3]], n)
?Done
Python
How did you get those values?
Get what?
Obviously
Done
Solution function names should follow snake_case in Python findA -> find_a
Done
NEVER EVER comparing floating numbers directly
Use assert.closeTo(actual, expected, delta, [message]) insteadIt's Node v10+ already, just use the builtin BigInt instead
That's assuming every value must be an integer, which is true in the context of this kata but not in general.
I feel like we should use
Fraction
instead, but then there wouldn't be any JS version...I've used assert.closeTo for js test cases, but for python there isn't such a function?
doesn't apply anymore.
Done