Skip to content

Instantly share code, notes, and snippets.

@pce
Last active August 8, 2020 10:18
Show Gist options
  • Save pce/067f37ac6ced9ddec1e538f8c6da56f9 to your computer and use it in GitHub Desktop.
Save pce/067f37ac6ced9ddec1e538f8c6da56f9 to your computer and use it in GitHub Desktop.
To compile and play with the sum of odds in C++: `g++ aoc_01-sumofofodd.cpp && ./a.out` or `clang++ -std=c++11 -stdlib=libc++ -g aoc_01-sumofofodd.cpp && ./a.out`
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using std::cout;
using std::string;
using std::vector;
vector<int> SumOfOdd(int n) {
vector<int> v;
double sumOfOdd = .0;
for (int i=0; i<=n; i++) {
sumOfOdd = pow(1.0 + (double)i, 2.0);
v.push_back((int)sumOfOdd);
}
return v;
}
void PrintBoard(const vector<int> board) {
for (int i = 0; i < board.size(); i++) {
cout << board[i];
cout << "\n";
}
cout << "\n";
}
int main() {
auto board = SumOfOdd(8);
PrintBoard(board);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment