Ad
  • Custom User Avatar
  • Custom User Avatar

    Added.

  • Custom User Avatar

    When I do not use bignumber.js at all, the tests fail because test suite is missing the require. Is it possible to put the require in the test suite, so solutions which do not need it do not have to include it?

  • Custom User Avatar

    My code (arr is array of native BigInt):

      console.info("My number as BN:     " + BN(arr[0] * arr[0] + arr[1] * arr[1]).toFixed());
      console.info("My number as BigInt: " + (arr[0] * arr[0] + arr[1] * arr[1]));
    

    Output:

    Testing  [
      10, 7,  5,  5, 3, 2,  7, 6, 5,  9,
      10, 2,  6,  7, 2, 9, 10, 8, 8,  1,
      10, 8,  8,  6, 5, 6,  4, 5, 9,  9,
       4, 8, 10, 10, 4, 5,  7, 6, 6, 10
    ]
    My number as BN:     352198124718383079462822912000000000000
    My number as BigInt: 352198124718383079462822912000000000000
    Actual          6211882367758080000,17709055371970560000
    Possible expect 15840161589507840000,10064164423173120000
    Product to get 3.52198124718383079462822912e+38
    Your A*A + B*B 3.52198124718383079462822912e+38
    Correct
    

    As you see, BN.toFixed is able to get accurate representation.

  • Custom User Avatar

    Why not print BigInts as strings, then? Is it difficult to convert bigint to string and display it?

  • Custom User Avatar

    Not easy (because Bignumber.js doesnt't display well very big numbers) but I'll try to explain that your result is wrong.
    with JS

    you: A = 3; B = 38575890503412110
    me : A = 20534466401280000; B = 32656316659200000
    your product: 1.488099328131240613479552494652109e+33
    my   product: 1.4880993281312406429302784e+33
    

    They seem pretty close.
    with Python or another language with native big integers:

    you: A = 3; B = 38575890503412110
    me : A = 20534466401280000; B = 32656316659200000
    your product: 1,488,099,328,131,240,613,479,552,494,652,109
    my   product: 1,488,099,328,131,240,642,930,278,400,000,000
    mine - your =                        29,450,725,905,347,891 ~= 2.9450725905347892e+16
    

    I expect my answer is clear enough, if not please tell.

    I looked at your code and trie it and unfortunately I am sorry to think that you are not in the right way.

    Edit: It seems you now Python so you can try it on this kata and have no problem with big integeers.

  • Custom User Avatar

    in JavaScript, even using bignumber.js, there are some tests that are (or at least i find) impossible to pass.

    ej:
    Actual 3,38575890503412110
    Possible expect 20534466401280000,32656316659200000
    Product to get 1.4880993281312406429302784e+33
    Your AA + BB 1.488099328131240613479552494652109e+33
    Error

    Actual 1374771,7309774025
    Possible expect 2190443200,6973862400
    Product to get 53432798186560000000
    Your AA + BB 53432798186560003066
    Error

    Actual 3,38575890503412110
    Possible expect 20534466401280000,32656316659200000
    Product to get 1.4880993281312406429302784e+33
    Your AA + BB 1.488099328131240613479552494652109e+33
    Error