Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grains - Javascript - problem with the test answer? Other people also seem to be using a workaround to make answer match test #23

Open
beansprout opened this issue Apr 24, 2019 · 1 comment

Comments

@beansprout
Copy link

I found that for the test

test('total', () => {
    expect(grains.total()).toBe('18446744073709551615');
  });

using big-integer.js gave me an answer of '18446744073709551616' no matter what I did. So I looked at other people's answers to figure out what I was doing wrong.

What I found was that other people were just subtracting 1 from the 'total' method in their answers using a variety of different fixes so I did the same. There was only one test involving the total method so all tests passed that way.

However, upon reflection, maybe the test should be fixed.

Here was my total method:

total() {
    let tot = bigInt(0);
    for (let i = 2; i < 65; i++) {
      tot = tot + parseInt(this.square(i))
      }
      return bigInt(tot).minus(1).toString();
    }

The .minus(1) in the second to last line was my "fix".

Or, if I really am supposed to get '18446744073709551615' what should I be doing instead?
My full answer is here: https://exercism.io/my/solutions/2261a8c46c844d43992a4ac2c7ba5e03

Originally posted by @beansprout in exercism/r#106 (comment)
(moved because I was in the wrong track. Oops!)

@iHiD
Copy link
Member

iHiD commented Apr 24, 2019

Hello :)

I believe the test is correct.

If you do the sum manually, you'll see you end up at the correct solution.

1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768 + 65536 + 131072 + 262144 + 524288 + 1048576 + 2097152 + 4194304 + 8388608 + 16777216 + 33554432 + 67108864 + 134217728 + 268435456 + 536870912 + 1073741824 + 2147483648 + 4294967296 + 8589934592 + 17179869184 + 34359738368 + 68719476736 + 137438953472 + 274877906944 + 549755813888 + 1099511627776 + 2199023255552 + 4398046511104 + 8796093022208 + 17592186044416 + 35184372088832 + 70368744177664 + 140737488355328 + 281474976710656 + 562949953421312 + 1125899906842624 + 2251799813685248 + 4503599627370496 + 9007199254740992 + 18014398509481984 + 36028797018963968 + 72057594037927936 + 144115188075855872 + 288230376151711744 + 576460752303423488 + 1152921504606846976 + 2305843009213693952 + 4611686018427387904 + 9223372036854775808 
=> 18446744073709551615

@iHiD iHiD transferred this issue from exercism/exercism Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants