6 kyu

Averaging in an Infinite Array

17 of 74At1029
Description
Loading description...
Mathematics
Algorithms
View
AllIssues13Questions1Suggestions3Show Resolved
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar

    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.

  • JohanWiltink Avatar

    ( 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 BigInts instead of Numbers as inputs? ( a, not n ! )

    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! )

  • Blind4Basics Avatar

    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)

  • monadius Avatar

    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 calling find_a) or add tests which verify that array is not modified.

  • JohanWiltink Avatar
  • JohanWiltink Avatar

    ( 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.

  • JohanWiltink Avatar

    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.

  • JohanWiltink Avatar

    ( JS, possibly others )

    Those are not random tests. They are the same every time.

  • Blind4Basics Avatar

    trying to just return 0n in JS, I get the following:

    TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    

    (using node 10) => Any idea?

  • Blind4Basics Avatar
    • I said REASONNABLE input, for the third sample test....... X/ => sample tests now need 2 more REASONNABLE tests with values of n close to -3 and 6.
    • edge case needed : n between 0 and 2 (and you need to enforce some random tests with that too)
    • the description now doesn't give the range of n, even if visible in the description => state it clearly
  • Blind4Basics Avatar

    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
    • just before: I'd clearly state that the user has to find out what to do for/about the B sequence.
    • Answers need not be reformatted => what?? => nope => nothing to do here.
    • the description doesn't state that the average is "exact" at each point. I mean that there is no rounding problems anywhere.
    • ... 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 of n. 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...)
    • suggestion: don't bother with negative indexes since you use A[0],A[1],A[2],A[3] in the description of the input. I'd suggest to use A[i],A[i+1],A[i+2],A[i+3] instead, and same for B.

    about the tests:

    • you need at least another sample test with reasonnable n (something like a call with [2,4,6,7],7 / note: I didn't check if this input is valid or whatever)

    cheers

  • ᛚᚨᚱᛊ ᚺᛖᚾᚱᛁᚲ Avatar

    Python: Instructions are ambiguous. What is array and where is the second row B?

  • Voile Avatar

    Test Cases are called as an array of [A[0],A[1],A[2],A[3],n].

    ...Why not findA([A[0],A[1],A[2],A[3]], n)?

  • ZED.CWT Avatar

    Python

    [-6, 0, -1, 6, -68]
    -14349098629443426218158917573770763142496 should equal 6
     Log
    [0, -2, -3, -1, -33]
    2952141850480565411 should equal -1
     Log
    [2, 9, -1, -8, -53]
    -73622127472503052690829399828256 should equal -8
    
  • ZED.CWT Avatar

    Solution function names should follow snake_case in Python findA -> find_a

  • ZED.CWT Avatar
     given [1,2,3,4,100]
    expected 6.056010048700358e+55 to deeply equal 6.05601004870036e+55
    
    
    60560100487003612846322657690093088848428068520476594299 === 6.056010048700361e+55
    

    NEVER EVER comparing floating numbers directly Use assert.closeTo(actual, expected, delta, [message]) instead

    It's Node v10+ already, just use the builtin BigInt instead

  • ZED.CWT Avatar
    [ -72, -90, -97, -98, 0 ]
    expected -72 to deeply equal -98
    
    [ -89, -83, -55, -90, 2 ]
    expected -55 to deeply equal -90