# [Challenge] Who wants a challenge?

The commenter on the website seemed sure…

@ionatan Can I try that challenge? I think I might know how to do it (although not in one line)

Pretty sure it’s 18446744073709551615 as total. On the 64th there are 9223372036854775808

In the general case then. For a chessboard that’s a x b

Here’s my attempt in JS:

Don't click me Zeke Last chance Zeke, don't look: ``` function grainCount(a){ var n = 1; for (i = 0; i < a; i++){ console.log(n); n = n*2; } } ```

The spirit of these challenges is to figure it out on your own - to further your own skills!

Frankly, this is a very easy one, the instructions are already explaining how it can be solved, it’s a simulation problem. This is very much something that you can learn to do! How would you do this manually? (And indeed, this can be done with pen and paper within reasonable amount of time and no fancy math)

Ah. Now we’re getting somewhere!

You need the total number though

Hang onnnn

I’ll accept one-liners only from you!

``` function grainCount(){ var a = 1; var total = 1; for (i = 0; i < 30; i++){ console.log(a); a = a*2; total = total + a; } console.log("Total: " + total); } ```

What’s that 30?!

No magical numbers if you will!

Forgot to remove that…
That was when I did specifically 5 by 6

Fixed...No magic numbers now: ``` function grainCount(size){ var a = 1; var total = 1; for (i = 0; i < size; i++){ console.log(a); a = a*2; total = total + a; } console.log("Total: " + total); } ```

Isn’t it very weird to start with the total as 1? Why not start at 3? or 7? I think 0 makes the most sense!

2 Likes

# #Winning

I started at 1 because it's the first (1st) square, and there's one grain on it.

Yeah, but what if we now tell you that there are a hundred in the first one. Then you’ll have to change two things in your program.

Wait wait wait
There’s a problem! You’re not getting the correct result though, are you?

JS is playing tricks on you.

I’ll still accept it, but it does not produce an accurate result. The result is above safe integers in JS

1 Like

Yeah but now you’re trying to make my head explode more.

BTW, the total number of wheat on that chess board, written in binary, is (click me to view spoiler) `0b1111111111111111111111111111111111111111111111111111111111111111`

Shhh! You’re giving a hint!