Skip to content

Instantly share code, notes, and snippets.

@towc
Created December 17, 2018 23:28
Show Gist options
  • Save towc/87bbe8e7da7878ed75e35b25057218a5 to your computer and use it in GitHub Desktop.
Save towc/87bbe8e7da7878ed75e35b25057218a5 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <iostream>
#include <vector>
bool isIn(const int& x, const std::vector<int>& xs)
{
int size = (int)xs.size();
for(int i = 0; i < size; ++i) {
if(x == xs[i]) {
return true;
}
}
return false;
}
int main()
{
std::ifstream inFile;
std::vector<int> xsv;
int x;
inFile.open("aoc-input-1");
while(inFile >> x) {
xsv.push_back(x);
}
inFile.close();
int xsSize = xsv.size();
int xs[xsSize];
std::copy(xsv.begin(), xsv.end(), xs);
std::vector<int> results;
int i = -1;
int lastRes = 0;
do {
i = (i + 1) % xsSize;
results.push_back(lastRes);
lastRes += xs[i];
//std::cout <<
// results.size() << ", " << lastRes
//<< std::endl;
} while(!isIn(lastRes, results));
std::cout << lastRes << std::endl;
return 0;
}
const fs = require('fs');
const freqs = fs.readFileSync('aoc-input-1', 'utf-8').trim().split('\n').map(Number);
const res = [];
let i = -1;
let lastRes = 0;
do {
i = (i + 1) % freqs.length;
//console.log(res.length, lastRes);
res.push(lastRes);
lastRes += freqs[i];
} while (!res.includes(lastRes));
console.log(lastRes);
+2
+11
+4
-16
-4
+15
+19
-8
-17
+12
+8
+8
+18
-10
-17
-6
+10
+10
+19
+11
+12
-17
+4
-1
+12
+6
+13
+14
+6
+19
+2
+19
-7
-15
+6
-12
-15
-18
+17
+8
+4
+14
+1
+15
-6
-6
+13
+9
-2
+1
+15
-12
+18
+7
-14
+15
-16
+6
-12
-11
-12
-1
-15
-8
-18
-15
+11
+13
-7
+15
+19
+2
+17
-9
-15
-11
-8
+16
+17
-6
+13
+16
-20
+19
+8
+14
+5
+11
-5
+6
+10
+3
-7
-5
-14
+9
+6
+13
+4
-3
-13
-6
-18
-23
-2
+16
+12
-4
+12
+3
-4
+9
-14
+1
-17
-21
+11
-8
+7
-16
-20
-3
-10
-17
-11
+6
-15
-11
+17
+12
-13
-11
-12
-18
-1
+10
-16
-1
-8
+18
+4
+2
-11
-18
+8
+18
-17
+7
+3
+17
+7
+1
-16
+10
-6
-10
+31
-5
-14
+15
+19
+6
-1
+17
-4
+16
-6
+9
-26
-18
+17
-9
-5
-19
+2
+13
+41
-18
+10
-26
-12
+4
-3
-23
-9
-29
-13
+15
+4
-21
+14
+23
-24
-4
-12
-8
-18
-16
-14
+17
-8
-16
+13
-15
+7
+9
-17
-4
-7
-12
+4
+10
-13
-6
-8
+10
+1
+9
-15
+14
-15
+11
-18
-18
+2
+10
-8
-10
+5
-4
+12
-4
-2
+15
+17
+16
+19
+17
+13
+8
-10
+13
+8
-13
-14
+5
-3
-15
-16
-9
-5
-10
+8
-2
+1
-14
-7
-3
-12
-3
+10
-18
+22
+8
-13
-3
-18
-12
-9
+1
-10
+8
-13
-12
-9
-2
+12
-14
+8
-19
-6
-11
+12
+15
+17
+7
-14
+11
+9
-10
-21
+3
-19
-6
-6
+7
+15
-13
-8
+10
-18
+15
-9
-19
+5
+11
-7
-14
+7
+9
+6
+6
+13
+8
+13
+19
-8
-3
-4
-18
+12
-2
+18
+13
-1
+17
-7
+12
+8
+2
+19
-11
+22
+14
+9
-12
+24
+1
+5
+20
-18
+17
-9
+12
-4
-15
-10
+4
-7
+11
+13
+10
+21
-14
-1
-13
-6
+14
+7
+7
+10
+11
-22
+6
+17
+26
-7
+8
-5
+29
-54
-16
+13
+10
-1
-23
+12
-20
-20
-27
+1
-2
-4
-26
-2
-36
-18
+14
-3
-18
-1
+17
+15
-12
+9
+1
+23
-22
-6
-20
+19
+3
-17
-6
-41
-5
-5
-5
-19
-9
-13
+3
+2
+10
+5
-6
-18
-19
+10
+17
+6
-17
+5
-7
+10
+6
-5
-14
+1
-17
-19
+7
+14
-19
+6
+12
-16
+13
-1
+16
+14
-13
-4
+2
-17
-1
-7
-5
-3
-14
-3
+5
+11
-12
-5
-14
+2
+2
-15
+12
-3
+15
-2
+10
+7
-16
+12
-15
+1
-3
-4
-19
+7
-5
+22
+8
+17
+16
+15
+11
+3
-16
-10
+7
+12
+16
+13
-10
+15
-1
-15
+22
+1
+3
+20
+24
+12
+17
-19
-12
+7
-11
-19
+4
+4
-21
+22
+1
+45
+3
-9
+41
-1
+94
+2
+7
-37
+3
+217
+13
+10
-14
+5
-3
-14
-26
-39
+80
+33
+9
-13
+7
+7
-13
-14
+1
+37
+33
+7
+14
+1
-5
-11
-8
-12
+4
+14
-17
+1
-10
-20
-25
+27
+31
-8
+1
+53
+22
+9
-14
-49
+13
-52
-64
-100
+34
+198
+605
+76787
-8
+13
+4
-8
+5
+9
-7
-13
-6
-4
-20
+6
+12
-4
+7
+5
-14
+10
+17
+18
+18
+5
+6
-12
-6
-8
-13
-5
-8
-17
+6
+2
+3
+18
-1
+20
+14
-18
+21
-12
+3
+8
+6
+21
-3
+1
+9
+16
+15
-7
+1
-16
+17
-5
-15
-14
+3
+3
-4
+2
+1
+16
+19
+12
-4
+14
-8
+17
-7
-1
-3
-11
-12
+7
+9
-10
-13
+1
-8
+4
-12
+13
-10
-8
-3
-19
-12
+7
+9
-1
-9
-4
-19
-12
+17
-12
+19
+18
-12
-7
-10
+5
-21
+4
-6
+4
-15
-9
+19
-17
+21
+12
+24
+13
+18
-16
-11
+10
+18
+7
+16
-10
-4
-13
+29
-13
-9
+3
-22
-13
+67
-10
+9
+6
+2
+8
+6
+18
-16
-15
+9
+2
+3
-4
+7
+18
+12
-10
-15
+1
+11
-9
-19
+15
+8
+11
+2
+3
+9
+14
-19
+16
-5
-12
+8
+17
+4
+10
-13
+19
+9
-19
-11
+8
+6
+3
+5
-16
+3
+7
+11
-1
+5
-7
-12
+13
-6
+1
+18
+6
+1
+14
-7
-2
-13
+18
-1
+18
-5
+3
-14
-17
+1
+13
+16
+14
+4
-13
-12
-1
+2
+3
+14
-1
-6
+12
+8
-11
+6
-7
+19
-16
+5
+18
+11
-16
-8
-3
+13
+6
+7
-14
+9
+14
-7
+9
-14
+1
-6
+16
-2
-12
-5
-8
+7
-19
+13
+2
+7
+13
-8
+7
+15
+9
+10
-5
+4
+7
-1
+12
+13
+13
+10
+13
+13
-6
+12
+10
-5
+9
+11
-16
+8
-11
-15
-15
+10
-17
+2
-6
-11
-14
-13
-14
-5
-8
-1
-7
-7
+21
-11
-5
+3
+5
-15
+20
+8
-17
+7
-13
+35
+6
-3
-1
-16
+8
-5
-10
+14
+20
+13
+10
-20
-17
+13
-2
+9
+19
-8
+4
-2
+12
-15
+12
-4
+20
-7
+2
-5
-19
-3
-1
+3
+6
+7
-20
+19
+15
+10
+3
-7
+1
+13
+4
+6
+5
+4
+4
+7
-19
+16
+2
+4
-8
-7
+18
+15
+6
+1
-13
+14
+18
-7
+8
-16
-10
+13
-12
+13
+14
+14
-8
-19
+4
-15
-16
-16
-8
+10
+17
-12
+10
+8
+19
-13
+14
+12
+3
-10
+2
+14
+1
-2
+3
+16
-3
-12
+5
+4
-19
+17
-4
-8
+15
-6
+14
+21
-4
-18
+4
-8
+21
-28
+5
-25
-4
-2
+14
-2
-22
-9
-7
-5
-20
-17
-6
+8
-5
-4
-2
-15
-6
+13
+13
+13
-29
-16
+13
-38
+5
-16
+4
-15
+19
-31
+24
+6
-13
+20
-47
-6
+13
+14
-79
-14
+11
-4
+24
-18
-1
+20
-4
+24
-26
-25
-16
-6
-8
-7
+8
-77371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment