Created
April 3, 2020 10:13
-
-
Save olumidayy/3815abb5aaf10fefa0d8a08d122e8aeb to your computer and use it in GitHub Desktop.
day10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
void main() { | |
getNumberOfGrains(8); | |
} | |
void getNumberOfGrains(n) { | |
var totalNumber = | |
[for (var i = 0; i < 64; i++) pow(2, i)].reduce((a, b) => a + b); | |
int numberOfGrains = pow(2, n - 1); | |
int subTotal = pow(2, n) - 1; | |
print('Total number of grains on the board: $totalNumber'); | |
print('Total number of grains from Square 1 to $n: $subTotal'); | |
print('Number of grains on Square $n: $numberOfGrains'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment