Skip to content

Instantly share code, notes, and snippets.

@olumidayy
Created April 3, 2020 10:13
Show Gist options
  • Save olumidayy/3815abb5aaf10fefa0d8a08d122e8aeb to your computer and use it in GitHub Desktop.
Save olumidayy/3815abb5aaf10fefa0d8a08d122e8aeb to your computer and use it in GitHub Desktop.
day10
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